但面对如此多的选择,如何在减少开发成本的同时,能够统一地使用 OpenAI 的接口?如何能高效地持续监控 LLM 应用的运行表现,而又不增加额外的开发复杂度?在这些问题上,GreptimeAI 和 Xinference 提供了切实可行的解决方案。
GreptimeAI 构建在开源时序数据库 GreptimeDB 之上,是为大型语言模型(LLM)应用提供的一套可观测性的解决方案,目前已经支持 LangChain 和 OpenAI 的生态。GreptimeAI 使您能够实时全面地了解成本、性能、流量和安全性方面的情况,帮助团队提升 LLM 应用的可靠性。

启动 Xinference 模型服务
在本地启动 Xinference 模型服务的方式非常简单,只需要输入如下命令即可:
xinference-local -H 0.0.0.0
Web UI 方式启动模型
Xinference 启动之后,在浏览器中输入 http://localhost:9997 来访问 Web UI。

(The steps of Xinference starup)
命令行方式启动模型
我们也可以使用 Xinference 的命令行工具来启动模型,默认 Model UID 是 qwen-chat(后续将通过这个 ID 来访问模型)。
xinference launch -n qwen-chat -s 14 -f pytorch
假设我们有能力通过调用 get_current_weather 函数来获取指定城市的天气信息,参数为 location 和 format。
from greptimeai import openai_patcher
from openai improt OpenAI
client = OpenAI(
base_url="http://127.0.0.1:9997/v1",
)
openai_patcher.setup(client=client)
messages = [
{"role": "system", "content": "你是一个有用的助手。不要对要函数调用的值做出假设。"},
{"role": "user", "content": "上海现在的天气怎么样?"}
]
chat_completion = client.chat.completions.create(
model="qwen-chat",
messages=messages,
tools=tools,
temperature=0.7
)
print('func_name', chat_completion.choices[0].message.tool_calls[0].function.name)
print('func_args', chat_completion.choices[0].message.tool_calls[0].function.arguments)
tools = [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "获取当前天气",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "城市,例如北京",
},
"format": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "使用的温度单位。从所在的城市进行推断。",
},
},
"required": ["location", "format"],
},
},
}
]
chat_completion得到了 Qwen 模型生成的函数调用:
func_name: get_current_weather
func_args: {"location": "上海", "format": "celsius"}
获取 function call 结果并再次调用接口
这里假设我们用给定的参数调用了 get_current_weather 函数,并已经获取到了结果,将结果和上下文重新发送给 Qwen 模型:
messages.append(chat_completion.choices[0].message.model_dump())
messages.append({
"role": "tool",
"tool_call_id": messages[-1]["tool_calls"][0]["id"],
"name": messages[-1]["tool_calls"][0]["function"]["name"],
"content": str({"temperature": "10", "temperature_unit": "celsius"})
})
chat_completion = client.chat.completions.create(
model="qwen-chat",
messages=messages,
tools=tools,
temperature=0.7
)
print(chat_completion.choices[0].message.content)
最终结果
Qwen 模型最终将返回显示的响应如下所示:
上海现在的温度是 10 摄氏度。
GreptimeAI 看板

[1] https://github.com/xorbitsai/inference
[2] https://xorbits.cn/blogs/langchain-streamlit-doc-chat
如果你有任何疑问或建议,欢迎扫描下方小助手微信私聊我们~

关于 Greptime
Greptime 格睿科技于 2022 年创立,目前正在完善和打造时序数据库 GreptimeDB,格睿云 GreptimeCloud 和可观测工具 GreptimeAI 这三款产品。
GreptimeDB 是一款用 Rust 语言编写的时序数据库,具有分布式、开源、云原生、兼容性强等特点,帮助企业实时读写、处理和分析时序数据的同时,降低长期存储的成本。
GreptimeCloud 基于开源的 GreptimeDB,为用户提供全托管的 DBaaS,能够与可观测性、物联网等领域结合的应用产品结合。利用云提供软件和服务,可以达到快速的自助开通和交付,标准化的运维支持,和更好的资源弹性。
GreptimeAI 是为 LLM 应用量身定制的可观测性解决方案,开发者可以通过该方案全面、深入地了解应用的成本、性能、流量和安全情况,在保证低成本和高性能的同时提供高效可靠的分析能力,同时保留了时序数据库的灵活性。
GreptimeCloud 已正式公测,欢迎关注公众号或官网了解最新动态!
官网:https://greptime.cn/
GitHub: https://github.com/GreptimeTeam/greptimedb
文档:https://docs.greptime.cn/
Twitter: https://twitter.com/Greptime
Slack: https://greptime.com/slack
LinkedIn: https://www.linkedin.com/company/greptime/
往期精彩文章:


GreptimeDB 提供 Enterprise 企业版服务,如有需要请联系 info@greptime.com 或添加小助手微信(微信号:greptime).
👇 点击下方阅读原文,立即体验 GreptimeDB!





