Skip to main content
Open In ColabOpen on GitHub

LocalAI

info

langchain-localai 是一个用于 LocalAI 的第三方集成包。它提供了一种在 Langchain 中使用 LocalAI 服务的方法。

源代码可在 Github 上找到。

让我们加载 LocalAI Embedding 类。为了使用 LocalAI Embedding 类,您需要在某个地方托管 LocalAI 服务并配置 embedding 模型。请参阅文档 https://localai.io/basics/getting_started/index.htmlhttps://localai.io/features/embeddings/index.html。

%pip install -U langchain-localai
from langchain_localai import LocalAIEmbeddings
embeddings = LocalAIEmbeddings(
openai_api_base="http://localhost:8080", model="embedding-model-name"
)
text = "This is a test document."
query_result = embeddings.embed_query(text)
doc_result = embeddings.embed_documents([text])

让我们使用第一代模型(例如 text-search-ada-doc-001/text-search-ada-query-001)来加载 LocalAI Embedding 类。注意:不推荐使用这些模型 - 请参阅 此处

from langchain_community.embeddings import LocalAIEmbeddings
API Reference:LocalAIEmbeddings
embeddings = LocalAIEmbeddings(
openai_api_base="http://localhost:8080", model="embedding-model-name"
)
text = "This is a test document."
query_result = embeddings.embed_query(text)
doc_result = embeddings.embed_documents([text])
import os

# if you are behind an explicit proxy, you can use the OPENAI_PROXY environment variable to pass through
os.environ["OPENAI_PROXY"] = "http://proxy.yourcompany.com:8080"