mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-07 13:59:28 +08:00
fix(GeminiProvider): relocate grounding metadata handling (#5490)
* fix(GeminiProvider): relocate grounding metadata handling to improve code clarity and maintainability * refactor(GeminiProvider): enhance conditional checks for chunk processing
This commit is contained in:
parent
0782b24790
commit
57e8b9a592
@ -447,26 +447,27 @@ export default class GeminiProvider extends BaseProvider {
|
|||||||
final_time_completion_millsec = new Date().getTime() - start_time_millsec
|
final_time_completion_millsec = new Date().getTime() - start_time_millsec
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Grounding/Search Metadata
|
|
||||||
const groundingMetadata = chunk.candidates?.[0]?.groundingMetadata
|
|
||||||
if (groundingMetadata) {
|
|
||||||
onChunk({
|
|
||||||
type: ChunkType.LLM_WEB_SEARCH_COMPLETE,
|
|
||||||
llm_web_search: {
|
|
||||||
results: groundingMetadata,
|
|
||||||
source: WebSearchSource.GEMINI
|
|
||||||
}
|
|
||||||
} as LLMWebSearchCompleteChunk)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Image Generation
|
// 4. Image Generation
|
||||||
const generateImage = this.processGeminiImageResponse(chunk)
|
const generateImage = this.processGeminiImageResponse(chunk)
|
||||||
if (generateImage?.images?.length) {
|
if (generateImage?.images?.length) {
|
||||||
onChunk({ type: ChunkType.IMAGE_COMPLETE, image: generateImage })
|
onChunk({ type: ChunkType.IMAGE_COMPLETE, image: generateImage })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chunk.candidates?.[0]?.finishReason && chunk.text) {
|
if (chunk.candidates?.[0]?.finishReason) {
|
||||||
onChunk({ type: ChunkType.TEXT_COMPLETE, text: content })
|
if (chunk.text) {
|
||||||
|
onChunk({ type: ChunkType.TEXT_COMPLETE, text: content })
|
||||||
|
}
|
||||||
|
if (chunk.candidates?.[0]?.groundingMetadata) {
|
||||||
|
// 3. Grounding/Search Metadata
|
||||||
|
const groundingMetadata = chunk.candidates?.[0]?.groundingMetadata
|
||||||
|
onChunk({
|
||||||
|
type: ChunkType.LLM_WEB_SEARCH_COMPLETE,
|
||||||
|
llm_web_search: {
|
||||||
|
results: groundingMetadata,
|
||||||
|
source: WebSearchSource.GEMINI
|
||||||
|
}
|
||||||
|
} as LLMWebSearchCompleteChunk)
|
||||||
|
}
|
||||||
onChunk({
|
onChunk({
|
||||||
type: ChunkType.BLOCK_COMPLETE,
|
type: ChunkType.BLOCK_COMPLETE,
|
||||||
response: {
|
response: {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user