Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion py/packages/genkit-anthropic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,30 @@
>
> **Preview** — This plugin is in preview and may have API changes in future releases.

This Genkit plugin provides a set of tools and utilities for working with Anthropic.
Anthropic Claude model provider for Genkit.

## Installation

```bash
uv add genkit-anthropic
```

## Usage

```python
from genkit import Genkit
from genkit_anthropic import Anthropic

ai = Genkit(plugins=[Anthropic()])

res = await ai.generate(
model='anthropic/claude-sonnet-4-6',
Comment thread
huangjeff5 marked this conversation as resolved.
prompt='Explain recursion in 10 words.',
)
print(res.text)
```

Set `ANTHROPIC_API_KEY` in the environment, or pass `api_key=` to `Anthropic()`.

## Disclaimer

Expand Down
1 change: 0 additions & 1 deletion py/packages/genkit-anthropic/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ version = "0.9.0"

[project.urls]
"Bug Tracker" = "https://github.com/genkit-ai/genkit/issues"
Changelog = "https://github.com/genkit-ai/genkit/blob/main/py/packages/genkit-anthropic/CHANGELOG.md"
"Documentation" = "https://firebase.google.com/docs/genkit"
"Homepage" = "https://github.com/genkit-ai/genkit"
"Repository" = "https://github.com/genkit-ai/genkit/tree/main/py"
Expand Down
4 changes: 2 additions & 2 deletions py/packages/genkit-django/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Genkit Django Plugin

`genkit-plugin-django` exposes Genkit flows as HTTP endpoints in a Django application. It mirrors `genkit-plugin-flask` and `genkit-plugin-fastapi`: one decorator turns a `@ai.flow()` into a Django view that speaks the Genkit HTTP protocol (JSON envelope, optional SSE streaming, structured error responses).
`genkit-django` exposes Genkit flows as HTTP endpoints in a Django application. It mirrors `genkit-flask` and `genkit-fastapi`: one decorator turns a `@ai.flow()` into a Django view that speaks the Genkit HTTP protocol (JSON envelope, optional SSE streaming, structured error responses).

## Install

```bash
pip install genkit-plugin-django
uv add genkit-django
```

## Usage
Expand Down
1 change: 0 additions & 1 deletion py/packages/genkit-django/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ version = "0.9.0"

[project.urls]
"Bug Tracker" = "https://github.com/genkit-ai/genkit/issues"
Changelog = "https://github.com/genkit-ai/genkit/blob/main/py/packages/genkit-django/CHANGELOG.md"
"Documentation" = "https://firebase.google.com/docs/genkit"
"Homepage" = "https://github.com/genkit-ai/genkit"
"Repository" = "https://github.com/genkit-ai/genkit/tree/main/py"
Expand Down
34 changes: 19 additions & 15 deletions py/packages/genkit-evaluators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,34 @@ No LLM or API keys required.
## Installation

```bash
pip install genkit-plugin-evaluators
uv add genkit-evaluators
```

## Usage

```python
from genkit import Genkit
from genkit_evaluators import GenkitEval

ai = Genkit(plugins=[GenkitEval()])

# Run evaluation with genkit eval-flow or programmatically
evaluator = await ai.registry.resolve_evaluator('genkitEval/regex')
result = await evaluator.run(
input={
'dataset': [
{'input': 'sample', 'output': 'banana', 'reference': 'ba?a?a'},
{'input': 'sample', 'output': 'apple', 'reference': 'ba?a?a'},
],
'evalRunId': 'test',
}
from genkit.evaluator import BaseDataPoint
from genkit_evaluators import register_genkit_evaluators

ai = Genkit()
register_genkit_evaluators(ai)

results = await ai.evaluate(
evaluator='genkitEval/regex',
dataset=[
BaseDataPoint(input='sample', output='banana', reference='ba?a?a'),
BaseDataPoint(input='sample', output='apple', reference='ba?a?a'),
],
)
```

Or from the CLI:

```bash
genkit eval:run datasets/example.json --evaluators=genkitEval/regex
```

## Evaluators

