FIX: Use claude-2.1 to enable system prompts (#411)
This commit is contained in:
parent
0f4e7723d7
commit
abde82c1f3
|
@ -24,7 +24,10 @@ module DiscourseAi
|
||||||
|
|
||||||
claude_prompt << conversation_context if prompt[:conversation_context]
|
claude_prompt << conversation_context if prompt[:conversation_context]
|
||||||
|
|
||||||
claude_prompt << "#{prompt[:input]}\n"
|
if uses_system_message? && (prompt[:input] || prompt[:post_insts])
|
||||||
|
claude_prompt << "Human: "
|
||||||
|
end
|
||||||
|
claude_prompt << "#{prompt[:input]}\n" if prompt[:input]
|
||||||
|
|
||||||
claude_prompt << "#{prompt[:post_insts]}\n" if prompt[:post_insts]
|
claude_prompt << "#{prompt[:post_insts]}\n" if prompt[:post_insts]
|
||||||
|
|
||||||
|
@ -35,7 +38,7 @@ module DiscourseAi
|
||||||
end
|
end
|
||||||
|
|
||||||
def max_prompt_tokens
|
def max_prompt_tokens
|
||||||
50_000
|
100_000 # Claude-2.1 has a 200k context window.
|
||||||
end
|
end
|
||||||
|
|
||||||
def conversation_context
|
def conversation_context
|
||||||
|
|
|
@ -22,7 +22,7 @@ module DiscourseAi
|
||||||
|
|
||||||
def default_options
|
def default_options
|
||||||
{
|
{
|
||||||
model: model,
|
model: model == "claude-2" ? "claude-2.1" : model,
|
||||||
max_tokens_to_sample: 3_000,
|
max_tokens_to_sample: 3_000,
|
||||||
stop_sequences: ["\n\nHuman:", "</function_calls>"],
|
stop_sequences: ["\n\nHuman:", "</function_calls>"],
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,9 +37,12 @@ module DiscourseAi
|
||||||
|
|
||||||
def model_uri
|
def model_uri
|
||||||
# Bedrock uses slightly different names
|
# Bedrock uses slightly different names
|
||||||
|
# See: https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids-arns.html
|
||||||
bedrock_model_id = model.split("-")
|
bedrock_model_id = model.split("-")
|
||||||
bedrock_model_id[-1] = "v#{bedrock_model_id.last}"
|
bedrock_model_id[-1] = "v#{bedrock_model_id.last}"
|
||||||
bedrock_model_id = bedrock_model_id.join("-")
|
bedrock_model_id = +(bedrock_model_id.join("-"))
|
||||||
|
|
||||||
|
bedrock_model_id << ":1" if model == "claude-2" # For claude-2.1
|
||||||
|
|
||||||
api_url =
|
api_url =
|
||||||
"https://bedrock-runtime.#{SiteSetting.ai_bedrock_region}.amazonaws.com/model/anthropic.#{bedrock_model_id}/invoke"
|
"https://bedrock-runtime.#{SiteSetting.ai_bedrock_region}.amazonaws.com/model/anthropic.#{bedrock_model_id}/invoke"
|
||||||
|
|
|
@ -10,7 +10,7 @@ module DiscourseAi
|
||||||
Models::OpenAi.new("gpt-4-1106-preview", max_tokens: 100_000),
|
Models::OpenAi.new("gpt-4-1106-preview", max_tokens: 100_000),
|
||||||
Models::OpenAi.new("gpt-3.5-turbo", max_tokens: 4096),
|
Models::OpenAi.new("gpt-3.5-turbo", max_tokens: 4096),
|
||||||
Models::OpenAi.new("gpt-3.5-turbo-16k", max_tokens: 16_384),
|
Models::OpenAi.new("gpt-3.5-turbo-16k", max_tokens: 16_384),
|
||||||
Models::Anthropic.new("claude-2", max_tokens: 100_000),
|
Models::Anthropic.new("claude-2", max_tokens: 200_000),
|
||||||
Models::Anthropic.new("claude-instant-1", max_tokens: 100_000),
|
Models::Anthropic.new("claude-instant-1", max_tokens: 100_000),
|
||||||
Models::Llama2.new("Llama2-chat-hf", max_tokens: SiteSetting.ai_hugging_face_token_limit),
|
Models::Llama2.new("Llama2-chat-hf", max_tokens: SiteSetting.ai_hugging_face_token_limit),
|
||||||
Models::Llama2FineTunedOrcaStyle.new(
|
Models::Llama2FineTunedOrcaStyle.new(
|
||||||
|
|
|
@ -49,7 +49,7 @@ RSpec.describe DiscourseAi::Completions::Dialects::Claude do
|
||||||
it "translates a prompt written in our generic format to Claude's format" do
|
it "translates a prompt written in our generic format to Claude's format" do
|
||||||
anthropic_version = <<~TEXT
|
anthropic_version = <<~TEXT
|
||||||
#{prompt[:insts]}
|
#{prompt[:insts]}
|
||||||
#{prompt[:input]}
|
Human: #{prompt[:input]}
|
||||||
#{prompt[:post_insts]}
|
#{prompt[:post_insts]}
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ RSpec.describe DiscourseAi::Completions::Dialects::Claude do
|
||||||
H: #{prompt[:examples][0][0]}
|
H: #{prompt[:examples][0][0]}
|
||||||
A: #{prompt[:examples][0][1]}
|
A: #{prompt[:examples][0][1]}
|
||||||
</example>
|
</example>
|
||||||
#{prompt[:input]}
|
Human: #{prompt[:input]}
|
||||||
#{prompt[:post_insts]}
|
#{prompt[:post_insts]}
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ RSpec.describe DiscourseAi::Completions::Dialects::Claude do
|
||||||
#{DiscourseAi::Completions::Dialects::Claude.tool_preamble}
|
#{DiscourseAi::Completions::Dialects::Claude.tool_preamble}
|
||||||
<tools>
|
<tools>
|
||||||
#{dialect.tools}</tools>
|
#{dialect.tools}</tools>
|
||||||
#{prompt[:input]}
|
Human: #{prompt[:input]}
|
||||||
#{prompt[:post_insts]}
|
#{prompt[:post_insts]}
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ RSpec.describe DiscourseAi::Completions::Dialects::Claude do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "trims content if it's getting too long" do
|
it "trims content if it's getting too long" do
|
||||||
context.last[:content] = context.last[:content] * 10_000
|
context.last[:content] = context.last[:content] * 20_000
|
||||||
prompt[:conversation_context] = context
|
prompt[:conversation_context] = context
|
||||||
|
|
||||||
translated_context = dialect.conversation_context
|
translated_context = dialect.conversation_context
|
||||||
|
|
|
@ -8,7 +8,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do
|
||||||
subject(:model) { described_class.new(model_name, DiscourseAi::Tokenizer::AnthropicTokenizer) }
|
subject(:model) { described_class.new(model_name, DiscourseAi::Tokenizer::AnthropicTokenizer) }
|
||||||
|
|
||||||
let(:model_name) { "claude-2" }
|
let(:model_name) { "claude-2" }
|
||||||
let(:bedrock_name) { "claude-v2" }
|
let(:bedrock_name) { "claude-v2:1" }
|
||||||
let(:generic_prompt) { { insts: "write 3 words" } }
|
let(:generic_prompt) { { insts: "write 3 words" } }
|
||||||
let(:dialect) { DiscourseAi::Completions::Dialects::Claude.new(generic_prompt, model_name) }
|
let(:dialect) { DiscourseAi::Completions::Dialects::Claude.new(generic_prompt, model_name) }
|
||||||
let(:prompt) { dialect.translate }
|
let(:prompt) { dialect.translate }
|
||||||
|
@ -62,7 +62,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do
|
||||||
stop_reason: finish_reason,
|
stop_reason: finish_reason,
|
||||||
truncated: false,
|
truncated: false,
|
||||||
log_id: "12b029451c6d18094d868bc04ce83f63",
|
log_id: "12b029451c6d18094d868bc04ce83f63",
|
||||||
model: "claude-2",
|
model: "claude-2.1",
|
||||||
exception: nil,
|
exception: nil,
|
||||||
}.to_json,
|
}.to_json,
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue