
Security News
New CVE Forecasting Tool Predicts 47,000 Disclosures in 2025
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
OpenAI的Funciton Call很有用,但每次都需要在 chat 接口中引用Json或者Pydantic Model,而XBrain只需要在Python函数上放一个装饰器,就能自动将函数接入到 chat 中。
安装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》、《如何向开源项目提交无法解答的问题》,更好的问题更容易获得帮助。
FAQs
XBrain通过装饰器将函数接入OpenAI的Chat
We found that pyxbrain demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.