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参数。

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.1.tar.gz (11.6 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.1-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file openai-simple-chat-0.1.1.tar.gz.

File metadata

  • Download URL: openai-simple-chat-0.1.1.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for openai-simple-chat-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1eb9aaf52e63b6979f34105314c4494e340f4bbcfac00199355cfa9dba813d0d
MD5 d9c3a0104ab769be75e15e911657f14e
BLAKE2b-256 c47240a744d8f25eeb81e2325b77b20649df185fe6cda18f746108772468b52e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openai_simple_chat-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4dc83870badfd2ad21007b2994b4b2011da63a4b5183eaace2bcbfb515e9839a
MD5 22850049f237c8d5e59707eb401ba62a
BLAKE2b-256 b1015a8da9e6bc5e1a76a3cad1db0752be873d7dcac3517531a26d0045ba276a

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