add aws claude-3 (#298)
# PR Checklist - [x] Did you check if it works normally in all models? *ignore this when it dosen't uses models* - [x] Did you check if it works normally in all of web, local and node hosted versions? if it dosen't, did you blocked it in those versions? - [x] Did you added a type def? # Description 
This commit is contained in:
@@ -147,11 +147,7 @@
|
|||||||
<span class="text-textcolor">Mancer {language.apiKey}</span>
|
<span class="text-textcolor">Mancer {language.apiKey}</span>
|
||||||
<TextInput marginBottom={true} size={"sm"} placeholder="..." bind:value={$DataBase.mancerHeader}/>
|
<TextInput marginBottom={true} size={"sm"} placeholder="..." bind:value={$DataBase.mancerHeader}/>
|
||||||
{/if}
|
{/if}
|
||||||
{#if $DataBase.aiModel.startsWith('claude-3') || $DataBase.subModel.startsWith('claude-3')}
|
{#if $DataBase.aiModel.startsWith('claude-') || $DataBase.subModel.startsWith('claude-')}
|
||||||
<span class="text-textcolor">Claude {language.apiKey}</span>
|
|
||||||
<TextInput marginBottom={true} size={"sm"} placeholder="..." bind:value={$DataBase.claudeAPIKey}/>
|
|
||||||
{/if}
|
|
||||||
{#if $DataBase.aiModel.startsWith('claude-1') || $DataBase.subModel.startsWith('claude-1') || $DataBase.subModel.startsWith('claude-2') || $DataBase.subModel.startsWith('claude-2')}
|
|
||||||
<span class="text-textcolor">Claude {language.apiKey}</span>
|
<span class="text-textcolor">Claude {language.apiKey}</span>
|
||||||
<TextInput marginBottom={true} size={"sm"} placeholder="..." bind:value={$DataBase.claudeAPIKey}/>
|
<TextInput marginBottom={true} size={"sm"} placeholder="..." bind:value={$DataBase.claudeAPIKey}/>
|
||||||
{#if $DataBase.useExperimental}
|
{#if $DataBase.useExperimental}
|
||||||
|
|||||||
@@ -1508,7 +1508,87 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
|||||||
delete body.system
|
delete body.system
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bedrock = db.claudeAws
|
||||||
|
|
||||||
|
if(bedrock && aiModel !== 'reverse_proxy'){
|
||||||
|
function getCredentialParts(key:string) {
|
||||||
|
const [accessKeyId, secretAccessKey, region] = key.split(":");
|
||||||
|
|
||||||
|
if (!accessKeyId || !secretAccessKey || !region) {
|
||||||
|
throw new Error("The key assigned to this request is invalid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return { accessKeyId, secretAccessKey, region };
|
||||||
|
}
|
||||||
|
const { accessKeyId, secretAccessKey, region } = getCredentialParts(apiKey);
|
||||||
|
|
||||||
|
const AMZ_HOST = "bedrock-runtime.%REGION%.amazonaws.com";
|
||||||
|
const host = AMZ_HOST.replace("%REGION%", region);
|
||||||
|
const stream = false
|
||||||
|
const CLAUDE_3_COMPAT_MODEL = "anthropic.claude-3-sonnet-20240229-v1:0";
|
||||||
|
|
||||||
|
// AWS currently only supports one v3 model.
|
||||||
|
const awsModel = CLAUDE_3_COMPAT_MODEL;
|
||||||
|
const url = `https://${host}/model/${awsModel}/invoke${stream ? "-with-response-stream" : ""}`
|
||||||
|
|
||||||
|
const params = {
|
||||||
|
messages : claudeChat,
|
||||||
|
system: systemPrompt.trim(),
|
||||||
|
max_tokens: maxTokens,
|
||||||
|
// stop_sequences: ["user:", "assistant:", "system:"],
|
||||||
|
temperature: temperature,
|
||||||
|
top_p: db.top_p,
|
||||||
|
top_k: db.top_k,
|
||||||
|
anthropic_version: "bedrock-2023-05-31",
|
||||||
|
}
|
||||||
|
|
||||||
|
const rq = new HttpRequest({
|
||||||
|
method: "POST",
|
||||||
|
protocol: "https:",
|
||||||
|
hostname: host,
|
||||||
|
path: `/model/${awsModel}/invoke${stream ? "-with-response-stream" : ""}`,
|
||||||
|
headers: {
|
||||||
|
["Host"]: host,
|
||||||
|
["Content-Type"]: "application/json",
|
||||||
|
["accept"]: "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(params),
|
||||||
|
});
|
||||||
|
|
||||||
|
const signer = new SignatureV4({
|
||||||
|
sha256: Sha256,
|
||||||
|
credentials: { accessKeyId, secretAccessKey },
|
||||||
|
region,
|
||||||
|
service: "bedrock",
|
||||||
|
});
|
||||||
|
|
||||||
|
const signed = await signer.sign(rq);
|
||||||
|
|
||||||
|
const res = await globalFetch(url, {
|
||||||
|
method: "POST",
|
||||||
|
body: params,
|
||||||
|
headers: signed.headers,
|
||||||
|
plainFetchForce: true
|
||||||
|
})
|
||||||
|
|
||||||
|
if(!res.ok){
|
||||||
|
return {
|
||||||
|
type: 'fail',
|
||||||
|
result: JSON.stringify(res.data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(res.data.error){
|
||||||
|
return {
|
||||||
|
type: 'fail',
|
||||||
|
result: JSON.stringify(res.data.error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
type: 'success',
|
||||||
|
result: res.data.content[0].text
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const res = await globalFetch(replacerURL, {
|
const res = await globalFetch(replacerURL, {
|
||||||
body: body,
|
body: body,
|
||||||
@@ -1646,11 +1726,11 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
|||||||
const url = `https://${host}/model/${awsModel}/invoke${stream ? "-with-response-stream" : ""}`
|
const url = `https://${host}/model/${awsModel}/invoke${stream ? "-with-response-stream" : ""}`
|
||||||
const params = {
|
const params = {
|
||||||
prompt : requestPrompt.startsWith("\n\nHuman: ") ? requestPrompt : "\n\nHuman: " + requestPrompt,
|
prompt : requestPrompt.startsWith("\n\nHuman: ") ? requestPrompt : "\n\nHuman: " + requestPrompt,
|
||||||
//model: raiModel,
|
|
||||||
max_tokens_to_sample: maxTokens,
|
max_tokens_to_sample: maxTokens,
|
||||||
stop_sequences: ["\n\nHuman:", "\n\nSystem:", "\n\nAssistant:"],
|
stop_sequences: ["\n\nHuman:", "\n\nSystem:", "\n\nAssistant:"],
|
||||||
temperature: temperature,
|
temperature: temperature,
|
||||||
top_p: db.top_p,
|
top_p: db.top_p,
|
||||||
|
//top_k: db.top_k,
|
||||||
}
|
}
|
||||||
const rq = new HttpRequest({
|
const rq = new HttpRequest({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
Reference in New Issue
Block a user