mcpllm推理机
引言
这 mcp_llm_inferencer 是一个开源库,旨在利用大型语言模型(LLM)的强大功能,如Claude和OpenAI的GPT,将提示映射输入转换为MCP服务器的具体组件。这些组件包括工具、资源模板和提示处理程序,使其成为使用MCP服务器环境的开发人员的通用工具。
特性
- LLM呼叫引擎:通过内置的重试和回退逻辑高效地调用LLM,以确保可靠的响应。
- 可互换的Claude和OpenAI支持:根据您的偏好或可用性在Claude和OpenAI API之间无缝切换。
- Claude Desktop的流媒体支持:直接从Claude Desktop流式传输响应,提供实时反馈。
- 工具和资源响应验证:确保生成的工具和资源在部署前符合预定义的标准。
- 结构化输出捆绑:将输出组织成每个组件的结构化包,简化了集成和使用。
安装说明
先决条件
- Python 3.6或更高版本
- 来自Claude或OpenAI的API密钥
安装 mcp_llm_inferencer
- 克隆存储库:
git clone https://github.com/your-repo/mcp_llm_inferencer.git
cd mcp_llm_inferencer- 使用pip安装软件包:
pip install .- 将API键设置为环境变量:
- 对于克劳德:
export CLAUDE_API_KEY='your-claude-api-key'- 对于OpenAI:
export OPENAI_API_KEY='your-openai-api-key'使用示例
基础示例
下面是一个简单的示例,演示如何使用 mcp_llm_inferencer 使用OpenAI API:
from mcp_llm_inferencer import MCPInferencer
# Initialize the inferencer with OpenAI API
inferencer = MCPInferencer(api_type='openai')
# Define your prompt
prompt = "Generate a tool to extract emails from text."
# Generate components
components = inferencer.generate_components(prompt)
print(components)Claude的高级示例
此示例显示如何将库与Claude API一起使用并处理流式响应:
from mcp_llm_inferencer import MCPInferencer
# Initialize the inferencer with Claude API
inferencer = MCPInferencer(api_type='claude', stream=True)
# Define your prompt
prompt = "Create a resource template for an S3 bucket."
# Generate components with streaming support
for component in inferencer.generate_components(prompt):
print(component)API文档
类别: MCPInferencer
初始化
MCPInferencer(api_type, api_key=None, stream=False)- api_type (str):要使用的LLM API的类型('crude'或'openai')。
- api_key (str,可选):指定LLM的API密钥。如果没有提供,它将尝试从环境变量中读取。
- 流 (bool,可选):为Claude Desktop启用流媒体支持。
方法
- generate_components(提示)
- 根据给定的提示生成MCP服务器组件。 - 提示 (str):要发送给LLM的输入提示。 - 返回:包含生成组件的字典或字典流。
方法使用示例
components = inferencer.generate_components("Generate a tool for sentiment analysis.")许可证
mcp_llm_inferencer 根据MIT许可证发布。请参阅 许可证 文件以获取更多详细信息。
______________________________________________________________________
请随时为 mcp_llm_inferencer 通过在我们的 .
⚠️ 开发状态
这个图书馆目前处于早期开发阶段。某些测试可能因以下问题而失败:
欢迎为解决这些问题做出贡献!如果您有解决方案,请提交拉取请求。

