fix roles

This commit is contained in:
Claeb101 2023-03-04 21:29:17 -05:00
parent 488cfb722c
commit 0b399d17c8

View File

@ -1,6 +1,7 @@
import { Configuration, OpenAIApi } from "openai"; import { Configuration, OpenAIApi } from "openai";
import * as dotenv from "dotenv"; import * as dotenv from "dotenv";
import { getMessages } from "./session"; import { getMessages } from "./session";
import { Role } from "@prisma/client";
dotenv.config(); dotenv.config();
const configuration = new Configuration({ const configuration = new Configuration({
@ -9,6 +10,17 @@ const configuration = new Configuration({
const openai = new OpenAIApi(configuration); const openai = new OpenAIApi(configuration);
const convertRole = (role) => {
switch(role){
case Role.BOT:
return "assistant"
case Role.USER:
return "user"
default:
return "user"
}
}
export const chat = async (callId) => { export const chat = async (callId) => {
const msgs = await getMessages(callId); const msgs = await getMessages(callId);
const messages = [ const messages = [
@ -19,9 +31,11 @@ export const chat = async (callId) => {
}, },
]; ];
for (let msg of msgs) { for (let msg of msgs) {
messages.push({ messages.push({
role: msg.role, role: convertRole(msg.role),
content: msg.content, content: msg.content,
}); });
} }