Zum Hauptinhalt springen

Prompt-Formatierung

LiteLLM übersetzt automatisch das OpenAI ChatCompletions Prompt-Format in andere Modelle. Sie können dies auch steuern, indem Sie eine benutzerdefinierte Prompt-Vorlage für ein Modell festlegen.

Huggingface-Modelle

LiteLLM unterstützt Huggingface Chat Templates und prüft automatisch, ob Ihr Huggingface-Modell eine registrierte Chat-Vorlage hat (z.B. Mistral-7b).

Für beliebte Modelle (z.B. meta-llama/llama2) haben wir ihre Vorlagen als Teil des Pakets gespeichert.

Gespeicherte Vorlagen

ModellnameFunktioniert für ModelleCompletion-Aufruf
mistralai/Mistral-7B-Instruct-v0.1mistralai/Mistral-7B-Instruct-v0.1completion(model='huggingface/mistralai/Mistral-7B-Instruct-v0.1', messages=messages, api_base="Ihre_API_Endpoint")
meta-llama/Llama-2-7b-chatAlle meta-llama llama2 Chat-Modellecompletion(model='huggingface/meta-llama/Llama-2-7b', messages=messages, api_base="Ihre_API_Endpoint")
tiiuae/falcon-7b-instructAlle falcon Instruct-Modellecompletion(model='huggingface/tiiuae/falcon-7b-instruct', messages=messages, api_base="Ihre_API_Endpoint")
mosaicml/mpt-7b-chatAlle mpt Chat-Modellecompletion(model='huggingface/mosaicml/mpt-7b-chat', messages=messages, api_base="Ihre_API_Endpoint")
codellama/CodeLlama-34b-Instruct-hfAlle codellama Instruct-Modellecompletion(model='huggingface/codellama/CodeLlama-34b-Instruct-hf', messages=messages, api_base="Ihre_API_Endpoint")
WizardLM/WizardCoder-Python-34B-V1.0Alle wizardcoder-Modellecompletion(model='huggingface/WizardLM/WizardCoder-Python-34B-V1.0', messages=messages, api_base="Ihre_API_Endpoint")
Phind/Phind-CodeLlama-34B-v2Alle phind-codellama-Modellecompletion(model='huggingface/Phind/Phind-CodeLlama-34B-v2', messages=messages, api_base="Ihre_API_Endpoint")

Springe zu Code

Prompt selbst formatieren

Sie können den Prompt auch selbst formatieren. Hier ist wie:

import litellm
# Create your own custom prompt template
litellm.register_prompt_template(
model="togethercomputer/LLaMA-2-7B-32K",
initial_prompt_value="You are a good assistant" # [OPTIONAL]
roles={
"system": {
"pre_message": "[INST] <<SYS>>\n", # [OPTIONAL]
"post_message": "\n<</SYS>>\n [/INST]\n" # [OPTIONAL]
},
"user": {
"pre_message": "[INST] ", # [OPTIONAL]
"post_message": " [/INST]" # [OPTIONAL]
},
"assistant": {
"pre_message": "\n" # [OPTIONAL]
"post_message": "\n" # [OPTIONAL]
}
}
final_prompt_value="Now answer as best you can:" # [OPTIONAL]
)

def test_huggingface_custom_model():
model = "huggingface/togethercomputer/LLaMA-2-7B-32K"
response = completion(model=model, messages=messages, api_base="https://my-huggingface-endpoint")
print(response['choices'][0]['message']['content'])
return response

test_huggingface_custom_model()

Dies wird derzeit für Huggingface, TogetherAI, Ollama und Petals unterstützt.

Andere Anbieter haben entweder feste Prompt-Vorlagen (z.B. Anthropic) oder formatieren sie selbst (z.B. Replicate). Wenn ein Anbieter fehlt, lassen Sie es uns wissen!

Alle Anbieter

Hier ist der Code, wie wir alle Anbieter formatieren. Lassen Sie uns wissen, wie wir dies weiter verbessern können

AnbieterModellnameCode
Anthropicclaude-instant-1, claude-instant-1.2, claude-2Code
OpenAI Text Completiontext-davinci-003, text-curie-001, text-babbage-001, text-ada-001, babbage-002, davinci-002,Code
Replicatealle Modellnamen, die mit replicate/ beginnenCode
Coherecommand-nightly, command, command-light, command-medium-beta, command-xlarge-beta, command-r-plusCode
Huggingfacealle Modellnamen, die mit huggingface/ beginnenCode
OpenRouteralle Modellnamen, die mit openrouter/ beginnenCode
AI21j2-mid, j2-light, j2-ultraCode
VertexAItext-bison, text-bison@001, chat-bison, chat-bison@001, chat-bison-32k, code-bison, code-bison@001, code-gecko@001, code-gecko@latest, codechat-bison, codechat-bison@001, codechat-bison-32kCode
Bedrockalle Modellnamen, die mit bedrock/ beginnenCode
Sagemakersagemaker/jumpstart-dft-meta-textgeneration-llama-2-7bCode
TogetherAIalle Modellnamen, die mit together_ai/ beginnenCode
AlephAlphaalle Modellnamen, die mit aleph_alpha/ beginnenCode
Palmalle Modellnamen, die mit palm/ beginnenCode
NLP Cloudalle Modellnamen, die mit palm/ beginnenCode
Petalsalle Modellnamen, die mit petals/ beginnenCode