Skip to main content

一个简单的OpenAI API兼容封装库

Project description

CallAI

CallAI是一个简单易用的OpenAI API封装库,提供了更友好的接口和功能,使开发者能够更方便地使用大型语言模型。

安装

pip install callai

主要特性

  • 兼容OpenAI官方API
  • 简化的调用接口
  • 支持会话管理
  • 内置函数调用功能
  • 支持流式响应

快速开始

基本用法

from callai import AI

# 初始化客户端
ai = AI(api_key="your-api-key", default_model="gpt-3.5-turbo")

# 简单问答
response = ai.ask("请介绍一下Python语言的特点")
print(response)

# 使用系统提示
response = ai.ask("我应该如何入门Python?", system_prompt="你是一位编程教育专家")
print(response)

# 流式输出
for chunk in ai.stream_ask("讲一个关于AI的故事"):
    print(chunk, end="", flush=True)

会话管理

# 创建会话
session = ai.session(system_prompt="你是一位AI助手")

# 在会话中交流
response = session.ask("你好,请问你是谁?")
print(response)

response = session.ask("我们刚才聊了什么?")
print(response)

# 保存会话
session.save_json("my_session.json")

# 加载会话
restored_session = ai.load_json("my_session.json")

函数调用

from callai import AI, Tool

# 定义工具函数
@Tool.register
def get_weather(location: str, unit: str = "celsius"):
    """获取指定位置的天气信息
    
    Args:
        location: 位置名称,如"北京"
        unit: 温度单位,可选值为"celsius"或"fahrenheit"
    """
    # 模拟天气API返回
    return {"temperature": 25, "condition": "晴天", "location": location, "unit": unit}

# 使用工具函数
ai = AI(api_key="your-api-key")
result = ai.call_with_tools("北京今天的天气怎么样?")
print(result)

API参考

详细的API文档请访问我们的官方网站

许可证

本项目采用MIT许可证。详见LICENSE文件。

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

callai-0.2.1.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

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

callai-0.2.1-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file callai-0.2.1.tar.gz.

File metadata

  • Download URL: callai-0.2.1.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for callai-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6574e59df6df3885cd4634e2787a5d9ac6686750f5efb0fe830dc7fef5cfa6d3
MD5 2625645f56918dc0eecc8b8ffda861b4
BLAKE2b-256 bf7bbd71df633c51a8e63690e4813a277a359da3b61ff64ec045ef30c5df7641

See more details on using hashes here.

File details

Details for the file callai-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: callai-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for callai-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 834e2eb80be96a40b0cbc089b3b2b381730bd7efcdeff2b7a2c72cf8bfaf3efb
MD5 299b264793636a5b749cf64d546ffc10
BLAKE2b-256 b9e5e0bf905b0f3bc8759e0a05a99bf07de9da240058dd514566817b47bf31d8

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