Skip to content

Commit

Permalink
Merge pull request babaohuang#68 from stefan-ysh/main
Browse files Browse the repository at this point in the history
convert message list into parameters that conforms to the api rules(Interim Solution)
  • Loading branch information
babaohuang authored Dec 22, 2023
2 parents f946e32 + 78de3f8 commit b585abc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/Generator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ export default () => {
window.scrollTo({ top: document.body.scrollHeight, behavior: 'instant' })
}

// ? Interim Solution
// ensure that the user and the model have a one-to-one conversation and avoid any errors like:
// "Please ensure that multiturn requests ends with a user role or a function response."
// convert the raw list into data that conforms to the interface api rules
const convertReqMsgList = (originalMsgList: ChatMessage[]) => {
return originalMsgList.filter((curMsg, i, arr) => {
// Check if there is a next message
const nextMsg = arr[i + 1]
// Include the current message if there is no next message or if the roles are different
return !nextMsg || curMsg.role !== nextMsg.role
})
}
const requestWithLatestMessage = async() => {
setLoading(true)
setCurrentAssistantMessage('')
Expand All @@ -89,7 +101,7 @@ export default () => {
const response = await fetch('/api/generate', {
method: 'POST',
body: JSON.stringify({
messages: requestMessageList,
messages: convertReqMsgList(requestMessageList),
time: timestamp,
pass: storagePassword,
sign: await generateSignature({
Expand Down

0 comments on commit b585abc

Please sign in to comment.