-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcd1e08
commit d5bc6f7
Showing
3 changed files
with
121 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import getAgentResponse from "@wasp/actions/getAgentResponse"; | ||
import addNewConversationToChat from "@wasp/actions/addNewConversationToChat"; | ||
import { prepareOpenAIRequest } from "./helpers"; | ||
|
||
export async function addUserMessageToConversation( | ||
chat_id: number, | ||
userQuery: string | ||
) { | ||
const payload = { | ||
chat_id: chat_id, | ||
message: userQuery, | ||
role: "user", | ||
}; | ||
|
||
const updatedConversation: any = await addNewConversationToChat(payload); | ||
const [message, conv_id, is_answer_to_agent_question]: [ | ||
message: any, | ||
conv_id: number, | ||
is_answer_to_agent_question: boolean | ||
] = prepareOpenAIRequest(updatedConversation); | ||
return [message, conv_id, is_answer_to_agent_question]; | ||
} | ||
|
||
export async function addAgentMessageToConversation( | ||
chat_id: number, | ||
message: any, | ||
conv_id: number, | ||
is_answer_to_agent_question: boolean | ||
) { | ||
const response: any = await getAgentResponse({ | ||
message: message, | ||
conv_id: conv_id, | ||
is_answer_to_agent_question: is_answer_to_agent_question, | ||
}); | ||
const openAIResponse = { | ||
chat_id: Number(chat_id), | ||
message: response.content, | ||
role: "assistant", | ||
...(response.team_status && { status: response.team_status }), | ||
}; | ||
await addNewConversationToChat(openAIResponse); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters