# Large Language Models Python API Unified python API for multiple LLM providers including `alibaba`, `baidu`, `deepseek`, `google`, `tencent`, `xunfei`, `zhipu`, and `openrouter`. ## Install ```shell pip install chatchat ``` ## Quick Start ### Terminal Chat ```shell $ chatchat run baidu ernie-lite-8k user> Hello assistant> Hello! How can I help you today? user> /exit $ chatchat run google gemini-2.5-flash --proxy YOUR_PROXY user> Introduce yourself briefly. assistant> Hello! I am a large language model... user> /exit ``` ### Python Client ```python from chatchat.client import Client llm = Client('tencent', model='hunyuan-lite') # chat response = llm.chat([{'role': 'user', 'content': 'Hello'}]) # stream for chunk in llm.chat([{'role': 'user', 'content': 'Hello'}], stream=True): print(chunk, end='') ``` ### Tool Calling & Agent ```python from chatchat.tool import tool from chatchat.agent import Agent @tool( name='get_weather', description='get weather for a city', parameters={ 'type': 'object', 'properties': { 'city': { 'type': 'string', 'description': 'the city name, e.g., Shanghai', } }, 'required': ['city'], } ) def get_weather(city): return f'{city} is Sunny.' agent = Agent(provider='zhipu', model='glm-4.7-flash', tools=[get_weather]) response = agent('How is the weather in Shanghai?') ``` ### Agent to Agent ```python from chatchat.agent import Agent from chatchat.tool import tool @tool( name='query_ticket', description='query train tickets', parameters={ 'type': 'object', 'properties': { 'from_city': { 'type': 'string', 'description': 'the city name, e.g., Shanghai', }, 'to_city': { 'type': 'string', 'description': 'the city name, e.g., Beijing', } }, 'required': ['from_city', 'to_city'], } ) def query_ticket(from_city, to_city): ... travel_agent = Agent( name='travel_agent', description='query tickets between cities', provider='zhipu', model='glm-4.7-flash', tools=[query_ticket], ) agent = Agent(provider='zhipu', model='glm-4.7-flash', tools=[travel_agent]) ``` ## Configuration ```shell # set API key chatchat config .api_key=YOUR_API_KEY # list supported providers chatchat config --list ``` > Refer to [examples](./examples) for more usage. ## Sponsor
公众号
AliPay.png
AliPay WeChatPay
AliPay.png WeChatPay.png