Skip to main content

大模型对话标准接口。支持模板对话、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提示词模板引擎。
  • 改进:更灵活的服务初始化构造和调用。

Project details


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.2.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openai_simple_chat-0.1.2-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file openai_simple_chat-0.1.2.tar.gz.

File metadata

  • Download URL: openai_simple_chat-0.1.2.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for openai_simple_chat-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b0e9c0f7eae18ccae1a46de9741172f9a6ac9691ffcf5d4671ad5dc582fb1e00
MD5 2c128507183712a5b9bfd40f68e057ab
BLAKE2b-256 911073b6b4a3070d829fb710374a4ca81ce297f858b6edb93b7c8fafd1bd02ae

See more details on using hashes here.

File details

Details for the file openai_simple_chat-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for openai_simple_chat-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6975e53bc2ac45759957144c02278367e8618f1da4355ae283d93eb372a3d47d
MD5 d740b1b3d895b35065798617cf530de3
BLAKE2b-256 57eea78da2494e1c5c3b978670f138f28ff7ecddb545f344d7c44f2deed511dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page