Ollama 통합

Ollama 통합

LangChain JavaScript로 Ollama LLM과 통합하는 방법을 알아봅니다.

Ollama는 Llama 3 같은 오픈소스 대규모 언어 모델(LLM)을 로컬에서 실행할 수 있게 해줘요. LangChain으로 Ollama 텍스트 완성 모델(LLM)을 시작하는 데 도움을 주는 가이드입니다. Ollama 기능과 구성 옵션에 대한 자세한 문서는 API reference를 참조하세요.

출처: 문서

본문

현재 이 페이지는 Ollama 모델을 텍스트 완성 모델로 사용하는 방법을 다루는 문서예요. Ollama에서 제공하는 많은 인기 모델은 챗 완성 모델입니다.

아마 이 페이지를 찾고 계실 수도 있어요.

개요

통합 세부 정보

Ollama는 Llama 3 같은 오픈소스 대규모 언어 모델(LLM)을 로컬에서 실행할 수 있게 해줍니다.

Ollama는 모델 가중치, 구성, 데이터를 Modelfile로 정의된 단일 패키지로 묶습니다. GPU 사용을 포함한 설정·구성 세부 사항을 최적화합니다.

이 예제는 LangChain을 사용해 Ollama로 실행되는 Llama 2 7b 인스턴스와 상호작용하는 방법을 다룹니다. 지원되는 모델과 모델 변형의 전체 목록은 Ollama 모델 라이브러리를 참조하세요.

클래스(Class) 패키지(Package) 로컬(Local) 직렬화(Serializable) PY 지원 다운로드(Downloads) 버전(Version)
Ollama @langchain/ollama NPM - Downloads NPM - Version

설정

Ollama LLM 모델에 접근하려면 다음 지침에 따라 Ollama를 설치한 뒤 @langchain/ollama 통합 패키지를 설치하세요.

자격 증명(Credentials)

모델 호출에 대한 자동 추적을 받으려면 아래 주석을 해제해 LangSmith API 키를 설정할 수도 있습니다:

# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"

설치

LangChain Ollama 통합은 @langchain/ollama 패키지에 있습니다:

npm install @langchain/ollama @langchain/core
yarn add @langchain/ollama @langchain/core
pnpm add @langchain/ollama @langchain/core

인스턴스화(Instantiation)

이제 모델 객체를 인스턴스화하고 채팅 완성을 생성할 수 있습니다:

import { Ollama } from "@langchain/ollama"

const llm = new Ollama({
  model: "llama3", // Default value
  temperature: 0,
  maxRetries: 2,
  // other params...
})

호출(Invocation)

const inputText = "Ollama is an AI company that "

const completion = await llm.invoke(inputText)
completion
I think you meant to say "Olivia" instead of "Ollama". Olivia is not a well-known AI company, but there are several other AI companies with similar names. Here are a few examples:

* Oliva AI: A startup that uses artificial intelligence to help businesses optimize their operations and improve customer experiences.
* Olivia Technologies: A company that develops AI-powered solutions for industries such as healthcare, finance, and education.
* Olivia.ai: A platform that uses AI to help businesses automate their workflows and improve productivity.

If you meant something else by "Ollama", please let me know and I'll do my best to help!

멀티모달 모델(Multimodal models)

Ollama는 0.1.15 버전 이상에서 LLaVA 같은 오픈소스 멀티모달 모델을 지원합니다. base64로 인코딩된 이미지 데이터를 멀티모달 지원 모델에 바인딩해 컨텍스트로 사용할 수 있습니다:

import { Ollama } from "@langchain/ollama";
import * as fs from "node:fs/promises";

const imageData = await fs.readFile("../../../../../examples/hotdog.jpg");

const model = new Ollama({
  model: "llava",
}).bind({
  images: [imageData.toString("base64")],
});

const res = await model.invoke("What's in this image?");
console.log(res);
 The image shows a hot dog placed inside what appears to be a bun that has been specially prepared to resemble a hot dog bun. This is an example of a creative or novelty food item, where the bread used for the bun looks similar to a cooked hot dog itself, playing on the name "hot dog." The image also shows the typical garnishes like ketchup and mustard on the side.

관련 자료(Related)


API reference

모든 Ollama 기능과 구성에 대한 자세한 문서는 API reference를 참조하세요.

더 알아보기 (Learn more)