From 0b399d17c8076fa0fd9cfdb84da7b4cb83f30427 Mon Sep 17 00:00:00 2001 From: Claeb101 Date: Sat, 4 Mar 2023 21:29:17 -0500 Subject: [PATCH] fix roles --- src/chat.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/chat.js b/src/chat.js index 2439d28..9cf9f7b 100644 --- a/src/chat.js +++ b/src/chat.js @@ -1,6 +1,7 @@ import { Configuration, OpenAIApi } from "openai"; import * as dotenv from "dotenv"; import { getMessages } from "./session"; +import { Role } from "@prisma/client"; dotenv.config(); const configuration = new Configuration({ @@ -9,6 +10,17 @@ const configuration = new 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) => { const msgs = await getMessages(callId); const messages = [ @@ -19,9 +31,11 @@ export const chat = async (callId) => { }, ]; + + for (let msg of msgs) { messages.push({ - role: msg.role, + role: convertRole(msg.role), content: msg.content, }); }