GPT-4o搜索模型服务

一个通过MCP协议提供OpenAI GPT-4o搜索预览模型访问的服务,适用于需要集成高级搜索功能的开发场景。

  • by jedarden
  • Python
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 jedarden/gpt-4o-search-mcp

使用说明

项目概述

模型上下文协议(MCP)服务器,使OpenAI的gpt-4o-search-preview模型可以通过MCP访问。

  • app/app.py:主要应用程序入口点。
  • requirements.txt:列出运行应用程序所需的Python依赖项。
  • dockerfile:在Docker容器中构建和运行应用程序的说明。
  • .env.example:示例环境变量文件。将此复制到 .env 并根据需要更新值。

部署说明

1.环境变量

在运行应用程序之前,请设置环境变量:

  1. 复制 .env.example 向 .env:
    cp .env.example .env
    
  2. 编辑 .env 并根据您的环境需要更新这些值。

2.使用Docker部署

  1. 构建Docker镜像:
    docker build -t my-python-app -f dockerfile .
    
  2. 运行容器:
    docker run --env-file .env -p 8000:8000 my-python-app
    

3.使用Python(virtualenv)进行部署

  1. 创建并激活虚拟环境:
    python3 -m venv venv
    source venv/bin/activate
    
  2. 安装依赖项:
    pip install -r requirements.txt
    
  3. 设置环境变量(请参见 .env.example).
  4. 运行应用程序:
    python app/app.py
    

示例:使用roo代码连接到MCP

下面是一个示例配置块 gpt-4o-search MCP服务:

"gpt-4o-search": {
  "url": "http://link-to-where-service-is-hosted:8000/sse",
  "transport": "http",
  "alwaysAllow": [
    "search"
  ],
  "timeout": 300
}

Python示例:执行“搜索”操作

以下Python代码演示了如何使用上述配置连接到MCP服务,并使用roo代码原理执行“搜索”操作。此示例使用 requests 库向MCP端点发送搜索请求。

from mcp import MCPClient

# Initialize the MCP client for the gpt-4o-search server
client = MCPClient("http://link-to-where-service-is-hosted:8000/sse")

# Perform a "search" operation
result = client.tool("search", {"query": "What is Model Context Protocol?"})

print("Search result:", result)
### Explanation

- **MCPClient**: The official `mcp` Python library provides the `MCPClient` class to connect to an MCP server.
- **client = MCPClient(...)**: Initializes the client with the URL of the gpt-4o-search MCP server.
- **client.tool("search", {...})**: Performs the "search" operation by specifying the tool name and parameters as a dictionary.
- **Result**: The result of the search operation is printed.

---
# Notes

- Only perform the work outlined above and do not deviate from these instructions.
- For further details, refer to the individual files and comments within the codebase.```