大模型对话标准接口。支持模板对话、JSON对话等。
Project description
openai-simple-chat
大模型对话标准接口。支持模板对话、JSON对话等。
安装
pip install openai-simple-chat
环境变量配置项
- OPENAI_BASE_URL # 支持openai兼容服务
- OPENAI_API_KEY
- OPENAI_CHAT_MODEL
- OLLAMA_BASE_URL # 支持ollama兼容服务
- OLLAMA_API_KEY
- OLLAMA_CHAT_MODEL
- OPENAI_SIMPLE_CHAT_TEMPLATE_ENGINE # 其它设置
- OPENAI_SIMPLE_CHAT_LOGGER_NAME
使用方法
test_templates/calc.txt
以标准json返回以下计算结果数值【输出格式为:{"result": xx}】:{{expression}}
main1.py
import openai_simple_chat
llm = openai_simple_chat.OpenAIChatService(
template_engine=openai_simple_chat.get_template_prompt_by_jinjia2,
template_root="test_templates",
)
response, response_info = llm.jsonchat(
template="calc.txt",
expression="1+1",
)
assert response
assert response_info
assert isinstance(response, dict)
assert isinstance(response_info, dict)
assert "result" in response
assert response["result"] == 2
# 注意,如果是stream_chat的话,response可能为空字符串。
main2.py
import openai_simple_chat
llm = openai_simple_chat.OllamaChatService(
template_engine=openai_simple_chat.get_template_prompt_by_jinjia2,
template_root="test_templates",
)
response, response_info = llm.jsonchat(template="calc.txt", expression="1+1")
assert response
assert response_info
assert isinstance(response, dict)
assert isinstance(response_info, dict)
assert "result" in response
assert response["result"] == 2
版本记录
v0.1.0
- 版本首发。
- 支持模板对话。
- 支持json对话。
- 兼容openai和ollama服务。
- 兼容django和jinja2模板引擎。
- jsonchat已经对deekseek输出的
think过程输出进行处理。
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
openai-simple-chat-0.1.0.tar.gz
(11.8 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
File details
Details for the file openai-simple-chat-0.1.0.tar.gz.
File metadata
- Download URL: openai-simple-chat-0.1.0.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73fe692554eaacb54491250d26ed90d9042bff0bb1937da8ee2e1e16fdd2c4f2
|
|
| MD5 |
f3302e66df8e983e1339ec8980f20fc0
|
|
| BLAKE2b-256 |
69282e96d502a6757a16d9b2c069a1db7f22e8c5faf724cfca0b7ca0bf58eb51
|
File details
Details for the file openai_simple_chat-0.1.0-py3-none-any.whl.
File metadata
- Download URL: openai_simple_chat-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37a3ba41913d7f2d42c7354894b848acd5d034e6bc2fd520d3a67444e70b4d33
|
|
| MD5 |
8c899465bb818921519d5f6bce27dac1
|
|
| BLAKE2b-256 |
0690fa62a696d0b2304053803002b55c336344a9b64e74f1ca1f077ed2a63f5c
|