Skip to content

Commit bc4c733

Browse files
authored
docs(py): upgrade plugin docstrings to landing-page hero style with inline return shapes (#5650)
1 parent 14ff3bd commit bc4c733

22 files changed

Lines changed: 320 additions & 1532 deletions

File tree

py/packages/genkit-anthropic/src/genkit_anthropic/__init__.py

Lines changed: 11 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -20,165 +20,30 @@
2020
Genkit framework. It registers Claude models as Genkit actions, enabling
2121
text generation operations.
2222
23-
Key Concepts (ELI5)::
24-
25-
┌─────────────────────┬────────────────────────────────────────────────────┐
26-
│ Concept │ ELI5 Explanation │
27-
├─────────────────────┼────────────────────────────────────────────────────┤
28-
│ Claude │ Anthropic's AI assistant. Like a helpful friend │
29-
│ │ who's great at explaining things and writing. │
30-
├─────────────────────┼────────────────────────────────────────────────────┤
31-
│ Sonnet │ The "just right" Claude model. Good at most │
32-
│ │ tasks without being too slow or expensive. │
33-
├─────────────────────┼────────────────────────────────────────────────────┤
34-
│ Haiku │ The fast & cheap Claude model. Perfect for │
35-
│ │ quick tasks like classification or summaries. │
36-
├─────────────────────┼────────────────────────────────────────────────────┤
37-
│ Opus │ The most capable Claude. For complex tasks │
38-
│ │ like research, analysis, or creative writing. │
39-
├─────────────────────┼────────────────────────────────────────────────────┤
40-
│ API Key │ Your password to use Claude. Keep it secret! │
41-
│ │ Set as ANTHROPIC_API_KEY environment variable. │
42-
├─────────────────────┼────────────────────────────────────────────────────┤
43-
│ System Prompt │ Instructions that shape Claude's personality. │
44-
│ │ Like giving a new employee their job description. │
45-
├─────────────────────┼────────────────────────────────────────────────────┤
46-
│ Tool Calling │ Claude can use functions you define. Like │
47-
│ │ giving it a calculator or search engine to use. │
48-
└─────────────────────┴────────────────────────────────────────────────────┘
49-
50-
Data Flow::
51-
52-
┌─────────────────────────────────────────────────────────────────────────┐
53-
│ HOW CLAUDE PROCESSES YOUR REQUEST │
54-
│ │
55-
│ Your Code │
56-
│ ai.generate(prompt="Explain quantum computing") │
57-
│ │ │
58-
│ │ (1) Request goes to Anthropic plugin │
59-
│ ▼ │
60-
│ ┌─────────────────┐ │
61-
│ │ Anthropic │ Plugin adds API key to request │
62-
│ │ Plugin │ │
63-
│ └────────┬────────┘ │
64-
│ │ │
65-
│ │ (2) Converts Genkit format → Claude Messages API │
66-
│ ▼ │
67-
│ ┌─────────────────┐ │
68-
│ │ AnthropicModel │ Handles message roles, images, │
69-
│ │ │ tools, and streaming │
70-
│ └────────┬────────┘ │
71-
│ │ │
72-
│ │ (3) HTTPS request to api.anthropic.com │
73-
│ ▼ │
74-
│ ════════════════════════════════════════════════════ │
75-
│ │ Internet │
76-
│ ▼ │
77-
│ ┌─────────────────┐ │
78-
│ │ Anthropic │ Claude thinks about your prompt │
79-
│ │ Claude API │ and generates a response │
80-
│ └────────┬────────┘ │
81-
│ │ │
82-
│ │ (4) Response parsed back to Genkit format │
83-
│ ▼ │
84-
│ ┌─────────────────┐ │
85-
│ │ Your App │ response.text = "Quantum computing..." │
86-
│ └─────────────────┘ │
87-
└─────────────────────────────────────────────────────────────────────────┘
88-
89-
Architecture Overview::
90-
91-
┌─────────────────────────────────────────────────────────────────────────┐
92-
│ Anthropic Plugin │
93-
├─────────────────────────────────────────────────────────────────────────┤
94-
│ Plugin Entry Point (__init__.py) │
95-
│ ├── Anthropic - Plugin class │
96-
│ └── anthropic_name() - Helper to create namespaced model names │
97-
├─────────────────────────────────────────────────────────────────────────┤
98-
│ plugin.py - Plugin Implementation │
99-
│ ├── Anthropic class (registers models) │
100-
│ └── Client initialization with Anthropic SDK │
101-
├─────────────────────────────────────────────────────────────────────────┤
102-
│ models.py - Model Implementation │
103-
│ ├── AnthropicModel (Messages API integration) │
104-
│ ├── Request/response conversion │
105-
│ └── Streaming support │
106-
├─────────────────────────────────────────────────────────────────────────┤
107-
│ model_info.py - Model Registry │
108-
│ ├── SUPPORTED_MODELS (claude-sonnet-4-5, opus, haiku, etc.) │
109-
│ └── Model capabilities and metadata │
110-
└─────────────────────────────────────────────────────────────────────────┘
111-
112-
Overview:
113-
The Anthropic plugin adds support for Claude models to Genkit. It uses
114-
the official Anthropic Python SDK and registers models that can be used
115-
with ai.generate() and other Genkit generation methods.
116-
117-
Supported Models:
118-
┌─────────────────────────────────────────────────────────────────────────┐
119-
│ Model │ Description │
120-
├───────────────────────────┼─────────────────────────────────────────────┤
121-
│ claude-sonnet-4-5 │ Balanced performance and capability │
122-
│ claude-haiku-4-5 │ Fast and cost-effective │
123-
│ claude-opus-4-5 │ Most capable, complex tasks │
124-
│ claude-sonnet-5 │ Latest Sonnet model │
125-
└───────────────────────────┴─────────────────────────────────────────────┘
126-
127-
Key Components:
128-
┌─────────────────────────────────────────────────────────────────────────┐
129-
│ Component │ Purpose │
130-
├─────────────────────┼───────────────────────────────────────────────────┤
131-
│ Anthropic │ Plugin class to register with Genkit │
132-
│ anthropic_name() │ Helper to create namespaced model names │
133-
└─────────────────────┴───────────────────────────────────────────────────┘
134-
13523
Example:
136-
Basic usage:
137-
13824
```python
13925
from genkit import Genkit
14026
from genkit_anthropic import Anthropic, AnthropicConfig
14127
142-
# Uses ANTHROPIC_API_KEY env var or pass api_key explicitly
143-
ai = Genkit(
144-
plugins=[Anthropic()],
145-
model='anthropic/claude-sonnet-4-5',
146-
)
147-
148-
response = await ai.generate(prompt='Hello, Claude!')
149-
print(response.text)
150-
151-
# With custom configuration
152-
response = await ai.generate(
153-
model='anthropic/claude-haiku-4-5',
154-
prompt='Write a haiku about AI',
155-
config=AnthropicConfig(temperature=0.7, max_output_tokens=100),
156-
)
157-
```
28+
# 1. Initialize Genkit with the Anthropic plugin
29+
ai = Genkit(plugins=[Anthropic()])
15830
159-
With tools:
160-
161-
```python
162-
@ai.tool()
163-
def get_weather(city: str) -> str:
164-
return f'Weather in {city}: Sunny, 72°F'
165-
166-
167-
response = await ai.generate(
31+
# 2. Generate content using Claude Sonnet 4.5
32+
res = await ai.generate(
16833
model='anthropic/claude-sonnet-4-5',
169-
prompt='What is the weather in Paris?',
170-
tools=['get_weather'],
34+
prompt='Explain recursion in 10 words.',
17135
)
36+
37+
# 3. Inspect output shapes directly
38+
print(res.text)
39+
# => A function calling itself until reaching a base stopping condition.
17240
```
17341
174-
Caveats:
175-
- Requires ANTHROPIC_API_KEY environment variable or api_key parameter
176-
- Model names are prefixed with 'anthropic/' (e.g., 'anthropic/claude-sonnet-4-5')
177-
- Anthropic models may have different tool calling behavior than Google models
42+
Requirements:
43+
- Requires the ``ANTHROPIC_API_KEY`` environment variable or explicit ``api_key``.
17844
17945
See Also:
18046
- Anthropic documentation: https://docs.anthropic.com/
181-
- Genkit documentation: https://genkit.dev/
18247
"""
18348

18449
from genkit_anthropic.config import (

py/packages/genkit-django/src/genkit_django/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,25 @@
2525
# myapp/views.py
2626
from genkit import Genkit
2727
from genkit_django import genkit_django_handler
28+
from genkit_google_genai import GoogleAI
2829
29-
ai = Genkit(plugins=[...])
30+
# 1. Initialize Genkit
31+
ai = Genkit(plugins=[GoogleAI()])
3032
3133
34+
# 2. Define flow and decorate as Django view
3235
@genkit_django_handler(ai)
3336
@ai.flow()
3437
async def chat(prompt: str) -> str:
35-
response = await ai.generate(prompt=prompt)
36-
return response.text
38+
res = await ai.generate(
39+
model='googleai/gemini-flash-latest',
40+
prompt=f'Answer concisely: {prompt}',
41+
)
42+
return res.text
43+
44+
45+
# POST /chat/ {"data": "Hello!"}
46+
# => {"result": "Hi there! How can I assist you today?"}
3747
```
3848
3949
```python

py/packages/genkit-fastapi/src/genkit_fastapi/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,25 @@
2929
from genkit_fastapi import genkit_fastapi_handler
3030
from genkit_google_genai import GoogleAI
3131
32+
# 1. Initialize Genkit and FastAPI app
3233
ai = Genkit(plugins=[GoogleAI()])
3334
app = FastAPI()
3435
3536
37+
# 2. Define flow and expose as FastAPI endpoint in one clean decorator stack
3638
@app.post('/chat', response_model=None)
3739
@genkit_fastapi_handler(ai)
3840
@ai.flow()
3941
async def chat_flow(prompt: str) -> str:
40-
response = await ai.generate(prompt=prompt)
41-
return response.text
42+
res = await ai.generate(
43+
model='googleai/gemini-flash-latest',
44+
prompt=f'Answer concisely: {prompt}',
45+
)
46+
return res.text
47+
48+
49+
# POST /chat {"data": "Why is the sky blue?"}
50+
# => {"result": "The sky appears blue due to Rayleigh scattering..."}
4251
```
4352
4453
Running:

0 commit comments

Comments
 (0)