通过Promptulate低代码解决方案轻松创建高效LLM Agent应用

  • 💖 作者简介:大家好,我是Zeeland,开源建设者与全栈领域优质创作者。
  • 📝 掘金主页:Zeeland🔥
  • 📣 我的博客:Zeeland
  • 📚 Github主页: Undertone0809 (Zeeland)
  • 🎉 支持我:点赞👍+收藏⭐️+留言📝
  • 💬介绍:The mixture of software dev+Iot+ml+anything🔥

简介

在LLM应用的开发中,开发者常常面临着选择合适的大型语言模型(LLM)和集成多样化工具的挑战。现在,有了promptulate库中的pne.chat()函数,这一切变得前所未有的简单。本文将介绍如何使用pne.chat()来构建强大而灵活的LLM应用。

项目Github: github.com/Undertone08...

相关文档

pne.chat():一站式AI对话解决方案

pne.chat()promptulate库的核心功能之一,它集成了多种LLM的能力,包括OpenAI、Anthropic、Cohere等超过100种不同的LLM。这意味着开发者可以通过一个统一的接口,调用不同的LLM API,极大地简化了开发流程。

像OpenAI一样调用

使用pne.chat()进行对话就像与OpenAI的GPT模型聊天一样简单。你只需要准备好对话消息,pne.chat()会自动处理格式转换,并返回响应。

python 复制代码
import promptulate as pne

messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Who are you?"},
]
response: str = pne.chat(messages=messages)
print(response)
text 复制代码
I am a helpful assistant designed to assist you with any questions or tasks you may have. How can I assist you today?

获取元数据

如果你需要更复杂的功能,元数据是非常重要的。通过设置return_raw_response=True,你可以获取原始响应,其中包含了元数据。

python 复制代码
import promptulate as pne

response = pne.chat(
    messages="When is your knowledge up to?",
    model="gpt-4-1106-preview"
)
print(response)
text 复制代码
My knowledge is up to date as of March 2021. Any events or developments occurring after that date would not be included in my responses. If you're asking for any recent information or updates, I recommend checking the latest sources as my information might not be current.

调用任意模型

pne.chat()支持调用超过100种LLM,你只需要提供相应的API密钥即可。以下是使用Anthropic的claude-2模型的示例:

python 复制代码
import os
import promptulate as pne

os.environ["ANTHROPIC_API_KEY"] = "你的API密钥"

response = pne.chat(messages=messages, model="claude-2")
print(response)

输出格式化

在构建复杂的Agent项目时,输出格式化是提高系统稳健性的必要措施。pne.chat()可以返回格式化的对象,这对于确保输出的一致性和可用性至关重要。

python 复制代码
from typing import List
import promptulate as pne
from pydantic import BaseModel, Field

class LLMResponse(BaseModel):
    provinces: List[str] = Field(description="中国所有省份")

response: LLMResponse = pne.chat(
    messages="请告诉我中国所有的省份。",
    output_schema=LLMResponse
)
print(response.provinces)
text 复制代码
I am an AI assistant here to help you with any questions or tasks you may have. How can I assist you today?
{'id': 'chatcmpl-8UK0tfwlkixWyaxKJ2XWNGMVGFPo0', 'choices': [{'finish_reason': 'stop', 'index': 0, 'message': {'content': 'I am an AI assistant here to help you with any questions or tasks you may have. How can I assist you today?', 'role': 'assistant'}}], 'created': 1702237461, 'model': 'gpt-3.5-turbo-0613', 'object': 'chat.completion', 'system_fingerprint': None, 'usage': {'completion_tokens': 25, 'prompt_tokens': 20, 'total_tokens': 45}, '_response_ms': 2492.372}

实时流式响应

pne.chat()还支持流式响应,这意味着你可以实时与你的助手进行交流。

python 复制代码
import promptulate as pne

response = pne.chat("你是谁?", stream=True)

for chunk in response:
    print(chunk)

pne.chat()的优势

  • 全面性:支持超过100种LLM,涵盖了市面上大多数主流的模型。
  • 易用性:统一的API接口,简化了从不同LLM获取响应的过程。
  • 灵活性:支持流式响应和格式化输出,适应不同的开发需求。
  • 扩展性:提供了插件、存储和LLM扩展的高级抽象,方便开发者根据需求进行定制。
  • 中文优化:针对中文场景进行了特别优化,更适合中文用户使用。

结语

pne.chat()作为一个一站式的AI对话开发解决方案,为开发者提供了前所未有的便利性和强大功能。无论是想要快速集成LLM,还是需要构建复杂的对话系统,pne.chat()都能大大降低开发难度,提高开发效率。随着promptulate未来对工具和检索方法的持续扩展,pne.chat()将成为LLM应用开发的不二选择。

相关推荐
程序员佳佳8 小时前
【万字硬核】从零构建企业级AI中台:基于Vector Engine整合GPT-5.2、Sora2与Veo3的落地实践指南
人工智能·gpt·chatgpt·ai作画·aigc·api·ai编程
kaizq8 小时前
AI-MCP-SQLite-SSE本地服务及CherryStudio便捷应用
python·sqlite·llm·sse·mcp·cherry studio·fastmcp
亚里随笔12 小时前
GenEnv:让AI智能体像人一样在_游戏_中成长
人工智能·游戏·llm·rl·agentic
sinat_2869451912 小时前
opencode
人工智能·算法·chatgpt
彼岸花开了吗14 小时前
构建AI智能体:八十、SVD知识整理与降维:从数据混沌到语义秩序的智能转换
人工智能·python·llm
栀秋66615 小时前
智能驱动的 Git 提交:基于 Ollama 大模型的规范化提交信息生成方案
react.js·llm·ollama
AI架构师易筋17 小时前
AIOps 告警归因中的提示工程:从能用到可上生产(4 阶梯)
开发语言·人工智能·llm·aiops·rag
小小宫城狮19 小时前
BPE 算法原理与训练实现
算法·llm
Blossom.11819 小时前
大模型自动化压缩:基于权重共享的超网神经架构搜索实战
运维·人工智能·python·算法·chatgpt·架构·自动化
开发者导航20 小时前
【开发者导航】ChatGPT Atlas 开源平替,一款免费的AI浏览器,让网页自动驾驶!
人工智能·chatgpt