genkit-plugin-anthropic 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- genkit/plugins/anthropic/__init__.py +186 -0
- genkit/plugins/anthropic/model_info.py +157 -0
- genkit/plugins/anthropic/models.py +282 -0
- genkit/plugins/anthropic/plugin.py +138 -0
- genkit/plugins/anthropic/py.typed +0 -0
- genkit_plugin_anthropic-0.5.0.dist-info/METADATA +36 -0
- genkit_plugin_anthropic-0.5.0.dist-info/RECORD +9 -0
- genkit_plugin_anthropic-0.5.0.dist-info/WHEEL +4 -0
- genkit_plugin_anthropic-0.5.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Copyright 2025 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
#
|
|
15
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
"""Anthropic plugin for Genkit.
|
|
18
|
+
|
|
19
|
+
This plugin provides integration with Anthropic's Claude models for the
|
|
20
|
+
Genkit framework. It registers Claude models as Genkit actions, enabling
|
|
21
|
+
text generation operations.
|
|
22
|
+
|
|
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-3.5-sonnet, 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-3-5-sonnet-latest │ Balanced performance and capability │
|
|
122
|
+
│ claude-3-5-haiku-latest │ Fast and cost-effective │
|
|
123
|
+
│ claude-3-opus-latest │ Most capable, complex tasks │
|
|
124
|
+
│ claude-sonnet-4-20250514 │ 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
|
+
|
|
135
|
+
Example:
|
|
136
|
+
Basic usage:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from genkit import Genkit
|
|
140
|
+
from genkit.plugins.anthropic import Anthropic
|
|
141
|
+
|
|
142
|
+
# Uses ANTHROPIC_API_KEY env var or pass api_key explicitly
|
|
143
|
+
ai = Genkit(
|
|
144
|
+
plugins=[Anthropic()],
|
|
145
|
+
model='anthropic/claude-3-5-sonnet-latest',
|
|
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-3-5-haiku-latest',
|
|
154
|
+
prompt='Write a haiku about AI',
|
|
155
|
+
config={'temperature': 0.7, 'max_tokens': 100},
|
|
156
|
+
)
|
|
157
|
+
```
|
|
158
|
+
|
|
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(
|
|
168
|
+
model='anthropic/claude-3-5-sonnet-latest',
|
|
169
|
+
prompt='What is the weather in Paris?',
|
|
170
|
+
tools=['get_weather'],
|
|
171
|
+
)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Caveats:
|
|
175
|
+
- Requires ANTHROPIC_API_KEY environment variable or api_key parameter
|
|
176
|
+
- Model names are prefixed with 'anthropic/' (e.g., 'anthropic/claude-3-5-sonnet-latest')
|
|
177
|
+
- Anthropic models may have different tool calling behavior than Google models
|
|
178
|
+
|
|
179
|
+
See Also:
|
|
180
|
+
- Anthropic documentation: https://docs.anthropic.com/
|
|
181
|
+
- Genkit documentation: https://genkit.dev/
|
|
182
|
+
"""
|
|
183
|
+
|
|
184
|
+
from genkit.plugins.anthropic.plugin import Anthropic, anthropic_name
|
|
185
|
+
|
|
186
|
+
__all__ = ['Anthropic', 'anthropic_name']
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# Copyright 2025 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
#
|
|
15
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
"""Anthropic Models for Genkit."""
|
|
18
|
+
|
|
19
|
+
from genkit.types import (
|
|
20
|
+
Constrained,
|
|
21
|
+
ModelInfo,
|
|
22
|
+
Supports,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
# Model definitions
|
|
26
|
+
CLAUDE_3_HAIKU = ModelInfo(
|
|
27
|
+
label='Anthropic - Claude 3 Haiku',
|
|
28
|
+
versions=['claude-3-haiku-20240307'],
|
|
29
|
+
supports=Supports(
|
|
30
|
+
multiturn=True,
|
|
31
|
+
media=True,
|
|
32
|
+
tools=True,
|
|
33
|
+
system_role=True,
|
|
34
|
+
),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
CLAUDE_3_5_HAIKU = ModelInfo(
|
|
38
|
+
label='Anthropic - Claude 3.5 Haiku',
|
|
39
|
+
versions=['claude-3-5-haiku-20241022'],
|
|
40
|
+
supports=Supports(
|
|
41
|
+
multiturn=True,
|
|
42
|
+
media=True,
|
|
43
|
+
tools=True,
|
|
44
|
+
system_role=True,
|
|
45
|
+
),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
CLAUDE_SONNET_4 = ModelInfo(
|
|
49
|
+
label='Anthropic - Claude Sonnet 4',
|
|
50
|
+
versions=['claude-sonnet-4-20250514'],
|
|
51
|
+
supports=Supports(
|
|
52
|
+
multiturn=True,
|
|
53
|
+
media=True,
|
|
54
|
+
tools=True,
|
|
55
|
+
system_role=True,
|
|
56
|
+
),
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
CLAUDE_OPUS_4 = ModelInfo(
|
|
60
|
+
label='Anthropic - Claude Opus 4',
|
|
61
|
+
versions=['claude-opus-4-20250514'],
|
|
62
|
+
supports=Supports(
|
|
63
|
+
multiturn=True,
|
|
64
|
+
media=True,
|
|
65
|
+
tools=True,
|
|
66
|
+
system_role=True,
|
|
67
|
+
),
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
CLAUDE_SONNET_4_5 = ModelInfo(
|
|
71
|
+
label='Anthropic - Claude Sonnet 4.5',
|
|
72
|
+
versions=['claude-sonnet-4-5-20250929'],
|
|
73
|
+
supports=Supports(
|
|
74
|
+
multiturn=True,
|
|
75
|
+
media=True,
|
|
76
|
+
tools=True,
|
|
77
|
+
system_role=True,
|
|
78
|
+
output=['text', 'json'],
|
|
79
|
+
constrained=Constrained.ALL,
|
|
80
|
+
),
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
CLAUDE_HAIKU_4_5 = ModelInfo(
|
|
84
|
+
label='Anthropic - Claude Haiku 4.5',
|
|
85
|
+
versions=['claude-haiku-4-5-20251001'],
|
|
86
|
+
supports=Supports(
|
|
87
|
+
multiturn=True,
|
|
88
|
+
media=True,
|
|
89
|
+
tools=True,
|
|
90
|
+
system_role=True,
|
|
91
|
+
output=['text', 'json'],
|
|
92
|
+
constrained=Constrained.ALL,
|
|
93
|
+
),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
CLAUDE_OPUS_4_1 = ModelInfo(
|
|
97
|
+
label='Anthropic - Claude Opus 4.1',
|
|
98
|
+
versions=['claude-opus-4-1-20250805'],
|
|
99
|
+
supports=Supports(
|
|
100
|
+
multiturn=True,
|
|
101
|
+
media=True,
|
|
102
|
+
tools=True,
|
|
103
|
+
system_role=True,
|
|
104
|
+
output=['text', 'json'],
|
|
105
|
+
constrained=Constrained.ALL,
|
|
106
|
+
),
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
CLAUDE_OPUS_4_5 = ModelInfo(
|
|
110
|
+
label='Anthropic - Claude Opus 4.5',
|
|
111
|
+
versions=['claude-opus-4-5-20251101'],
|
|
112
|
+
supports=Supports(
|
|
113
|
+
multiturn=True,
|
|
114
|
+
media=True,
|
|
115
|
+
tools=True,
|
|
116
|
+
system_role=True,
|
|
117
|
+
output=['text', 'json'],
|
|
118
|
+
constrained=Constrained.ALL,
|
|
119
|
+
),
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
SUPPORTED_ANTHROPIC_MODELS: dict[str, ModelInfo] = {
|
|
123
|
+
'claude-3-haiku': CLAUDE_3_HAIKU,
|
|
124
|
+
'claude-3-5-haiku': CLAUDE_3_5_HAIKU,
|
|
125
|
+
'claude-sonnet-4': CLAUDE_SONNET_4,
|
|
126
|
+
'claude-opus-4': CLAUDE_OPUS_4,
|
|
127
|
+
'claude-sonnet-4-5': CLAUDE_SONNET_4_5,
|
|
128
|
+
'claude-haiku-4-5': CLAUDE_HAIKU_4_5,
|
|
129
|
+
'claude-opus-4-1': CLAUDE_OPUS_4_1,
|
|
130
|
+
'claude-opus-4-5': CLAUDE_OPUS_4_5,
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
DEFAULT_SUPPORTS = Supports(
|
|
134
|
+
multiturn=True,
|
|
135
|
+
media=True,
|
|
136
|
+
tools=True,
|
|
137
|
+
system_role=True,
|
|
138
|
+
output=['text'],
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def get_model_info(name: str) -> ModelInfo:
|
|
143
|
+
"""Get model info for a given model name.
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
name: Model name.
|
|
147
|
+
|
|
148
|
+
Returns:
|
|
149
|
+
Model information.
|
|
150
|
+
"""
|
|
151
|
+
return SUPPORTED_ANTHROPIC_MODELS.get(
|
|
152
|
+
name,
|
|
153
|
+
ModelInfo(
|
|
154
|
+
label=f'Anthropic - {name}',
|
|
155
|
+
supports=DEFAULT_SUPPORTS,
|
|
156
|
+
),
|
|
157
|
+
)
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
# Copyright 2025 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
#
|
|
15
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
"""Anthropic model implementations."""
|
|
18
|
+
|
|
19
|
+
from typing import Any
|
|
20
|
+
|
|
21
|
+
from anthropic import AsyncAnthropic
|
|
22
|
+
from anthropic.types import Message as AnthropicMessage
|
|
23
|
+
from genkit.ai import ActionRunContext
|
|
24
|
+
from genkit.blocks.model import get_basic_usage_stats
|
|
25
|
+
from genkit.plugins.anthropic.model_info import get_model_info
|
|
26
|
+
from genkit.types import (
|
|
27
|
+
FinishReason,
|
|
28
|
+
GenerateRequest,
|
|
29
|
+
GenerateResponse,
|
|
30
|
+
GenerateResponseChunk,
|
|
31
|
+
GenerationUsage,
|
|
32
|
+
MediaPart,
|
|
33
|
+
Message,
|
|
34
|
+
Part,
|
|
35
|
+
Role,
|
|
36
|
+
TextPart,
|
|
37
|
+
ToolRequest,
|
|
38
|
+
ToolRequestPart,
|
|
39
|
+
ToolResponsePart,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
DEFAULT_MAX_OUTPUT_TOKENS = 4096
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class AnthropicModel:
|
|
46
|
+
"""Represents an Anthropic language model for use with Genkit.
|
|
47
|
+
|
|
48
|
+
Encapsulates interaction logic for a specific Claude model
|
|
49
|
+
enabling its use within Genkit for generative tasks.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
def __init__(self, model_name: str, client: AsyncAnthropic) -> None:
|
|
53
|
+
"""Initialize Anthropic model.
|
|
54
|
+
|
|
55
|
+
Sets up the client for communicating with the Anthropic API
|
|
56
|
+
and stores the model name.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
model_name: Name of the Anthropic model.
|
|
60
|
+
client: AsyncAnthropic client instance.
|
|
61
|
+
"""
|
|
62
|
+
model_info = get_model_info(model_name)
|
|
63
|
+
self.model_name = model_info.versions[0] if model_info.versions else model_name
|
|
64
|
+
self.client = client
|
|
65
|
+
|
|
66
|
+
async def generate(self, request: GenerateRequest, ctx: ActionRunContext | None = None) -> GenerateResponse:
|
|
67
|
+
"""Generate response from Anthropic.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
request: Generation request.
|
|
71
|
+
ctx: Action run context for streaming.
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
Generated response.
|
|
75
|
+
"""
|
|
76
|
+
params = self._build_params(request)
|
|
77
|
+
streaming = ctx and ctx.is_streaming
|
|
78
|
+
|
|
79
|
+
if streaming:
|
|
80
|
+
assert ctx is not None # streaming requires ctx
|
|
81
|
+
response = await self._generate_streaming(params, ctx)
|
|
82
|
+
else:
|
|
83
|
+
response = await self.client.messages.create(**params)
|
|
84
|
+
|
|
85
|
+
content = self._to_genkit_content(response.content)
|
|
86
|
+
|
|
87
|
+
response_message = Message(role=Role.MODEL, content=content)
|
|
88
|
+
basic_usage = get_basic_usage_stats(input_=request.messages, response=response_message)
|
|
89
|
+
|
|
90
|
+
finish_reason_map: dict[str, FinishReason] = {
|
|
91
|
+
'end_turn': FinishReason.STOP,
|
|
92
|
+
'max_tokens': FinishReason.LENGTH,
|
|
93
|
+
'stop_sequence': FinishReason.STOP,
|
|
94
|
+
'tool_use': FinishReason.STOP,
|
|
95
|
+
}
|
|
96
|
+
stop_reason_str = str(response.stop_reason) if response.stop_reason else ''
|
|
97
|
+
finish_reason = finish_reason_map.get(stop_reason_str, FinishReason.UNKNOWN)
|
|
98
|
+
|
|
99
|
+
return GenerateResponse(
|
|
100
|
+
message=response_message,
|
|
101
|
+
usage=GenerationUsage(
|
|
102
|
+
input_tokens=response.usage.input_tokens,
|
|
103
|
+
output_tokens=response.usage.output_tokens,
|
|
104
|
+
total_tokens=response.usage.input_tokens + response.usage.output_tokens,
|
|
105
|
+
input_characters=basic_usage.input_characters,
|
|
106
|
+
output_characters=basic_usage.output_characters,
|
|
107
|
+
input_images=basic_usage.input_images,
|
|
108
|
+
output_images=basic_usage.output_images,
|
|
109
|
+
),
|
|
110
|
+
finish_reason=finish_reason,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
def _build_params(self, request: GenerateRequest) -> dict[str, Any]:
|
|
114
|
+
"""Build Anthropic API parameters."""
|
|
115
|
+
config = request.config
|
|
116
|
+
params: dict[str, Any] = {}
|
|
117
|
+
|
|
118
|
+
if isinstance(config, dict):
|
|
119
|
+
params = config.copy()
|
|
120
|
+
elif config:
|
|
121
|
+
if hasattr(config, 'model_dump'):
|
|
122
|
+
params = config.model_dump(exclude_none=True)
|
|
123
|
+
else:
|
|
124
|
+
params = {k: v for k, v in vars(config).items() if v is not None}
|
|
125
|
+
|
|
126
|
+
# Handle mapped parameters
|
|
127
|
+
max_tokens = params.pop('max_output_tokens', None)
|
|
128
|
+
if max_tokens is None:
|
|
129
|
+
max_tokens = params.get('max_tokens', DEFAULT_MAX_OUTPUT_TOKENS)
|
|
130
|
+
|
|
131
|
+
params.get('temperature')
|
|
132
|
+
params.get('top_p')
|
|
133
|
+
params.get('stop_sequences')
|
|
134
|
+
thinking = params.pop('thinking', None)
|
|
135
|
+
metadata = params.pop('metadata', None)
|
|
136
|
+
|
|
137
|
+
# Standard mapped fields are already in params if they share names (temperature, top_p, stop_sequences)
|
|
138
|
+
# But we ensure they are set correctly if valid
|
|
139
|
+
# Actually, if they are in params, they are good.
|
|
140
|
+
# We just need to handle renaming/logic.
|
|
141
|
+
|
|
142
|
+
params['model'] = self.model_name
|
|
143
|
+
params['messages'] = self._to_anthropic_messages(request.messages)
|
|
144
|
+
params['max_tokens'] = int(max_tokens)
|
|
145
|
+
|
|
146
|
+
# Remove known genkit keys that don't map directly or are handled
|
|
147
|
+
params.pop('version', None) # If version was passed through config
|
|
148
|
+
|
|
149
|
+
if thinking and isinstance(thinking, dict):
|
|
150
|
+
anthropic_thinking: dict[str, str | int] = {}
|
|
151
|
+
# Handle boolean enabled -> type="enabled"
|
|
152
|
+
if thinking.get('enabled') is True or thinking.get('type') == 'enabled':
|
|
153
|
+
anthropic_thinking['type'] = 'enabled'
|
|
154
|
+
|
|
155
|
+
# Handle camelCase -> snake_case for budget tokens
|
|
156
|
+
tokens = thinking.get('budgetTokens', thinking.get('budget_tokens'))
|
|
157
|
+
if tokens:
|
|
158
|
+
anthropic_thinking['budget_tokens'] = int(tokens)
|
|
159
|
+
|
|
160
|
+
if anthropic_thinking.get('type') == 'enabled':
|
|
161
|
+
params['thinking'] = anthropic_thinking
|
|
162
|
+
# Note: Anthropic may require temperature to be None/excluded if thinking is
|
|
163
|
+
# enabled. Standard behavior is: if thinking, extended thinking model rules apply.
|
|
164
|
+
|
|
165
|
+
if metadata:
|
|
166
|
+
params['metadata'] = metadata
|
|
167
|
+
|
|
168
|
+
system = self._extract_system(request.messages)
|
|
169
|
+
if system:
|
|
170
|
+
params['system'] = system
|
|
171
|
+
|
|
172
|
+
if request.tools:
|
|
173
|
+
params['tools'] = [
|
|
174
|
+
{
|
|
175
|
+
'name': t.name,
|
|
176
|
+
'description': t.description,
|
|
177
|
+
'input_schema': t.input_schema,
|
|
178
|
+
}
|
|
179
|
+
for t in request.tools
|
|
180
|
+
]
|
|
181
|
+
|
|
182
|
+
if request.tool_choice:
|
|
183
|
+
if request.tool_choice == 'required':
|
|
184
|
+
params['tool_choice'] = {'type': 'any'}
|
|
185
|
+
elif request.tool_choice == 'auto':
|
|
186
|
+
params['tool_choice'] = {'type': 'auto'}
|
|
187
|
+
elif isinstance(request.tool_choice, dict):
|
|
188
|
+
params['tool_choice'] = request.tool_choice
|
|
189
|
+
|
|
190
|
+
return params
|
|
191
|
+
|
|
192
|
+
async def _generate_streaming(self, params: dict[str, Any], ctx: ActionRunContext) -> AnthropicMessage:
|
|
193
|
+
"""Handle streaming generation."""
|
|
194
|
+
async with self.client.messages.stream(**params) as stream:
|
|
195
|
+
async for chunk in stream:
|
|
196
|
+
if chunk.type == 'content_block_delta' and hasattr(chunk, 'delta') and hasattr(chunk.delta, 'text'):
|
|
197
|
+
ctx.send_chunk(
|
|
198
|
+
GenerateResponseChunk(
|
|
199
|
+
role=Role.MODEL,
|
|
200
|
+
index=0,
|
|
201
|
+
content=[Part(root=TextPart(text=str(chunk.delta.text)))],
|
|
202
|
+
)
|
|
203
|
+
)
|
|
204
|
+
return await stream.get_final_message()
|
|
205
|
+
|
|
206
|
+
def _extract_system(self, messages: list[Message]) -> str | None:
|
|
207
|
+
"""Extract system prompt from messages."""
|
|
208
|
+
for msg in messages:
|
|
209
|
+
if msg.role == Role.SYSTEM:
|
|
210
|
+
texts = []
|
|
211
|
+
for part in msg.content:
|
|
212
|
+
actual_part = part.root if isinstance(part, Part) else part
|
|
213
|
+
if isinstance(actual_part, TextPart):
|
|
214
|
+
texts.append(actual_part.text)
|
|
215
|
+
return ''.join(texts) if texts else None
|
|
216
|
+
return None
|
|
217
|
+
|
|
218
|
+
def _to_anthropic_messages(self, messages: list[Message]) -> list[dict[str, Any]]:
|
|
219
|
+
"""Convert Genkit messages to Anthropic format."""
|
|
220
|
+
result = []
|
|
221
|
+
for msg in messages:
|
|
222
|
+
if msg.role == Role.SYSTEM:
|
|
223
|
+
continue
|
|
224
|
+
role = 'assistant' if msg.role == Role.MODEL else 'user'
|
|
225
|
+
content: list[dict[str, Any]] = []
|
|
226
|
+
for part in msg.content:
|
|
227
|
+
actual_part = part.root if isinstance(part, Part) else part
|
|
228
|
+
if isinstance(actual_part, TextPart):
|
|
229
|
+
content.append({'type': 'text', 'text': actual_part.text})
|
|
230
|
+
elif isinstance(actual_part, MediaPart):
|
|
231
|
+
content.append(self._to_anthropic_media(actual_part))
|
|
232
|
+
elif isinstance(actual_part, ToolRequestPart):
|
|
233
|
+
content.append({
|
|
234
|
+
'type': 'tool_use',
|
|
235
|
+
'id': actual_part.tool_request.ref,
|
|
236
|
+
'name': actual_part.tool_request.name,
|
|
237
|
+
'input': actual_part.tool_request.input,
|
|
238
|
+
})
|
|
239
|
+
elif isinstance(actual_part, ToolResponsePart):
|
|
240
|
+
content.append({
|
|
241
|
+
'type': 'tool_result',
|
|
242
|
+
'tool_use_id': actual_part.tool_response.ref,
|
|
243
|
+
'content': str(actual_part.tool_response.output),
|
|
244
|
+
})
|
|
245
|
+
result.append({'role': role, 'content': content})
|
|
246
|
+
return result
|
|
247
|
+
|
|
248
|
+
def _to_anthropic_media(self, media_part: MediaPart) -> dict[str, Any]:
|
|
249
|
+
"""Convert media part to Anthropic format."""
|
|
250
|
+
url = media_part.media.url
|
|
251
|
+
if url.startswith('data:'):
|
|
252
|
+
_, base64_data = url.split(',', 1)
|
|
253
|
+
content_type = url.split(':')[1].split(';')[0]
|
|
254
|
+
return {
|
|
255
|
+
'type': 'image',
|
|
256
|
+
'source': {
|
|
257
|
+
'type': 'base64',
|
|
258
|
+
'media_type': content_type,
|
|
259
|
+
'data': base64_data,
|
|
260
|
+
},
|
|
261
|
+
}
|
|
262
|
+
return {'type': 'image', 'source': {'type': 'url', 'url': url}}
|
|
263
|
+
|
|
264
|
+
def _to_genkit_content(self, content_blocks: list[Any]) -> list[Part]:
|
|
265
|
+
"""Convert Anthropic response to Genkit format."""
|
|
266
|
+
parts = []
|
|
267
|
+
for block in content_blocks:
|
|
268
|
+
if block.type == 'text':
|
|
269
|
+
parts.append(Part(root=TextPart(text=block.text)))
|
|
270
|
+
elif block.type == 'tool_use':
|
|
271
|
+
parts.append(
|
|
272
|
+
Part(
|
|
273
|
+
root=ToolRequestPart(
|
|
274
|
+
tool_request=ToolRequest(
|
|
275
|
+
ref=block.id,
|
|
276
|
+
name=block.name,
|
|
277
|
+
input=block.input,
|
|
278
|
+
)
|
|
279
|
+
)
|
|
280
|
+
)
|
|
281
|
+
)
|
|
282
|
+
return parts
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# Copyright 2025 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
#
|
|
15
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
"""Anthropic plugin for Genkit."""
|
|
18
|
+
|
|
19
|
+
from typing import Any, cast
|
|
20
|
+
|
|
21
|
+
from anthropic import AsyncAnthropic
|
|
22
|
+
from genkit.ai import Plugin
|
|
23
|
+
from genkit.blocks.model import model_action_metadata
|
|
24
|
+
from genkit.core.action import Action, ActionMetadata
|
|
25
|
+
from genkit.core.registry import ActionKind
|
|
26
|
+
from genkit.core.schema import to_json_schema
|
|
27
|
+
from genkit.plugins.anthropic.model_info import SUPPORTED_ANTHROPIC_MODELS, get_model_info
|
|
28
|
+
from genkit.plugins.anthropic.models import AnthropicModel
|
|
29
|
+
from genkit.types import GenerationCommonConfig
|
|
30
|
+
|
|
31
|
+
ANTHROPIC_PLUGIN_NAME = 'anthropic'
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def anthropic_name(name: str) -> str:
|
|
35
|
+
"""Get Anthropic model name.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
name: The name of Anthropic model.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
Fully qualified Anthropic model name.
|
|
42
|
+
"""
|
|
43
|
+
return f'{ANTHROPIC_PLUGIN_NAME}/{name}'
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class Anthropic(Plugin):
|
|
47
|
+
"""Anthropic plugin for Genkit.
|
|
48
|
+
|
|
49
|
+
This plugin adds Anthropic models to Genkit for generative AI applications.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
name = ANTHROPIC_PLUGIN_NAME
|
|
53
|
+
|
|
54
|
+
def __init__(
|
|
55
|
+
self,
|
|
56
|
+
models: list[str] | None = None,
|
|
57
|
+
**anthropic_params: object,
|
|
58
|
+
) -> None:
|
|
59
|
+
"""Initializes Anthropic plugin with given configuration.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
models: List of model names to register. Defaults to all supported models.
|
|
63
|
+
**anthropic_params: Additional parameters passed to the AsyncAnthropic client.
|
|
64
|
+
This may include api_key, base_url, timeout, and other configuration
|
|
65
|
+
settings required by Anthropic's API.
|
|
66
|
+
"""
|
|
67
|
+
self.models = models or list(SUPPORTED_ANTHROPIC_MODELS.keys())
|
|
68
|
+
self._anthropic_params = anthropic_params
|
|
69
|
+
self._anthropic_client = AsyncAnthropic(**cast(dict[str, Any], anthropic_params))
|
|
70
|
+
|
|
71
|
+
async def init(self) -> list[Action]:
|
|
72
|
+
"""Initialize plugin.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
Empty list (using lazy loading via resolve).
|
|
76
|
+
"""
|
|
77
|
+
return []
|
|
78
|
+
|
|
79
|
+
async def resolve(self, action_type: ActionKind, name: str) -> Action | None:
|
|
80
|
+
"""Resolve an action by creating and returning an Action object.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
action_type: The kind of action to resolve.
|
|
84
|
+
name: The namespaced name of the action to resolve.
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
Action object if found, None otherwise.
|
|
88
|
+
"""
|
|
89
|
+
if action_type != ActionKind.MODEL:
|
|
90
|
+
return None
|
|
91
|
+
|
|
92
|
+
return self._create_model_action(name)
|
|
93
|
+
|
|
94
|
+
def _create_model_action(self, name: str) -> Action:
|
|
95
|
+
"""Create an Action object for an Anthropic model.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
name: The namespaced name of the model.
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
Action object for the model.
|
|
102
|
+
"""
|
|
103
|
+
# Extract local name (remove plugin prefix)
|
|
104
|
+
clean_name = name.replace(f'{ANTHROPIC_PLUGIN_NAME}/', '') if name.startswith(ANTHROPIC_PLUGIN_NAME) else name
|
|
105
|
+
|
|
106
|
+
model = AnthropicModel(model_name=clean_name, client=self._anthropic_client)
|
|
107
|
+
model_info = get_model_info(clean_name)
|
|
108
|
+
|
|
109
|
+
return Action(
|
|
110
|
+
kind=ActionKind.MODEL,
|
|
111
|
+
name=name,
|
|
112
|
+
fn=model.generate,
|
|
113
|
+
metadata={
|
|
114
|
+
'model': {
|
|
115
|
+
'supports': (
|
|
116
|
+
model_info.supports.model_dump(by_alias=True, exclude_none=True) if model_info.supports else {}
|
|
117
|
+
),
|
|
118
|
+
'customOptions': to_json_schema(GenerationCommonConfig),
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
async def list_actions(self) -> list[ActionMetadata]:
|
|
124
|
+
"""List available Anthropic models.
|
|
125
|
+
|
|
126
|
+
Returns:
|
|
127
|
+
List of ActionMetadata for all supported models.
|
|
128
|
+
"""
|
|
129
|
+
actions = []
|
|
130
|
+
for model_name, model_info in SUPPORTED_ANTHROPIC_MODELS.items():
|
|
131
|
+
actions.append(
|
|
132
|
+
model_action_metadata(
|
|
133
|
+
name=anthropic_name(model_name),
|
|
134
|
+
info=model_info.model_dump(by_alias=True, exclude_none=True),
|
|
135
|
+
config_schema=GenerationCommonConfig,
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
return actions
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: genkit-plugin-anthropic
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Genkit Anthropic Plugin
|
|
5
|
+
Project-URL: Bug Tracker, https://github.com/firebase/genkit/issues
|
|
6
|
+
Project-URL: Documentation, https://firebase.google.com/docs/genkit
|
|
7
|
+
Project-URL: Homepage, https://github.com/firebase/genkit
|
|
8
|
+
Project-URL: Repository, https://github.com/firebase/genkit/tree/main/py
|
|
9
|
+
Author: Google
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ai,anthropic,artificial-intelligence,claude,generative-ai,genkit,llm,machine-learning
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Environment :: Web Environment
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python
|
|
20
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
28
|
+
Classifier: Typing :: Typed
|
|
29
|
+
Requires-Python: >=3.10
|
|
30
|
+
Requires-Dist: anthropic>=0.40.0
|
|
31
|
+
Requires-Dist: genkit
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# Genkit Anthropic model provider Plugin
|
|
35
|
+
|
|
36
|
+
This Genkit plugin provides a set of tools and utilities for working with Anthropic.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
genkit/plugins/anthropic/__init__.py,sha256=oduWKut0uljJ2hzR2rrAOuNaBbURI-TUR6tslm0rb2g,14413
|
|
2
|
+
genkit/plugins/anthropic/model_info.py,sha256=7YKsJMtgw_w9o4kaHtN03MM10ZsvqweZuG3klRUiX2k,3773
|
|
3
|
+
genkit/plugins/anthropic/models.py,sha256=RbduryCgaZXE7w0X9UeA_voO1NGVzvccJaomkZEsJ9M,11218
|
|
4
|
+
genkit/plugins/anthropic/plugin.py,sha256=O8hKqQ81B_v918QUzY6OucJAw9_hO4zUDnOzk225L3k,4645
|
|
5
|
+
genkit/plugins/anthropic/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
genkit_plugin_anthropic-0.5.0.dist-info/METADATA,sha256=wfCgrgHnPlZGczOttcERR9S5EO2G-8zk49ENIS8rJR0,1561
|
|
7
|
+
genkit_plugin_anthropic-0.5.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
8
|
+
genkit_plugin_anthropic-0.5.0.dist-info/licenses/LICENSE,sha256=bsvE5_qSn_2LH2G-haMvT_AoIeINhX6fvzZTlyq2xJY,11340
|
|
9
|
+
genkit_plugin_anthropic-0.5.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 Google LLC
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|