autogen-xai-client
This is an autogen>=0.4 extension for xai client integration.
Disclaimer
- This project is still in a very early stage under development, please create issues in this github repo for bug reports.
- This project is a personal endeavor and is not affiliated with, endorsed by, or connected to any organization/employer in any way. The views, ideas, and opinions expressed in this project are solely my own and do not reflect those of others.
Usage
Prerequisites
- create a python environment with version
3.10or above pip install --upgrade autogen-xai-client
code snippets
Importing dependencies:
import os
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.task import Console, TextMentionTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_xai_client import XAIChatCompletionClient
from autogen_xai_client.config import XAIClientConfiguration
Create a xai client
xai_client = XAIChatCompletionClient(
base_url="https://api.x.ai/v1",
model="grok-beta",
api_key="<api_key>",
)
Define an agent using the xai client and register a dummy tool for querying weather
# Define a tool
async def get_weather(city: str) -> str:
return f"The weather in {city} is 73 degrees and Sunny."
async def main() -> None:
# Define an agent
weather_agent = AssistantAgent(
name="weather_agent",
model_client=wx_client,
tools=[get_weather],
)
# Define termination condition
termination = TextMentionTermination("TERMINATE")
# Define a team
agent_team = RoundRobinGroupChat([weather_agent], termination_condition=termination)
# Run the team and stream messages to the console
stream = agent_team.run_stream(task="What is the weather in New York?")
await Console(stream)
# NOTE: if running this inside a Python script you'll need to use asyncio.run(main()).
await main()
Metadata
Release files for autogen-xai-client 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| autogen_xai_client-0.1.1.tar.gz | 12.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autogen_xai_client-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.4 kB
Release files / autogen_xai_client-0.1.1.tar.gz
| Download URL | autogen_xai_client-0.1.1.tar.gz |
|---|---|
| Size | 12.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d7827a623d4e54e4eb8e9ef9198a50e89c59be9468104f98e845865f8e117106
|
|
BLAKE2b-256 checksum How to use checksums |
04d66da524ad6e47f65d042863b41e09e09687a254782d78c59d05f9b4fb6143
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.14 Darwin/23.5.0
|
Release files / autogen_xai_client-0.1.1-py3-none-any.whl
| Download URL | autogen_xai_client-0.1.1-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5a58b7eca87f06614f458821eae09d528ed9cf2eaf498f99e548cef925fd7dd6
|
|
BLAKE2b-256 checksum How to use checksums |
f64ee5d31d8546c44da0a5d5e11a6154fc3b8300e993fda023f1b6d8121d7539
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.14 Darwin/23.5.0
|