大模型对话标准接口。支持模板对话、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的情况下报错的问题。
v0.1.4
- 添加:动态计算max_tokens的机制。
- 修改:移除max_input_tokens和max_output_tokens参数。
- 修正:openai的streaming_chat问题。
- 修正:ollama的对话问题。
v0.1.5
- 优化:非标准json输出的处理,支持半开json块的解析。
v0.1.6
- 优化:添加extra_messages参数。
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.6.tar.gz
(16.0 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.6.tar.gz.
File metadata
- Download URL: openai-simple-chat-0.1.6.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8162fdbbe9c0a54bf3ab88c76cc515ca206e9d5624ff6f72f6d87437df6e43b
|
|
| MD5 |
cfc7f8db7b89b36866a34da12739f69d
|
|
| BLAKE2b-256 |
afe97c655a38f003c36786831491d8954e8b811b89094a5f0a0cda0b36cc878b
|
File details
Details for the file openai_simple_chat-0.1.6-py3-none-any.whl.
File metadata
- Download URL: openai_simple_chat-0.1.6-py3-none-any.whl
- Upload date:
- Size: 20.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8463ba7ab47344b73be0df8e12a214914a0e483974c869d72ef827ec6b4e77a4
|
|
| MD5 |
7f262ef528246d43280b77d3b89d91f9
|
|
| BLAKE2b-256 |
745d3204e950f0687a27e909d60ef55b6e11e13fe422718a785454377284c884
|