ai: gemini: annotation sources

This commit is contained in:
end-4
2025-05-10 10:56:35 +02:00
parent 0af7924be9
commit f93cca8a13
6 changed files with 130 additions and 2 deletions
+22
View File
@@ -310,11 +310,33 @@ Singleton {
}
function parseGeminiBuffer() {
// console.log("BUFFER DATA: ", requester.geminiBuffer);
try {
const dataJson = JSON.parse(requester.geminiBuffer);
const responseContent = dataJson.candidates[0]?.content?.parts[0]?.text
requester.message.content += responseContent;
const annotationSources = dataJson.candidates[0]?.groundingMetadata.groundingChunks?.map(chunk => {
return {
"type": "url_citation",
"text": chunk?.web?.title,
"url": chunk?.web?.uri,
}
});
const annotations = dataJson.candidates[0]?.groundingMetadata.groundingSupports?.map(citation => {
return {
"type": "url_citation",
"start_index": citation.segment?.startIndex,
"end_index": citation.segment?.endIndex,
"text": citation?.segment.text,
"url": annotationSources[citation.groundingChunkIndices[0]]?.url,
"sources": citation.groundingChunkIndices
}
});
requester.message.annotationSources = annotationSources;
requester.message.annotations = annotations;
// console.log(JSON.stringify(requester.message, null, 2));
} catch (e) {
console.log("[AI] Could not parse response from stream: ", e);
requester.message.content += requester.geminiBuffer
} finally {
requester.geminiBuffer = "";
@@ -7,4 +7,6 @@ QtObject {
property string model
property bool thinking: true
property bool done: false
property var annotations: []
property var annotationSources: []
}