Skip to content

Commit 3f2e38b

Browse files
authored
feat(py): Implemented xai plugin (#4001)
1 parent 3e1c786 commit 3f2e38b

File tree

15 files changed

+1822
-4
lines changed

15 files changed

+1822
-4
lines changed

py/plugins/xai/LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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.

py/plugins/xai/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# xAI Sample
2+
3+
1. Setup environment and install dependencies:
4+
```bash
5+
uv venv
6+
source .venv/bin/activate
7+
8+
uv sync
9+
```
10+
11+
2. Set xAI API key:
12+
```bash
13+
export XAI_API_KEY=your-api-key
14+
```
15+
16+
3. Run the sample:
17+
```bash
18+
genkit start -- uv run src/xai_hello.py
19+
```

py/plugins/xai/conftest.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
"""Pytest configuration for xAI plugin tests."""
18+
19+
import sys
20+
from pathlib import Path
21+
22+
# Add src directory to path for test imports
23+
src_path = Path(__file__).parent / 'src'
24+
if str(src_path) not in sys.path:
25+
sys.path.insert(0, str(src_path))

py/plugins/xai/pyproject.toml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
[project]
18+
authors = [{ name = "Google" }]
19+
classifiers = [
20+
"Development Status :: 3 - Alpha",
21+
"Environment :: Console",
22+
"Environment :: Web Environment",
23+
"Intended Audience :: Developers",
24+
"Operating System :: OS Independent",
25+
"License :: OSI Approved :: Apache Software License",
26+
"Programming Language :: Python",
27+
"Programming Language :: Python :: 3 :: Only",
28+
"Programming Language :: Python :: 3.10",
29+
"Programming Language :: Python :: 3.11",
30+
"Programming Language :: Python :: 3.12",
31+
"Programming Language :: Python :: 3.13",
32+
"Programming Language :: Python :: 3.14",
33+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
34+
"Topic :: Software Development :: Libraries",
35+
]
36+
dependencies = [
37+
"genkit",
38+
"xai-sdk>=0.0.1",
39+
]
40+
description = "Genkit xAI Plugin"
41+
license = { text = "Apache-2.0" }
42+
name = "genkit-plugin-xai"
43+
readme = "README.md"
44+
requires-python = ">=3.10"
45+
version = "0.1.0"
46+
47+
[build-system]
48+
build-backend = "hatchling.build"
49+
requires = ["hatchling"]
50+
51+
[tool.hatch.build.targets.wheel]
52+
packages = ["src/genkit", "src/genkit/plugins"]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
"""xAI plugin for Genkit."""
18+
19+
from genkit.plugins.xai.plugin import XAI, xai_name
20+
21+
__all__ = ['XAI', 'xai_name']
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
"""xAI model information."""
18+
19+
from genkit.types import ModelInfo, Supports
20+
21+
__all__ = ['SUPPORTED_XAI_MODELS', 'get_model_info']
22+
23+
_LANGUAGE_MODEL_SUPPORTS = Supports(
24+
multiturn=True,
25+
tools=True,
26+
media=False,
27+
system_role=True,
28+
output=['text', 'json'],
29+
)
30+
31+
_VISION_MODEL_SUPPORTS = Supports(
32+
multiturn=False,
33+
tools=True,
34+
media=True,
35+
system_role=False,
36+
output=['text', 'json'],
37+
)
38+
39+
SUPPORTED_XAI_MODELS: dict[str, ModelInfo] = {
40+
'grok-3': ModelInfo(
41+
label='xAI - Grok 3',
42+
versions=['grok-3'],
43+
supports=_LANGUAGE_MODEL_SUPPORTS,
44+
),
45+
'grok-3-fast': ModelInfo(
46+
label='xAI - Grok 3 Fast',
47+
versions=['grok-3-fast'],
48+
supports=_LANGUAGE_MODEL_SUPPORTS,
49+
),
50+
'grok-3-mini': ModelInfo(
51+
label='xAI - Grok 3 Mini',
52+
versions=['grok-3-mini'],
53+
supports=_LANGUAGE_MODEL_SUPPORTS,
54+
),
55+
'grok-3-mini-fast': ModelInfo(
56+
label='xAI - Grok 3 Mini Fast',
57+
versions=['grok-3-mini-fast'],
58+
supports=_LANGUAGE_MODEL_SUPPORTS,
59+
),
60+
'grok-2-vision-1212': ModelInfo(
61+
label='xAI - Grok 2 Vision',
62+
versions=['grok-2-vision-1212'],
63+
supports=_VISION_MODEL_SUPPORTS,
64+
),
65+
}
66+
67+
68+
def get_model_info(name: str) -> ModelInfo:
69+
return SUPPORTED_XAI_MODELS.get(
70+
name,
71+
ModelInfo(
72+
label=f'xAI - {name}',
73+
supports=_LANGUAGE_MODEL_SUPPORTS,
74+
),
75+
)

0 commit comments

Comments
 (0)