- **genkitEval/regex** – Reference is a regex string. Output (stringified if needed) must match.
Expand Down
6 changes: 4 additions & 2 deletions py/packages/genkit-evaluators/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ requires-python = ">=3.10"
version = "0.9.0"

[project.urls]
"Homepage" = "https://github.com/genkit-ai/genkit"
"Repository" = "https://github.com/genkit-ai/genkit/tree/main/py"
"Bug Tracker" = "https://github.com/genkit-ai/genkit/issues"
"Documentation" = "https://firebase.google.com/docs/genkit"
"Homepage" = "https://github.com/genkit-ai/genkit"
"Repository" = "https://github.com/genkit-ai/genkit/tree/main/py"

[build-system]
build-backend = "hatchling.build"
Expand Down
104 changes: 94 additions & 10 deletions py/packages/genkit-fastapi/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,118 @@
# Genkit FastAPI Plugin

Serve Genkit flows as FastAPI endpoints.
Expose Genkit flows and agents as HTTP endpoints in a FastAPI application.

## Installation

```bash
pip install genkit-plugin-fastapi
uv add genkit-fastapi genkit-google-genai
```

## Usage

### Serving Flows (`serve_flow`)

Use `serve_flow` to register a Genkit flow as a FastAPI endpoint:

```python
from fastapi import FastAPI
from genkit import Genkit
from genkit_fastapi import genkit_fastapi_handler
from genkit_fastapi import serve_flow
from genkit_google_genai import GoogleAI

ai = Genkit(plugins=[GoogleAI()])
ai = Genkit(plugins=[GoogleAI()], model='googleai/gemini-flash-latest')
app = FastAPI()


@ai.tool(description='Get current weather for a location')
async def get_weather(location: str) -> str:
return f'Sunny in {location}'


@ai.flow()
async def chat_flow(prompt: str) -> str:
response = await ai.generate(prompt=prompt)
response = await ai.generate(
prompt=prompt,
tools=[get_weather],
)
return response.text


@app.post('/chat')
# Mount flow endpoint at POST /api/chat_flow
app.include_router(serve_flow(chat_flow), prefix='/api')
```

### Serving Agents (`serve_agent`)

Use `serve_agent` to expose an agent as FastAPI routes (including `/getSnapshot` and `/abort` endpoints when session state storage is enabled):

```python
from fastapi import FastAPI
from genkit import Genkit
from genkit_fastapi import serve_agent
from genkit_google_genai import GoogleAI

ai = Genkit(plugins=[GoogleAI()], model='googleai/gemini-flash-latest')
app = FastAPI()


@ai.tool(description='Get current weather for a location')
async def get_weather(location: str) -> str:
return f'Sunny in {location}'


weather_agent = ai.define_agent(
name='weatherAgent',
model='googleai/gemini-flash-latest',
system='You are a helpful weather assistant.',
tools=[get_weather],
)

# Mount agent turn route at POST /api/weatherAgent (plus /getSnapshot and /abort companion endpoints)
app.include_router(serve_agent(weather_agent), prefix='/api')
```

### Custom Base Path & Dependency Injection

Customize the base path or resolve request context using FastAPI's dependency injection system:

```python
from fastapi import Depends, Header
from genkit_fastapi import serve_flow


async def user_context(authorization: str = Header(...)):
return {'uid': parse_token(authorization)}


app.include_router(
serve_flow(
chat_flow,
base_path='/chat',
context_dependency=user_context,
),
prefix='/api',
)
```

### Decorator Handler (`genkit_fastapi_handler`)

For custom route definitions, you can also use `@genkit_fastapi_handler`:

```python
from genkit_fastapi import genkit_fastapi_handler


@app.post('/custom-chat', response_model=None)
@genkit_fastapi_handler(ai)
async def chat():
return chat_flow
@ai.flow()
async def custom_chat(prompt: str) -> str:
response = await ai.generate(
prompt=prompt,
tools=[get_weather],
)
return response.text
```

## Running

Expand All @@ -42,10 +126,10 @@ uvicorn main:app

