forked from Shinonome/dots-hyprland
ai: add usage metadata for openai and mistral
This commit is contained in:
@@ -100,6 +100,17 @@ ApiStrategy {
|
|||||||
message.content += newContent;
|
message.content += newContent;
|
||||||
message.rawContent += newContent;
|
message.rawContent += newContent;
|
||||||
|
|
||||||
|
// Usage metadata
|
||||||
|
if (dataJson.usage) {
|
||||||
|
return {
|
||||||
|
tokenUsage: {
|
||||||
|
input: dataJson.usage.prompt_tokens ?? -1,
|
||||||
|
output: dataJson.usage.completion_tokens ?? -1,
|
||||||
|
total: dataJson.usage.total_tokens ?? -1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (`dataJson`.done) {
|
if (`dataJson`.done) {
|
||||||
return { finished: true };
|
return { finished: true };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ ApiStrategy {
|
|||||||
// Real stuff
|
// Real stuff
|
||||||
try {
|
try {
|
||||||
const dataJson = JSON.parse(cleanData);
|
const dataJson = JSON.parse(cleanData);
|
||||||
|
console.log(JSON.stringify(dataJson, null, 2));
|
||||||
let newContent = "";
|
let newContent = "";
|
||||||
|
|
||||||
const responseContent = dataJson.choices[0]?.delta?.content || dataJson.message?.content;
|
const responseContent = dataJson.choices[0]?.delta?.content || dataJson.message?.content;
|
||||||
@@ -72,6 +73,17 @@ ApiStrategy {
|
|||||||
message.content += newContent;
|
message.content += newContent;
|
||||||
message.rawContent += newContent;
|
message.rawContent += newContent;
|
||||||
|
|
||||||
|
// Usage metadata
|
||||||
|
if (dataJson.usage) {
|
||||||
|
return {
|
||||||
|
tokenUsage: {
|
||||||
|
input: dataJson.usage.prompt_tokens ?? -1,
|
||||||
|
output: dataJson.usage.completion_tokens ?? -1,
|
||||||
|
total: dataJson.usage.total_tokens ?? -1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (dataJson.done) {
|
if (dataJson.done) {
|
||||||
return { finished: true };
|
return { finished: true };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user