Skip to main content

ErisPulse OpenAI 通用接口封装模块

Project description

ErisPulse-OpenAI 模块文档

简介

ErisPulse-OpenAI 是一个 OpenAI 通用接口的封装模块,提供了便捷的异步接口来与 OpenAI API 交互。

使用示例

基本使用

from ErisPulse import sdk

# 初始化模块
openai = sdk.OpenAI

# 同步聊天
messages = [{"role": "user", "content": "你好"}]
response = await openai.chat(messages)
print(response)

# 流式聊天
async for chunk in openai.chat_stream(messages):
    print(chunk, end="", flush=True)

自定义配置

# 自定义模型和参数
response = await openai.chat(
    messages,
    model="gpt-4",
    temperature=0.5,
    max_tokens=500
)

流式处理回调

async def handle_stream(content):
    print(content, end="", flush=True)

response = await openai.chat(
    messages,
    stream=True,
    stream_handler=handle_stream
)

API 参考

chat(messages, model=None, stream=False, stream_handler=None, **kwargs)

  • messages: List[Dict[str, str]] - 对话消息列表
  • model: Optional[str] - 指定模型,默认为配置中的模型
  • stream: bool - 是否使用流式响应
  • stream_handler: Optional[Callable] - 流式响应的回调函数
  • **kwargs: 其他 OpenAI API 参数
  • 返回: str - AI 响应内容

chat_stream(messages, model=None, **kwargs)

  • messages: List[Dict[str, str]] - 对话消息列表
  • model: Optional[str] - 指定模型,默认为配置中的模型
  • **kwargs: 其他 OpenAI API 参数
  • 返回: AsyncGenerator[str, None] - 流式响应生成器

配置说明

需要在项目的 config.toml 中配置OpenAI相关参数

参考链接

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

erispulse_openai-2.1.2.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

erispulse_openai-2.1.2-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file erispulse_openai-2.1.2.tar.gz.

File metadata

  • Download URL: erispulse_openai-2.1.2.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for erispulse_openai-2.1.2.tar.gz
Algorithm Hash digest
SHA256 5292f57fdb88e1311b2ab36c2eb5c3e4df6d19da2bbfce7e06c12f120181289f
MD5 71685023adafd2083a3cba1279100991
BLAKE2b-256 9680d97dec8cf4fc62ebde154f7149df3259d11ac98936fd61b739b1f0b81a68

See more details on using hashes here.

Provenance

The following attestation bundles were made for erispulse_openai-2.1.2.tar.gz:

Publisher: python-publish.yml on ErisPulse/ErisPulse-OpenAI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file erispulse_openai-2.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for erispulse_openai-2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 236801e94d13c006c9c4f32276ce10bd0b9e3ddf7473581006f2a4d4ad28080f
MD5 2725c0f853b371c93f3386a69088b1eb
BLAKE2b-256 10a7c0c2778c9fd55697e3fb2f3d6f862febc90401133d70a706bc602a894ed1

See more details on using hashes here.

Provenance

The following attestation bundles were made for erispulse_openai-2.1.2-py3-none-any.whl:

Publisher: python-publish.yml on ErisPulse/ErisPulse-OpenAI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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