## Streaming

The handler automatically supports streaming when the client sends `Accept: text/event-stream`:
Endpoints automatically support streaming when the client sends `Accept: text/event-stream` or specifies `?stream=true`:

```bash
curl -X POST http://localhost:8000/chat \
curl -X POST http://localhost:8000/api/chat_flow \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{"data": "Tell me a joke"}'
Expand Down
1 change: 0 additions & 1 deletion py/packages/genkit-fastapi/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ version = "0.9.0"

[project.urls]
"Bug Tracker" = "https://github.com/genkit-ai/genkit/issues"
"Changelog" = "https://github.com/genkit-ai/genkit/blob/main/py/packages/genkit-fastapi/CHANGELOG.md"
"Documentation" = "https://firebase.google.com/docs/genkit"
"Homepage" = "https://github.com/genkit-ai/genkit"
"Repository" = "https://github.com/genkit-ai/genkit/tree/main/py"
Expand Down
32 changes: 30 additions & 2 deletions py/packages/genkit-flask/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
# Genkit Flask plugin
# Genkit Flask Plugin

This Genkit plugin provides a set of tools and utilities for working with Flask.
Expose Genkit flows as HTTP endpoints in a Flask application.

## Installation

```bash
uv add genkit-flask genkit-google-genai
```

## Usage

```python
from flask import Flask
from genkit import Genkit
from genkit_flask import genkit_flask_handler
from genkit_google_genai import GoogleAI

app = Flask(__name__)
ai = Genkit(plugins=[GoogleAI()], model='googleai/gemini-flash-latest')


@app.post('/api/greet')
@genkit_flask_handler(ai)
@ai.flow()
async def greet_user(name: str) -> str:
res = await ai.generate(prompt=f'Say hello to {name} in one sentence.')
return res.text
```

Requires Flask 3.1+.
3 changes: 1 addition & 2 deletions py/packages/genkit-flask/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dependencies = [
"pydantic>=2.10.5",
"flask>=3.1.3",
]
description = "Genkit Firebase Plugin"
description = "Genkit Flask Plugin"
keywords = [
"genkit",
"ai",
Expand All @@ -68,7 +68,6 @@ version = "0.9.0"

[project.urls]
"Bug Tracker" = "https://github.com/genkit-ai/genkit/issues"
Changelog = "https://github.com/genkit-ai/genkit/blob/main/py/packages/genkit-flask/CHANGELOG.md"
"Documentation" = "https://firebase.google.com/docs/genkit"
"Homepage" = "https://github.com/genkit-ai/genkit"
"Repository" = "https://github.com/genkit-ai/genkit/tree/main/py"
Expand Down
25 changes: 22 additions & 3 deletions py/packages/genkit-google-cloud/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
# Google Cloud Plugin
# Genkit Google Cloud Plugin

This Genkit plugin provides a set of tools and utilities for working with Google
Cloud.
Export Genkit telemetry to Google Cloud Trace, Cloud Monitoring, and Cloud Logging.

## Installation

```bash
uv add genkit-google-cloud genkit-google-genai
```

## Usage

```python
from genkit import Genkit
from genkit_google_cloud import enable_google_cloud_telemetry
from genkit_google_genai import GoogleAI

enable_google_cloud_telemetry(project_id='my-project')

ai = Genkit(plugins=[GoogleAI()], model='googleai/gemini-flash-latest')
```

Requires Google Cloud Application Default Credentials (ADC) or explicit credentials.
1 change: 0 additions & 1 deletion py/packages/genkit-google-cloud/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ version = "0.9.0"

[project.urls]
"Bug Tracker" = "https://github.com/genkit-ai/genkit/issues"
Changelog = "https://github.com/genkit-ai/genkit/blob/main/py/packages/genkit-google-cloud/CHANGELOG.md"
"Documentation" = "https://firebase.google.com/docs/genkit"
"Homepage" = "https://github.com/genkit-ai/genkit"
"Repository" = "https://github.com/genkit-ai/genkit/tree/main/py"
Expand Down
Loading
Loading