-
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
Showing
12 changed files
with
89 additions
and
66 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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { APP_DATA_TYPES } from '../config/appDataTypes'; | ||
|
||
// TODO: there is something similar in app-code-capsule, it may be intersting to move in SDK ? | ||
export interface ThreadMessage { | ||
type: APP_DATA_TYPES.BOT_COMMENT | APP_DATA_TYPES.STUDENT_COMMENT; | ||
data: { | ||
content: string; | ||
}; | ||
} |
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,30 @@ | ||
import { ChatBotMessage, ChatbotRole } from '@graasp/sdk'; | ||
|
||
import { APP_DATA_TYPES } from '../config/appDataTypes'; | ||
import { ThreadMessage } from '../interfaces/chatbot'; | ||
|
||
// TODO: maybe it is possible to move to SDK and to reuse it in code-capsule | ||
export const buildPrompt = ( | ||
initialPrompt: string | undefined, | ||
threadMessages: ThreadMessage[], | ||
userMessage: string, | ||
): Array<ChatBotMessage> => { | ||
// define the message to send to OpenAI with the initial prompt first if needed (role system). | ||
// Each call to OpenAI must contain the whole history of the messages. | ||
const finalPrompt: Array<ChatBotMessage> = initialPrompt | ||
? [{ role: ChatbotRole.System, content: initialPrompt }] | ||
: []; | ||
|
||
threadMessages.forEach((msg) => { | ||
const msgRole = | ||
msg.type === APP_DATA_TYPES.BOT_COMMENT | ||
? ChatbotRole.Assistant | ||
: ChatbotRole.User; | ||
finalPrompt.push({ role: msgRole, content: msg.data.content }); | ||
}); | ||
|
||
// add the last user's message in the prompt | ||
finalPrompt.push({ role: ChatbotRole.User, content: userMessage }); | ||
|
||
return finalPrompt; | ||
}; |