在创建您的对话式搜索代理时,您可以通过一些工具来扩展模型的功能。此页面列出了 Meilisearch 特有的工具,它们可以改善用户体验。
这是一项实验性功能。请使用 Meilisearch Cloud UI 或实验性功能端点来激活它
curl \
  -X PATCH 'MEILISEARCH_URL/experimental-features/' \
  -H 'Content-Type: application/json' \
  --data-binary '{
    "chatCompletions": true
  }'

Meilisearch 聊天工具

为了获得最佳用户体验,请配置所有以下工具。
  1. 通过在流式传输期间向用户显示搜索状态来处理进度更新
  2. 根据需要附加对话消息,以保持未来请求的上下文
  3. 向用户显示源文档以实现透明度和验证
  4. 使用 call_id 将进度更新与其相应的源结果相关联
这些特殊工具由 Meilisearch 内部处理,不会转发给 LLM 提供商。它们充当 Meilisearch 和您的应用程序之间的通信机制,以提供增强的用户体验功能。

_meiliSearchProgress

此工具报告内部搜索操作的实时进度。声明后,Meilisearch 将在后台执行搜索操作时调用此函数。 目的:提供搜索操作的透明度,并通过向用户显示幕后发生的事情来减少感知延迟。 参数
  • call_id:用于跟踪搜索操作的唯一标识符
  • function_name:正在执行的内部函数的名称(例如,“_meiliSearchInIndex”)
  • function_parameters:包含搜索参数(如 q (查询) 和 index_uid)的 JSON 编码字符串
响应示例:
{
  "function": {
    "name": "_meiliSearchProgress",
    "arguments": "{\"call_id\":\"89939d1f-6857-477c-8ae2-838c7a504e6a\",\"function_name\":\"_meiliSearchInIndex\",\"function_parameters\":\"{\\\"index_uid\\\":\\\"movies\\\",\\\"q\\\":\\\"search engine\\\"}\"}"
  }
}

_meiliAppendConversationMessage

由于 /chats/{workspace}/chat/completions 端点是无状态的,此工具通过请求客户端将内部消息附加到对话历史记录来帮助维护对话上下文。 目的:通过保留工具调用和结果来维护对话上下文,以提高后续请求的响应质量。 参数
  • role:消息作者角色(“user”或“assistant”)
  • content:消息内容(用于工具结果)
  • tool_calls:助手进行的工具调用数组
  • tool_call_id:此消息响应的工具调用的 ID
响应示例:
{
  "function": {
    "name": "_meiliAppendConversationMessage",
    "arguments": "{\"role\":\"assistant\",\"tool_calls\":[{\"id\":\"call_ijAdM42bixq9lAF4SiPwkq2b\",\"type\":\"function\",\"function\":{\"name\":\"_meiliSearchInIndex\",\"arguments\":\"{\\\"index_uid\\\":\\\"movies\\\",\\\"q\\\":\\\"search engine\\\"}\"}}]}"
  }
}

_meiliSearchSources

此工具提供 LLM 用于生成响应的源文档,从而实现透明度并允许用户验证信息来源。 目的:向用户显示哪些文档用于生成响应,从而提高信任度并实现源验证。 参数
  • call_id:与 _meiliSearchProgress 中的 call_id 匹配,以将查询与结果相关联
  • documents:包含仅显示属性的源文档的 JSON 对象
响应示例:
{
  "function": {
    "name": "_meiliSearchSources",
    "arguments": "{\"call_id\":\"abc123\",\"documents\":[{\"id\":197302,\"title\":\"The Sacred Science\",\"overview\":\"Diabetes. Prostate cancer...\",\"genres\":[\"Documentary\",\"Adventure\",\"Drama\"]}]}"
  }
}

OpenAI 工具声明示例

在请求的 tools 数组中包含这些工具以启用增强功能
{

  "tools": [
    {
      "type": "function",
      "function": {
        "name": "_meiliSearchProgress",
        "description": "Provides information about the current Meilisearch search operation",
        "parameters": {
          "type": "object",
          "properties": {
            "call_id": {
              "type": "string",
              "description": "The call ID to track the sources of the search"
            },
            "function_name": {
              "type": "string",
              "description": "The name of the function we are executing"
            },
            "function_parameters": {
              "type": "string",
              "description": "The parameters of the function we are executing, encoded in JSON"
            }
          },
          "required": ["call_id", "function_name", "function_parameters"],
          "additionalProperties": false
        },
        "strict": true
      }
    },
    {
      "type": "function",
      "function": {
        "name": "_meiliAppendConversationMessage",
        "description": "Append a new message to the conversation based on what happened internally",
        "parameters": {
          "type": "object",
          "properties": {
            "role": {
              "type": "string",
              "description": "The role of the messages author, either `role` or `assistant`"
            },
            "content": {
              "type": "string",
              "description": "The contents of the `assistant` or `tool` message. Required unless `tool_calls` is specified."
            },
            "tool_calls": {
              "type": ["array", "null"],
              "description": "The tool calls generated by the model, such as function calls",
              "items": {
                "type": "object",
                "properties": {
                  "function": {
                    "type": "object",
                    "description": "The function that the model called",
                    "properties": {
                      "name": {
                        "type": "string",
                        "description": "The name of the function to call"
                      },
                      "arguments": {
                        "type": "string",
                        "description": "The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function."
                      }
                    }
                  },
                  "id": {
                    "type": "string",
                    "description": "The ID of the tool call"
                  },
                  "type": {
                    "type": "string",
                    "description": "The type of the tool. Currently, only function is supported"
                  }
                }
              }
            },
            "tool_call_id": {
              "type": ["string", "null"],
              "description": "Tool call that this message is responding to"
            }
          },
          "required": ["role", "content", "tool_calls", "tool_call_id"],
          "additionalProperties": false
        },
        "strict": true
      }
    },
    {
      "type": "function",
      "function": {
        "name": "_meiliSearchSources",
        "description": "Provides sources of the search",
        "parameters": {
          "type": "object",
          "properties": {
            "call_id": {
              "type": "string",
              "description": "The call ID to track the original search associated to those sources"
            },
            "documents": {
              "type": "object",
              "description": "The documents associated with the search (call_id). Only the displayed attributes of the documents are returned"
            }
          },
          "required": ["call_id", "documents"],
          "additionalProperties": false
        },
        "strict": true
      }
    }
  ]
}
© . This site is unofficial and not affiliated with Meilisearch.