Skip to content

Commit

Permalink
feat: 支持接管LLM的log
Browse files Browse the repository at this point in the history
  • Loading branch information
MarleneJiang committed Aug 31, 2023
1 parent 90ae945 commit 861c6af
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions package/utils/openai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,35 +260,35 @@ export class LLM {
});
}

log(...args: string[]) {
static log(...args: string[]) {
console.log(args);
}
prettyPrintReqMessage(messages: messagesType) {
for (const message of messages) {
if (message.role === "system") {
this.log(
LLM.log(
`%c system ${message.name ? "(" + message.name + ")" : ""}: ${
message.content
} \n`,
`color: ${this.roleToColor[message.role]}`,
);
} else if (message.role === "user") {
this.log(
LLM.log(
`%c user: ${message.content} \n`,
`color: ${this.roleToColor[message.role]}`,
);
} else if (message.role === "assistant" && message.function_call) {
this.log(
LLM.log(
`%c assistant: ${JSON.stringify(message.function_call)} \n`,
`color: ${this.roleToColor[message.role]}`,
);
} else if (message.role === "assistant" && !message.function_call) {
this.log(
LLM.log(
`%c assistant: ${message.content} \n`,
`color: ${this.roleToColor[message.role]}`,
);
} else if (message.role === "function") {
this.log(
LLM.log(
`%c function (${
message.name // response message has not `name`
}): ${message.content} \n`,
Expand All @@ -301,27 +301,27 @@ export class LLM {
for (const message_ of messages) {
const message = message_.message;
if (message.role === "system") {
this.log(
LLM.log(
`%c system: ${message.content} \n`,
`color: ${this.roleToColor[message.role]}`,
);
} else if (message.role === "user") {
this.log(
LLM.log(
`%c user: ${message.content} \n`,
`color: ${this.roleToColor[message.role]}`,
);
} else if (message.role === "assistant" && message.function_call) {
this.log(
LLM.log(
`%c assistant: ${JSON.stringify(message.function_call)} \n`,
`color: ${this.roleToColor[message.role]}`,
);
} else if (message.role === "assistant" && !message.function_call) {
this.log(
LLM.log(
`%c assistant: ${message.content} \n`,
`color: ${this.roleToColor[message.role]}`,
);
} else if (message.role === "function") {
this.log(
LLM.log(
`%c function : ${message.content} \n`,
`color: ${this.roleToColor[message.role]}`,
);
Expand Down

0 comments on commit 861c6af

Please sign in to comment.