Large Language Models Python API
Project description
Large Language Models Python API
Unified python API for multiple LLM providers including alibaba, baidu, deepseek, google, tencent, xunfei, zhipu, and openrouter.
Install
pip install chatchat
Quick Start
Terminal Chat
$ 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
from chatchat.client import Client
llm = Client('tencent', model='hunyuan-lite')
# completion
response = llm.complete('Hi')
# chat
response = llm.chat('Hello')
# stream
for chunk in llm.complete('Hello', generation_options={'stream': True}):
print(chunk, end='')
Tool Calling & Agent
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('zhipu', model='glm-4.7-flash', tools=[get_weather])
response = agent('How is the weather in Shanghai?')
SubAgent
from chatchat.agent import SubAgent, 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 = SubAgent(
name='travel_agent',
description='query tickets between cities',
provider='zhipu', model='glm-4.7-flash',
tools=[query_ticket],
)
agent = Agent('zhipu', model='glm-4.7-flash', tools=[travel_agent])
Configuration
# set API key
chatchat config <provider>.api_key=YOUR_API_KEY
# list supported providers
chatchat config --list
Refer to examples for more usage.
Sponsor
| 公众号 | |
|---|---|
| AliPay | WeChatPay |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
chatchat-0.4.10.tar.gz
(20.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
chatchat-0.4.10-py3-none-any.whl
(29.0 kB
view details)
File details
Details for the file chatchat-0.4.10.tar.gz.
File metadata
- Download URL: chatchat-0.4.10.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4049127a21b6b2ced8b32012ba119083f000017636c5891a4dbec6545e2f44ef
|
|
| MD5 |
d75aff67644dea42e63ff956f0270caf
|
|
| BLAKE2b-256 |
89a53d1cbdbf80e36277829a39284562a1bd60b2659e143261471f336b456316
|
File details
Details for the file chatchat-0.4.10-py3-none-any.whl.
File metadata
- Download URL: chatchat-0.4.10-py3-none-any.whl
- Upload date:
- Size: 29.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a83365b3abaead1812049125036bd156746303e73be693e151c933790ca9d363
|
|
| MD5 |
ba53eb600745dd8fb01888717f0d6485
|
|
| BLAKE2b-256 |
11dcf9f0e0d9e360edbd91e4eb645d720c36739354bca7545f2a8f1d1dfaace6
|