mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 23:10:20 +08:00
fix: update geminiapi check (#6002)
This commit is contained in:
parent
12a07b853e
commit
fe78ce1d70
@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
Content,
|
Content,
|
||||||
File,
|
File,
|
||||||
|
FinishReason,
|
||||||
FunctionCall,
|
FunctionCall,
|
||||||
GenerateContentConfig,
|
GenerateContentConfig,
|
||||||
GenerateContentResponse,
|
GenerateContentResponse,
|
||||||
@ -912,14 +913,32 @@ export default class GeminiProvider extends BaseProvider {
|
|||||||
return { valid: false, error: new Error('No model found') }
|
return { valid: false, error: new Error('No model found') }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let config: GenerateContentConfig = {
|
||||||
|
maxOutputTokens: 1
|
||||||
|
}
|
||||||
|
if (isGeminiReasoningModel(model)) {
|
||||||
|
config = {
|
||||||
|
...config,
|
||||||
|
thinkingConfig: {
|
||||||
|
includeThoughts: false
|
||||||
|
} as ThinkingConfig
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isGenerateImageModel(model)) {
|
||||||
|
config = {
|
||||||
|
...config,
|
||||||
|
responseModalities: [Modality.TEXT, Modality.IMAGE],
|
||||||
|
responseMimeType: 'text/plain'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!stream) {
|
if (!stream) {
|
||||||
const result = await this.sdk.models.generateContent({
|
const result = await this.sdk.models.generateContent({
|
||||||
model: model.id,
|
model: model.id,
|
||||||
contents: [{ role: 'user', parts: [{ text: 'hi' }] }],
|
contents: [{ role: 'user', parts: [{ text: 'hi' }] }],
|
||||||
config: {
|
config: config
|
||||||
maxOutputTokens: 1
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
if (isEmpty(result.text)) {
|
if (isEmpty(result.text)) {
|
||||||
throw new Error('Empty response')
|
throw new Error('Empty response')
|
||||||
@ -928,14 +947,12 @@ export default class GeminiProvider extends BaseProvider {
|
|||||||
const response = await this.sdk.models.generateContentStream({
|
const response = await this.sdk.models.generateContentStream({
|
||||||
model: model.id,
|
model: model.id,
|
||||||
contents: [{ role: 'user', parts: [{ text: 'hi' }] }],
|
contents: [{ role: 'user', parts: [{ text: 'hi' }] }],
|
||||||
config: {
|
config: config
|
||||||
maxOutputTokens: 1
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
// 等待整个流式响应结束
|
// 等待整个流式响应结束
|
||||||
let hasContent = false
|
let hasContent = false
|
||||||
for await (const chunk of response) {
|
for await (const chunk of response) {
|
||||||
if (chunk.text && chunk.text.length > 0) {
|
if (chunk.candidates && chunk.candidates[0].finishReason === FinishReason.MAX_TOKENS) {
|
||||||
hasContent = true
|
hasContent = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user