问答接口
本文档详细描述了 AI+搜索的推理接口
目录
获取模型信息
描述
获取当前 AI 模型的相关信息,包括聊天模型提供者和嵌入模型提供者及其具体模型名称和显示名称。
请求
方法: GET
URL: http://192.168.3.9:3001/api/models
响应
{
"chatModelProviders": {
"openai": {
"gpt-3.5-turbo": {
"displayName": "GPT-3.5 Turbo"
},
"gpt-4": {
"displayName": "GPT-4"
},
"gpt-4-turbo": {
"displayName": "GPT-4 turbo"
},
"gpt-4o": {
"displayName": "GPT-4 omni"
},
"gpt-4o-mini": {
"displayName": "GPT-4 omni mini"
}
},
"custom_openai": {}
},
"embeddingModelProviders": {
"openai": {
"text-embedding-3-small": {
"displayName": "Text Embedding 3 Small"
},
"text-embedding-3-large": {
"displayName": "Text Embedding 3 Large"
}
},
"local": {
"xenova-bge-small-en-v1.5": {
"displayName": "BGE Small"
},
"xenova-gte-small": {
"displayName": "GTE Small"
},
"xenova-bert-base-multilingual-uncased": {
"displayName": "Bert Multilingual"
}
}
}
}
获取配置信息
描述
获取系统的配置信息,包括模型提供者列表及其对应的模型、各类 API 密钥等。
请求
方法: GET
URL: http://192.168.3.9:3001/api/config
响应
{
"chatModelProviders": {
"openai": [
{
"name": "gpt-3.5-turbo",
"displayName": "GPT-3.5 Turbo"
},
{
"name": "gpt-4",
"displayName": "GPT-4"
},
{
"name": "gpt-4-turbo",
"displayName": "GPT-4 turbo"
},
{
"name": "gpt-4o",
"displayName": "GPT-4 omni"
},
{
"name": "gpt-4o-mini",
"displayName": "GPT-4 omni mini"
}
],
"custom_openai": []
},
"embeddingModelProviders": {
"openai": [
{
"name": "text-embedding-3-small",
"displayName": "Text Embedding 3 Small"
},
{
"name": "text-embedding-3-large",
"displayName": "Text Embedding 3 Large"
}
],
"local": [
{
"name": "xenova-bge-small-en-v1.5",
"displayName": "BGE Small"
},
{
"name": "xenova-gte-small",
"displayName": "GTE Small"
},
{
"name": "xenova-bert-base-multilingual-uncased",
"displayName": "Bert Multilingual"
}
]
},
"openaiApiKey": "",
"ollamaApiUrl": "",
"anthropicApiKey": "",
"groqApiKey": "",
"geminiApiKey": ""
}
搜索与推理
本部分涵盖了通过 WebSocket 进行搜索和推理的具体操作流程,包括连接、消息传递及响应处理。
WebSocket 连接
URL:
ws://192.168.3.9:3001/?chatModel=gpt-3.5-turbo&chatModelProvider=openai&embeddingModel=text-embedding-3-small&embeddingModelProvider=openai
连接时需根据实际使用的模型名称和提供者调整查询参数。
响应初始信号
连接成功后,服务端发送以下消息表示会话已经打开:
{ "type": "signal", "data": "open" }
发送消息
发送用户问题时,需构造如下消息体。假设发送的问题为:"when is the first day of Kapiolani community college":
{
"type": "message",
"message": {
"messageId": "5b61edf4bc179e",
"chatId": "5a31859e83d0e45b6c5ba063091ff9403ed9eb3b",
"content": "when is the first day of Kapiolani community college"
},
"files": [],
"focusMode": "webSearch",
"optimizationMode": "speed",
"history": [["human", "when is the first day of Kapiolani community college"]]
}
接收服务器响应
服务器通过 WebSocket 发送两个主要类型的响应:
资源响应 (
sources
)包含相关页面内容及其元数据。
{ "type": "sources", "data": [ { "pageContent": "Last day to register, add, or change full-semester class sections. Last day to withdraw from full-semester classes with 100% tuition refund* online at www.star.hawaii.edu *Note: Full refund of student/program fees are given for complete withdrawal from all classes in the UH System before instruction begins or within the 100% refund period.", "metadata": { "title": "Academic Calendar | Kapi'olani Community College", "url": "https://www.kapiolani.hawaii.edu/classes/academic-calendar/" } } // 其他资源数据省略 ], "messageId": "32fcbbf251337c" }
消息响应 (
message
)服务器会分段发送回答内容,每段包含部分文本,最终以
messageEnd
表示消息结束。{"type":"message","data":"", "messageId": "32fcbbf251337c"} {"type":"message","data":"The","messageId":"32fcbbf251337c"} {"type":"message","data":" first","messageId":"32fcbbf251337c"} // 更多消息段 {"type":"messageEnd","messageId":"32fcbbf251337c"}
消息历史记录
客户端在每次发送问题时,必须携带完整的历史消息,以确保上下文的连贯性。例如:
{
"type": "message",
"message": {
"messageId": "bbd11e76ee1a9e",
"chatId": "100abb4a20b086458a693c8a0d3958d8063ead8d",
"content": "who am i"
},
"files": [],
"focusMode": "webSearch",
"optimizationMode": "speed",
"history": [
["human", "I'am Ping"],
[
"assistant",
"Hmm, sorry I could not find any relevant information on this topic. Would you like me to search again or ask something else?"
],
["human", "who am i"]
]
}
生成建议问题
描述
根据当前聊天历史生成相关的建议问题,帮助用户更好地继续对话。
请求
方法: POST
URL: http://192.168.3.9:3001/api/suggestions
示例请求:
{
"chatHistory": [
{
"content": "when is the first day of Kapiolani community college",
"messageId": "5b61edf4bc179e",
"chatId": "5a31859e83d0e45b6c5ba063091ff9403ed9eb3b",
"role": "user",
"createdAt": "2024-12-07T09:35:37.030Z"
},
{
"content": "The first day of Kapiʻolani Community College for the current academic year is September 2[9]. This date marks the beginning of the instructional period at the college. It's important to note that a late registration fee of $30.00 is charged for new registrations on or after the first day of instruction[11]. Additionally, tuition payment is typically due by 4:00 pm on the day of registration to ensure enrollment in classes[11].",
"messageId": "32fcbbf251337c",
"chatId": "5a31859e83d0e45b6c5ba063091ff9403ed9eb3b",
"role": "assistant",
"sources": [
{
"pageContent": "Last day to register, add, or change full-semester class sections. Last day to withdraw from full-semester classes with 100% tuition refund* online at www.star.hawaii.edu *Note: Full refund of student/program fees are given for complete withdrawal from all classes in the UH System before instruction begins or within the 100% refund period.",
"metadata": {
"title": "Academic Calendar | Kapi'olani Community College",
"url": "https://www.kapiolani.hawaii.edu/classes/academic-calendar/"
}
}
// 其他资源数据省略
],
"createdAt": "2024-12-07T09:35:40.955Z"
}
],
"chatModel": { "provider": "openai", "model": "gpt-3.5-turbo" }
}
响应
{
"suggestions": [
"What are the registration deadlines for Kapiʻolani Community College?",
"Can you provide more information about the tuition fees at Kapiʻolani Community College?",
"Are there any important dates or events to be aware of at Kapiʻolani Community College?",
"What are the academic calendar dates for Kapiʻolani Community College?"
]
}
获取网站 Logo
描述
通过指定网站的域名获取其对应的 Favicon(网站图标)。
使用方法
将目标网站的 URL 替换到以下模板中:
https://s2.googleusercontent.com/s2/favicons?domain_url=<目标网站URL>
示例
获取 Kapi'olani Community College 学术日历页面的 Logo:
https://s2.googleusercontent.com/s2/favicons?domain_url=https://www.kapiolani.hawaii.edu/classes/academic-calendar/
附录
模型提供者及其模型列表
聊天模型提供者 (chatModelProviders
)
- openai
gpt-3.5-turbo
: GPT-3.5 Turbogpt-4
: GPT-4gpt-4-turbo
: GPT-4 turbogpt-4o
: GPT-4 omnigpt-4o-mini
: GPT-4 omni mini
- custom_openai
- 暂无自定义模型
嵌入模型提供者 (embeddingModelProviders
)
- openai
text-embedding-3-small
: Text Embedding 3 Smalltext-embedding-3-large
: Text Embedding 3 Large
- local
xenova-bge-small-en-v1.5
: BGE Smallxenova-gte-small
: GTE Smallxenova-bert-base-multilingual-uncased
: Bert Multilingual
配置信息字段说明
- chatModelProviders: 聊天模型提供者及其模型列表。
- embeddingModelProviders: 嵌入模型提供者及其模型列表。
- openaiApiKey: OpenAI API 密钥。
- ollamaApiUrl: Ollama API 的 URL。
- anthropicApiKey: Anthropic API 密钥。
- groqApiKey: Groq API 密钥。
- geminiApiKey: Gemini API 密钥。
消息类型说明
- signal: 用于发送控制信号,如开启会话。
- message: 用于发送用户消息或接收助手消息。
- sources: 服务器返回的资源信息,包含相关页面内容和元数据。
- messageEnd: 表示消息传输结束。
以上文档旨在为 AI+搜索产品的开发提供全面、详尽的接口说明,确保开发过程顺利进行。如有任何疑问或需进一步的信息,请参考相关接口的详细描述或联系开发团队。