Skip to main content
LibreChat is joining ClickHouse to power the open-source Agentic Data Stack 🎉 Learn more
LibreChat

Ollama

在 LibreChat 中将 Ollama 配置为自定义 endpoint。

Ollama 可在本地运行开源模型并提供兼容 OpenAI 的 API,因此你可以将 LibreChat 指向你自己的机器。使用 ollama run <model> 下载模型,并浏览 Ollama Library 中可用的模型。

配置

Ollama 会忽略 API key,但仍要求该字段必须存在,因此请将其设置为任意占位符。将 baseURL 指向您的 Ollama 服务器。在 librechat.yaml 中的 endpoints.custom 下添加该 endpoint:

    - name: "Ollama"
      apiKey: "ollama"
      # use 'host.docker.internal' instead of localhost if running LibreChat in a docker container
      baseURL: "http://localhost:11434/v1/" 
      models:
        default: [
          "llama2",
          "mistral",
          "codellama",
          "dolphin-mixtral",
          "mistral-openorca"
          ]
        # fetching list of models is supported but the `name` field must start
        # with `ollama` (case-insensitive), as it does in this example.
        fetch: true
      titleConvo: true
      titleModel: "current_model"
      summarize: false
      summaryModel: "current_model"
      modelDisplayLabel: "Ollama"

注意事项

  • titleModel 设置为 "current_model",以便标题生成时复用对话的模型,而不是加载第二个模型。这使得 Ollama 在每个对话中仅保持一个已加载的模型。
  • 上面的 default 数组是热门模型的示例列表。设置 fetch: true 后,LibreChat 将从您的服务器拉取完整列表。

Ollama -> llama3

一旦从 default parameters 中移除了 stop,以下问题将不再出现。

如果 llama3 一直生成而没有停止,请添加一个带有停止序列的 addParams 块:

    - name: "Ollama"
      apiKey: "ollama"
      baseURL: "http://host.docker.internal:11434/v1/"
      models:
        default: [
          "llama3"
        ]
        fetch: false # fetching list of models is not supported
      titleConvo: true
      titleModel: "current_model"
      summarize: false
      summaryModel: "current_model"
      modelDisplayLabel: "Ollama"
      addParams:
          "stop": [
              "<|start_header_id|>",
              "<|end_header_id|>",
              "<|eot_id|>",
              "<|reserved_special_token"
          ]

如果您只通过 Ollama 运行 llama3,在配置层面通过 addParams 设置 stop 是可以的。当您运行多个模型时,请改用前端的对话参数和预设来添加停止序列,并省略 addParams

    - name: "Ollama"
      apiKey: "ollama"
      baseURL: "http://host.docker.internal:11434/v1/" 
      models:
        default: [
          "llama3:latest",
          "mistral"
          ]
        fetch: false # fetching list of models is not supported
      titleConvo: true
      titleModel: "current_model"
      modelDisplayLabel: "Ollama"

在对话参数中设置停止序列(并将其保存为预设):

image

这篇指南怎么样?