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
13 changes: 13 additions & 0 deletions py/plugins/xai/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2025 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
19 changes: 19 additions & 0 deletions py/plugins/xai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# xAI Sample

1. Setup environment and install dependencies:
```bash
uv venv
source .venv/bin/activate

uv sync
```

2. Set xAI API key:
```bash
export XAI_API_KEY=your-api-key
```

3. Run the sample:
```bash
genkit start -- uv run src/xai_hello.py
```
25 changes: 25 additions & 0 deletions py/plugins/xai/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

"""Pytest configuration for xAI plugin tests."""

import sys
from pathlib import Path

# Add src directory to path for test imports
src_path = Path(__file__).parent / 'src'
if str(src_path) not in sys.path:
sys.path.insert(0, str(src_path))
52 changes: 52 additions & 0 deletions py/plugins/xai/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

[project]
authors = [{ name = "Google" }]
classifiers = [
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Software Development :: Libraries",
]
dependencies = [
"genkit",
"xai-sdk>=0.0.1",
]
description = "Genkit xAI Plugin"
license = { text = "Apache-2.0" }
name = "genkit-plugin-xai"
readme = "README.md"
requires-python = ">=3.10"
version = "0.1.0"

[build-system]
build-backend = "hatchling.build"
requires = ["hatchling"]

[tool.hatch.build.targets.wheel]
packages = ["src/genkit", "src/genkit/plugins"]
21 changes: 21 additions & 0 deletions py/plugins/xai/src/genkit/plugins/xai/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

"""xAI plugin for Genkit."""

from genkit.plugins.xai.plugin import XAI, xai_name

__all__ = ['XAI', 'xai_name']
75 changes: 75 additions & 0 deletions py/plugins/xai/src/genkit/plugins/xai/model_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

"""xAI model information."""

from genkit.types import ModelInfo, Supports

__all__ = ['SUPPORTED_XAI_MODELS', 'get_model_info']

_LANGUAGE_MODEL_SUPPORTS = Supports(
multiturn=True,
tools=True,
media=False,
system_role=True,
output=['text', 'json'],
)

_VISION_MODEL_SUPPORTS = Supports(
multiturn=False,
tools=True,
media=True,
system_role=False,
output=['text', 'json'],
)

SUPPORTED_XAI_MODELS: dict[str, ModelInfo] = {
'grok-3': ModelInfo(
label='xAI - Grok 3',
versions=['grok-3'],
supports=_LANGUAGE_MODEL_SUPPORTS,
),
'grok-3-fast': ModelInfo(
label='xAI - Grok 3 Fast',
versions=['grok-3-fast'],
supports=_LANGUAGE_MODEL_SUPPORTS,
),
'grok-3-mini': ModelInfo(
label='xAI - Grok 3 Mini',
versions=['grok-3-mini'],
supports=_LANGUAGE_MODEL_SUPPORTS,
),
'grok-3-mini-fast': ModelInfo(
label='xAI - Grok 3 Mini Fast',
versions=['grok-3-mini-fast'],
supports=_LANGUAGE_MODEL_SUPPORTS,
),
'grok-2-vision-1212': ModelInfo(
label='xAI - Grok 2 Vision',
versions=['grok-2-vision-1212'],
supports=_VISION_MODEL_SUPPORTS,
),
}


def get_model_info(name: str) -> ModelInfo:
return SUPPORTED_XAI_MODELS.get(
name,
ModelInfo(
label=f'xAI - {name}',
supports=_LANGUAGE_MODEL_SUPPORTS,
),
)
Loading
Loading