跳至主要內容

Llamafile

LiteLLM 支援 Llamafile 上的所有模型。

屬性詳細資訊
說明llamafile 可讓您使用單一檔案來散佈並執行 LLM。 文件
LiteLLM 提供者路由llamafile/(適用於 OpenAI 相容伺服器)
提供者文件llamafile ↗
支援的端點/chat/completions, /embeddings, /completions

快速開始

使用方式 - litellm.completion(呼叫 OpenAI 相容端點)

llamafile 提供 OpenAI 相容的聊天完成端點——以下是如何使用 LiteLLM 呼叫它

若要使用 litellm 呼叫 llamafile,請將下列內容加入您的 completion 呼叫中

  • model="llamafile/<your-llamafile-model-name>"
  • api_base = "your-hosted-llamafile"
import litellm 

response = litellm.completion(
model="llamafile/mistralai/mistral-7b-instruct-v0.2", # pass the llamafile model name for completeness
messages=messages,
api_base="http://localhost:8080/v1",
temperature=0.2,
max_tokens=80)

print(response)

使用方式 - LiteLLM Proxy Server(呼叫 OpenAI 相容端點)

以下是如何使用 LiteLLM Proxy Server 呼叫 OpenAI 相容端點

  1. 修改 config.yaml
model_list:
- model_name: my-model
litellm_params:
model: llamafile/mistralai/mistral-7b-instruct-v0.2 # add llamafile/ prefix to route as OpenAI provider
api_base: http://localhost:8080/v1 # add api base for OpenAI compatible provider
  1. 啟動 proxy
$ litellm --config /path/to/config.yaml
  1. 將請求送至 LiteLLM Proxy Server
import openai
client = openai.OpenAI(
api_key="sk-1234", # pass litellm proxy key, if you're using virtual keys
base_url="http://0.0.0.0:4000" # litellm-proxy-base url
)

response = client.chat.completions.create(
model="my-model",
messages = [
{
"role": "user",
"content": "what llm are you"
}
],
)

print(response)

嵌入向量

from litellm import embedding   
import os

os.environ["LLAMAFILE_API_BASE"] = "http://localhost:8080/v1"


embedding = embedding(model="llamafile/sentence-transformers/all-MiniLM-L6-v2", input=["Hello world"])

print(embedding)
🚅
LiteLLM Enterprise
為正式環境打造的 SSO/SAML、稽核記錄、支出追蹤、多團隊管理與防護欄。
深入瞭解 →