Skip to main content

No project description provided

Project description

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.10 or 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()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autogen_xai_client-0.1.1.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autogen_xai_client-0.1.1-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file autogen_xai_client-0.1.1.tar.gz.

File metadata

  • Download URL: autogen_xai_client-0.1.1.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.14 Darwin/23.5.0

File hashes

Hashes for autogen_xai_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d7827a623d4e54e4eb8e9ef9198a50e89c59be9468104f98e845865f8e117106
MD5 325a52dc5914afe2af184b0104b851d7
BLAKE2b-256 04d66da524ad6e47f65d042863b41e09e09687a254782d78c59d05f9b4fb6143

See more details on using hashes here.

File details

Details for the file autogen_xai_client-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: autogen_xai_client-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.14 Darwin/23.5.0

File hashes

Hashes for autogen_xai_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5a58b7eca87f06614f458821eae09d528ed9cf2eaf498f99e548cef925fd7dd6
MD5 f8110343dde64d26f20452b704c58f6b
BLAKE2b-256 f64ee5d31d8546c44da0a5d5e11a6154fc3b8300e993fda023f1b6d8121d7539

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page