-
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
53157d3
commit ea216f5
Showing
10 changed files
with
253 additions
and
249 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
19 changes: 19 additions & 0 deletions
19
migrations/20231218010807_move_team_related_columns_to_chat_model/migration.sql
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,19 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `is_question_from_agent` on the `Conversation` table. All the data in the column will be lost. | ||
- You are about to drop the column `team_id` on the `Conversation` table. All the data in the column will be lost. | ||
- You are about to drop the column `team_name` on the `Conversation` table. All the data in the column will be lost. | ||
- You are about to drop the column `team_status` on the `Conversation` table. All the data in the column will be lost. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Chat" ADD COLUMN "team_id" INTEGER, | ||
ADD COLUMN "team_name" TEXT, | ||
ADD COLUMN "team_status" TEXT; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Conversation" DROP COLUMN "is_question_from_agent", | ||
DROP COLUMN "team_id", | ||
DROP COLUMN "team_name", | ||
DROP COLUMN "team_status"; |
2 changes: 2 additions & 0 deletions
2
migrations/20231218111917_add_show_loader_column_to_chat_model/migration.sql
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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Chat" ADD COLUMN "showLoader" BOOLEAN NOT NULL DEFAULT false; |
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 |
---|---|---|
@@ -1,75 +1,62 @@ | ||
import getAgentResponse from "@wasp/actions/getAgentResponse"; | ||
import addNewConversationToChat from "@wasp/actions/addNewConversationToChat"; | ||
import updateExistingConversation from "@wasp/actions/updateExistingConversation"; | ||
import updateExistingChat from "@wasp/actions/updateExistingChat"; | ||
import { prepareOpenAIRequest } from "./helpers"; | ||
|
||
export async function addUserMessageToConversation( | ||
chat_id: number, | ||
userQuery: string, | ||
conv_id?: number, | ||
team_name?: string, | ||
team_id?: number | ||
userQuery: string | ||
) { | ||
let userMessage = userQuery; | ||
let isAnswerToAgentQuestion = false; | ||
let user_answer_to_team_id = null; | ||
if (team_id) { | ||
if (conv_id) { | ||
const payload = { | ||
chat_id: chat_id, | ||
conv_id: conv_id, | ||
is_question_from_agent: false, | ||
team_status: null, | ||
}; | ||
await updateExistingConversation(payload); | ||
} | ||
userMessage = `<p>Replying to ${team_name}:</p><br/><br/>` + userQuery; | ||
isAnswerToAgentQuestion = true; | ||
user_answer_to_team_id = team_id; | ||
} | ||
|
||
const payload = { | ||
chat_id: chat_id, | ||
message: userMessage, | ||
role: "user", | ||
}; | ||
|
||
const updatedConversation: any = await addNewConversationToChat(payload); | ||
|
||
const [messages, latestConversationID]: [ | ||
messages: any, | ||
latestConversationID: number | ||
] = prepareOpenAIRequest(updatedConversation); | ||
return [ | ||
messages, | ||
latestConversationID, | ||
isAnswerToAgentQuestion, | ||
user_answer_to_team_id, | ||
]; | ||
const messages: any = prepareOpenAIRequest(updatedConversation); | ||
return messages; | ||
} | ||
|
||
export async function addAgentMessageToConversation( | ||
chat_id: number, | ||
message: any, | ||
conv_id: number, | ||
isAnswerToAgentQuestion: boolean, | ||
userResponseToTeamId: number | null | undefined | ||
team_id: number | null | undefined | ||
) { | ||
const response: any = await getAgentResponse({ | ||
chat_id: chat_id, | ||
message: message, | ||
conv_id: conv_id, | ||
isAnswerToAgentQuestion: isAnswerToAgentQuestion, | ||
userResponseToTeamId: userResponseToTeamId, | ||
team_id: team_id, | ||
}); | ||
|
||
const openAIResponse = { | ||
// ...(response.team_name && { team_name: response.team_name }), | ||
// ...(response.team_id && { team_id: response.team_id }), | ||
// ...(response.team_status && { team_status: response.team_status }), | ||
|
||
if (response.team_name) { | ||
const payload = { | ||
chat_id: chat_id, | ||
team_name: response.team_name, | ||
team_id: response.team_id, | ||
team_status: response.team_status, | ||
}; | ||
await updateExistingChat(payload); | ||
} | ||
|
||
if (response.content) { | ||
const openAIResponse = { | ||
chat_id: Number(chat_id), | ||
message: response.content, | ||
role: "assistant", | ||
}; | ||
|
||
await addNewConversationToChat(openAIResponse); | ||
} | ||
|
||
return { | ||
chat_id: Number(chat_id), | ||
message: response.content, | ||
role: "assistant", | ||
...(response.team_name && { team_name: response.team_name }), | ||
...(response.team_id && { team_id: response.team_id }), | ||
...(response.team_status && { team_status: response.team_status }), | ||
}; | ||
return 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
Oops, something went wrong.