Skip to content

Commit

Permalink
Support response format
Browse files Browse the repository at this point in the history
  • Loading branch information
AiQL.com authored Aug 3, 2024
1 parent 760866e commit 87c3e88
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- md-editor-v3: https://github.com/imzbf/md-editor-v3
- lottie-web: https://github.com/airbnb/lottie-web
- vuedraggable: https://github.com/SortableJS/vue.draggable.next
- mammoth: https://github.com/mwilliamson/mammoth.js
Copyright 2024 AIQL.COM
Expand Down Expand Up @@ -1265,18 +1266,24 @@ <h5 class="font-weight-bold">{{ column.key }}</h5>
const parseJson = (content, target) => {
try {
const parsed = JSON.parse(content)
const choices = parsed.choices
const choice = choices.map((choice) => {
// Support both steam or not
return choice.delta?.content || choice.message?.content
})
const choice = parseChoices(parsed)
parseChoice(choice, target)
} catch (e) {
console.log(e, content)
parseChoice(content, target)
}
};

const parseChoices = (parsed) => {
if ('choices' in parsed) {
return parsed.choices.map((choice) => choice.delta?.content || choice.message?.content)
} else if ('response' in parsed) {
return parsed.response
} else {
return parsed
}
};

const parseChoice = (choice, target) => {
if (choice) {
if (target instanceof Array) {
Expand Down

0 comments on commit 87c3e88

Please sign in to comment.