Zum Hauptinhalt springen

Llamafile

LiteLLM unterstĂĽtzt alle Modelle auf Llamafile.

EigenschaftDetails
BeschreibungLlamafile ermöglicht es Ihnen, LLMs mit einer einzigen Datei zu verteilen und auszuführen. Docs
Provider-Routing in LiteLLMllamafile/ (fĂĽr OpenAI-kompatiblen Server)
Provider-Dokumentationllamafile ↗
UnterstĂĽtzte Endpunkte/chat/completions, /embeddings, /completions

Schnellstart

Verwendung - litellm.completion (Aufrufen eines OpenAI-kompatiblen Endpunkts)​

llamafile bietet einen OpenAI-kompatiblen Endpunkt für Chat-Vervollständigungen - hier erfahren Sie, wie Sie ihn mit LiteLLM aufrufen können.

Um litellm zum Aufrufen von llamafile zu verwenden, fĂĽgen Sie Folgendes zu Ihrem completion-Aufruf hinzu:

  • model="llamafile/<Ihr-llamafile-Modellname>"
  • api_base = "Ihr-gehostetes-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="https://:8080/v1",
temperature=0.2,
max_tokens=80)

print(response)

Verwendung - LiteLLM Proxy Server (Aufrufen eines OpenAI-kompatiblen Endpunkts)​

So rufen Sie einen OpenAI-kompatiblen Endpunkt mit dem LiteLLM Proxy Server auf

  1. Konfigurieren Sie die 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://:8080/v1 # add api base for OpenAI compatible provider
  2. Starten Sie den Proxy

    $ litellm --config /path/to/config.yaml
  3. Anfrage an LiteLLM Proxy Server senden

    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)

Embeddings​

from litellm import embedding   
import os

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


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

print(embedding)