大模型对话标准接口。支持模板对话、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过程输出进行处理。
v0.1.1
- OpenAIService服务支持max_tokens参数。
v0.1.2
- 添加:get_template_prompt_by_django_template_source_engine提示词模板引擎。
- 改进:更灵活的服务初始化构造和调用。
v0.1.3
- 修正:直接使用template生成提示词而无需prompt的情况下报错的问题。
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.3.tar.gz
(17.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
File details
Details for the file openai_simple_chat-0.1.3.tar.gz.
File metadata
- Download URL: openai_simple_chat-0.1.3.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a93ffa2962021cd35d1907de30d912c0c2b26cf31cb237c6ae841f0a5101fdfc
|
|
| MD5 |
63ab4c3be2cedfcf3c0c76ff0f13cd28
|
|
| BLAKE2b-256 |
edbecc910f0407eedd3efaa469f6f51028810259d6c33c49a5a912967c7c2480
|
File details
Details for the file openai_simple_chat-0.1.3-py3-none-any.whl.
File metadata
- Download URL: openai_simple_chat-0.1.3-py3-none-any.whl
- Upload date:
- Size: 19.7 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 |
7c024ab129b596020603131e050c6e3c366d5199b17c01d72e594f31419db35f
|
|
| MD5 |
29ab42fbef20e77325dedc2e37fe1411
|
|
| BLAKE2b-256 |
574cc027e6fd04eebd041af4d3a72e7f0889bbdd7e794ef2841bf3fb243c721a
|