Skip to content

Commit

Permalink
feat: support system prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudbeer committed Oct 31, 2024
1 parent 154f225 commit 7a0a1dd
Show file tree
Hide file tree
Showing 4 changed files with 17,611 additions and 2,371 deletions.
18 changes: 9 additions & 9 deletions app/client/platforms/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class ClaudeApi implements LLMApi {
if (messages[i].content !== "") {
system_prompt = messages[i].content;
} else {
system_prompt = "' '";
system_prompt = "'.'";
}
}
}
Expand Down Expand Up @@ -273,9 +273,9 @@ export class ClaudeApi implements LLMApi {
});
}

console.log("messages[0].role", messages[0].role)
// console.log("messages[0].role", messages[0].role)

const requestPayload = {
const requestPayload: any = {
...(has_system_prompt ? { system: system_prompt } : {}),
messages: new_messages,
top_p: modelConfig.top_p,
Expand Down Expand Up @@ -385,7 +385,6 @@ export class ClaudeApi implements LLMApi {

// console.log("is vision model", visionModel);

// console.log("options.messages", options.messages);

const messages = options.messages.map((v) => ({
role: v.role,
Expand All @@ -399,14 +398,13 @@ export class ClaudeApi implements LLMApi {
if (!modelID || !modelVersion) {
throw new Error(`Could not find modelID or modelVersion.`);
}
const requestPayload = this.convertMessagePayload(

const requestPayload: any = this.convertMessagePayload(
messages,
modelConfig,
modelVersion,
);

// console.log("requestPayload", requestPayload);

// add max_tokens to vision model
if (visionModel) {
Object.defineProperty(requestPayload, "max_tokens", {
Expand Down Expand Up @@ -435,7 +433,6 @@ export class ClaudeApi implements LLMApi {
let metrics: any = {};

if (shouldStream) {
console.log("streaming");
let responseText = "";
let remainText = "";
let finished = false;
Expand Down Expand Up @@ -473,13 +470,15 @@ export class ClaudeApi implements LLMApi {

const payload: ConverseCommandInput = {
modelId: modelID,
...(requestPayload.system ? { system: [{ text: requestPayload.system }] } : [{ text: "." }]),
messages: requestPayload.messages,
inferenceConfig: {
maxTokens: requestPayload.max_tokens,
temperature: requestPayload.temperature,
topP: requestPayload.top_p
}
}
// console.log(payload, ".............")
const response = await client.converseStream(payload);

try {
Expand All @@ -501,10 +500,11 @@ export class ClaudeApi implements LLMApi {


} else {
console.log("not streaming");
// console.log("not streaming");

const payload: ConverseCommandInput = {
modelId: modelID,
...(requestPayload.system ? { system: [{ text: requestPayload.system }] } : [{ text: "." }]),
messages: requestPayload.messages,
inferenceConfig: {
maxTokens: requestPayload.max_tokens,
Expand Down
Loading

0 comments on commit 7a0a1dd

Please sign in to comment.