forked from phoenix/litellm-mirror
Adds "pre-fill" support for Claude
This commit is contained in:
parent
b103ab1f0b
commit
b10f64face
1 changed files with 11 additions and 2 deletions
|
@ -295,6 +295,9 @@ def claude_2_1_pt(
|
|||
if system message is passed in, you can only do system, human, assistant or system, human
|
||||
|
||||
if a system message is passed in and followed by an assistant message, insert a blank human message between them.
|
||||
|
||||
Additionally, you can "put words in Claude's mouth" by ending with an assistant message.
|
||||
See: https://docs.anthropic.com/claude/docs/put-words-in-claudes-mouth
|
||||
"""
|
||||
|
||||
class AnthropicConstants(Enum):
|
||||
|
@ -311,6 +314,7 @@ def claude_2_1_pt(
|
|||
if idx > 0 and messages[idx - 1]["role"] == "system":
|
||||
prompt += f"{AnthropicConstants.HUMAN_PROMPT.value}" # Insert a blank human message
|
||||
prompt += f"{AnthropicConstants.AI_PROMPT.value}{message['content']}"
|
||||
if messages[-1]["role"] != "assistant":
|
||||
prompt += f"{AnthropicConstants.AI_PROMPT.value}" # prompt must end with \"\n\nAssistant: " turn
|
||||
return prompt
|
||||
|
||||
|
@ -364,6 +368,10 @@ def format_prompt_togetherai(messages, prompt_format, chat_template):
|
|||
def anthropic_pt(
|
||||
messages: list,
|
||||
): # format - https://docs.anthropic.com/claude/reference/complete_post
|
||||
"""
|
||||
You can "put words in Claude's mouth" by ending with an assistant message.
|
||||
See: https://docs.anthropic.com/claude/docs/put-words-in-claudes-mouth
|
||||
"""
|
||||
class AnthropicConstants(Enum):
|
||||
HUMAN_PROMPT = "\n\nHuman: "
|
||||
AI_PROMPT = "\n\nAssistant: "
|
||||
|
@ -382,6 +390,7 @@ def anthropic_pt(
|
|||
idx == 0 and message["role"] == "assistant"
|
||||
): # ensure the prompt always starts with `\n\nHuman: `
|
||||
prompt = f"{AnthropicConstants.HUMAN_PROMPT.value}" + prompt
|
||||
if messages[-1]["role"] != "assistant":
|
||||
prompt += f"{AnthropicConstants.AI_PROMPT.value}"
|
||||
return prompt
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue