Skip to main content

XBrain通过装饰器将函数接入OpenAI的Chat

Project description

🤔解决了什么问题

OpenAI的Funciton Call很有用,但每次都需要在 chat 接口中引用Json或者Pydantic Model,而XBrain只需要在Python函数上放一个装饰器,就能自动将函数接入到 chat 中。

📄文档

Quick Start

安装xbrain:

pip install pyxbrain

在你的项目目录下创建一个demo.py文件,写入以下代码:

from pydantic import BaseModel
from xbrain.core import xbrain_tool
class GenerateTag(BaseModel):
    """创建一个新的插件"""
    pass

@xbrain_tool.Tool(model=GenerateTag)
def generate_tag():
    print("hello")

__init__.py文件中导入demo.py

from demo import *

在项目入口处配置并运行xbrain,此时demo.py中的generate_tag函数被成功接入了xbrain中:

from xbrain.core.chat import run 
from xbrain.utils.config import Config
config = Config()
config.set_openai_config(base_url="https://api.openai-next.com/v1", api_key="xxxxx", model="gpt-4o-2024-08-06")
messages = []
messages.append({"role": "user", "content": "配置tag"})
res = run(messages, user_prompt="从文章中提炼出关键信息")

🤝 如何贡献

你可以通过 Fork 项目、提交 PR 或在 Issue 中提出你的想法和建议。具体操作可参考贡献指南

强烈推荐阅读 《提问的智慧》《如何向开源社区提问题》《如何有效地报告 Bug》《如何向开源项目提交无法解答的问题》,更好的问题更容易获得帮助。

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

pyxbrain-1.1.31.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

pyxbrain-1.1.31-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file pyxbrain-1.1.31.tar.gz.

File metadata

  • Download URL: pyxbrain-1.1.31.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for pyxbrain-1.1.31.tar.gz
Algorithm Hash digest
SHA256 0c42fcd8f89b28d274a086a9093c3ef5f93acc7ee9e9c52f370ae61fc35680d0
MD5 a47d1becf78e7adc9364f5d99b25a41e
BLAKE2b-256 e83a8af57dd9e41a51af426469364fe2048e3f90d8ed87ed8643146db0bdea8d

See more details on using hashes here.

File details

Details for the file pyxbrain-1.1.31-py3-none-any.whl.

File metadata

  • Download URL: pyxbrain-1.1.31-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for pyxbrain-1.1.31-py3-none-any.whl
Algorithm Hash digest
SHA256 65290ee4e1a96ecac359f5bb2db14219fc7a7346abfc38464cb514b2858ef77d
MD5 1a25e1bdc70178c566d6e3e26711bd70
BLAKE2b-256 9f7eb3e95b2ad720ed0b86908c1687fee9f93937a0da175b5d63864de3dc0b4f

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