mirror of
https://github.com/vitalityAI/therapist.git
synced 2025-04-08 05:40:17 -04:00
fix roles
This commit is contained in:
parent
488cfb722c
commit
0b399d17c8
16
src/chat.js
16
src/chat.js
|
@ -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,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user