fix: gemini system cannot be empty

This commit is contained in:
ikechan8370 2025-02-04 12:13:58 +08:00
parent bbba9bc872
commit e224272012

View file

@ -169,11 +169,6 @@ export class CustomGoogleGeminiClient extends GoogleGeminiClient {
* @type Array<Content> * @type Array<Content>
*/ */
contents: history, contents: history,
system_instruction: {
parts: {
text: systemMessage
}
},
safetySettings: [ safetySettings: [
{ {
category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
@ -204,6 +199,13 @@ export class CustomGoogleGeminiClient extends GoogleGeminiClient {
}, },
tools: [] tools: []
} }
if (systemMessage) {
body.system_instruction = {
parts: {
text: systemMessage
}
}
}
if (this.tools?.length > 0) { if (this.tools?.length > 0) {
body.tools.push({ body.tools.push({
function_declarations: this.tools.map(tool => tool.function()) function_declarations: this.tools.map(tool => tool.function())