Skip to main content
Ollama allows you to run open-source Large Language Models (LLMs), such as Llama 3.1, locally. Ollama bundles model weights, configuration, and data into a single package, defined by a Modelfile. It optimizes setup and configuration details, including GPU usage. 本指南将帮助你开始使用 ChatOllama chat models。有关所有 ChatOllama 功能和配置的详细文档,请前往 API 参考

概述

集成详情

Ollama allows you to use a wide range of models with different capabilities. Some of the fields in the details table below only apply to a subset of models that Ollama offers. For a complete list of supported models and model variants, see the Ollama model library and search by tag.

模型功能

请参阅下表标题中的链接,了解如何使用特定功能。

设置

Follow these instructions to set up and run a local Ollama instance. Then, download the @langchain/ollama package.

凭证

如果你想要自动追踪模型调用,还可以设置你的 LangSmith API 密钥,取消注释以下内容:

安装

LangChain 的 ChatOllama 集成位于 @langchain/ollama 包中:

实例化

现在我们可以实例化模型对象并生成聊天补全:

调用

Tools

Ollama now offers support for native tool calling for a subset of their available models. The example below demonstrates how you can invoke a tool from an Ollama model.

结构化输出

Ollama natively supports structured output for all models, allowing you to force the model to return a specific format by calling .withStructuredOutput().
If you prefer to use structured output via tool calling, pass the method: "functionCalling" option:

Multimodal models

Ollama supports open source multimodal models like LLaVA in versions 0.1.15 and up. You can pass images as part of a message’s content field to multimodal-capable models like this:

API 参考

有关所有 ChatOllama 功能和配置的详细文档,请前往 API 参考