Commit 38d4c7b7 by Calcium-Ion Committed by GitHub

Merge pull request #656 from Yan-Zero/main

fix: gemini function call
parents 6f9f7a0b a6989dfb
...@@ -35,9 +35,7 @@ func StrToMap(str string) map[string]interface{} { ...@@ -35,9 +35,7 @@ func StrToMap(str string) map[string]interface{} {
m := make(map[string]interface{}) m := make(map[string]interface{})
err := json.Unmarshal([]byte(str), &m) err := json.Unmarshal([]byte(str), &m)
if err != nil { if err != nil {
return map[string]interface{}{ return nil
"result": str,
}
} }
return m return m
} }
......
...@@ -3,4 +3,7 @@ package constant ...@@ -3,4 +3,7 @@ package constant
var ( var (
FinishReasonStop = "stop" FinishReasonStop = "stop"
FinishReasonToolCalls = "tool_calls" FinishReasonToolCalls = "tool_calls"
FinishReasonLength = "length"
FinishReasonFunctionCall = "function_call"
FinishReasonContentFilter = "content_filter"
) )
...@@ -4,7 +4,7 @@ type GeminiChatRequest struct { ...@@ -4,7 +4,7 @@ type GeminiChatRequest struct {
Contents []GeminiChatContent `json:"contents"` Contents []GeminiChatContent `json:"contents"`
SafetySettings []GeminiChatSafetySettings `json:"safety_settings,omitempty"` SafetySettings []GeminiChatSafetySettings `json:"safety_settings,omitempty"`
GenerationConfig GeminiChatGenerationConfig `json:"generation_config,omitempty"` GenerationConfig GeminiChatGenerationConfig `json:"generation_config,omitempty"`
Tools []GeminiChatTools `json:"tools,omitempty"` Tools []GeminiChatTool `json:"tools,omitempty"`
SystemInstructions *GeminiChatContent `json:"system_instruction,omitempty"` SystemInstructions *GeminiChatContent `json:"system_instruction,omitempty"`
} }
...@@ -18,9 +18,29 @@ type FunctionCall struct { ...@@ -18,9 +18,29 @@ type FunctionCall struct {
Arguments any `json:"args"` Arguments any `json:"args"`
} }
type GeminiFunctionResponseContent struct {
Name string `json:"name"`
Content any `json:"content"`
}
type FunctionResponse struct { type FunctionResponse struct {
Name string `json:"name"` Name string `json:"name"`
Response any `json:"response"` Response GeminiFunctionResponseContent `json:"response"`
}
type GeminiPartExecutableCode struct {
Language string `json:"language,omitempty"`
Code string `json:"code,omitempty"`
}
type GeminiPartCodeExecutionResult struct {
Outcome string `json:"outcome,omitempty"`
Output string `json:"output,omitempty"`
}
type GeminiFileData struct {
MimeType string `json:"mimeType,omitempty"`
FileUri string `json:"fileUri,omitempty"`
} }
type GeminiPart struct { type GeminiPart struct {
...@@ -28,6 +48,9 @@ type GeminiPart struct { ...@@ -28,6 +48,9 @@ type GeminiPart struct {
InlineData *GeminiInlineData `json:"inlineData,omitempty"` InlineData *GeminiInlineData `json:"inlineData,omitempty"`
FunctionCall *FunctionCall `json:"functionCall,omitempty"` FunctionCall *FunctionCall `json:"functionCall,omitempty"`
FunctionResponse *FunctionResponse `json:"functionResponse,omitempty"` FunctionResponse *FunctionResponse `json:"functionResponse,omitempty"`
FileData *GeminiFileData `json:"fileData,omitempty"`
ExecutableCode *GeminiPartExecutableCode `json:"executableCode,omitempty"`
CodeExecutionResult *GeminiPartCodeExecutionResult `json:"codeExecutionResult,omitempty"`
} }
type GeminiChatContent struct { type GeminiChatContent struct {
...@@ -40,8 +63,10 @@ type GeminiChatSafetySettings struct { ...@@ -40,8 +63,10 @@ type GeminiChatSafetySettings struct {
Threshold string `json:"threshold"` Threshold string `json:"threshold"`
} }
type GeminiChatTools struct { type GeminiChatTool struct {
GoogleSearch any `json:"googleSearch,omitempty"` GoogleSearch any `json:"googleSearch,omitempty"`
GoogleSearchRetrieval any `json:"googleSearchRetrieval,omitempty"`
CodeExecution any `json:"codeExecution,omitempty"`
FunctionDeclarations any `json:"functionDeclarations,omitempty"` FunctionDeclarations any `json:"functionDeclarations,omitempty"`
} }
...@@ -54,11 +79,12 @@ type GeminiChatGenerationConfig struct { ...@@ -54,11 +79,12 @@ type GeminiChatGenerationConfig struct {
StopSequences []string `json:"stopSequences,omitempty"` StopSequences []string `json:"stopSequences,omitempty"`
ResponseMimeType string `json:"responseMimeType,omitempty"` ResponseMimeType string `json:"responseMimeType,omitempty"`
ResponseSchema any `json:"responseSchema,omitempty"` ResponseSchema any `json:"responseSchema,omitempty"`
Seed int64 `json:"seed,omitempty"`
} }
type GeminiChatCandidate struct { type GeminiChatCandidate struct {
Content GeminiChatContent `json:"content"` Content GeminiChatContent `json:"content"`
FinishReason string `json:"finishReason"` FinishReason *string `json:"finishReason"`
Index int64 `json:"index"` Index int64 `json:"index"`
SafetyRatings []GeminiChatSafetyRating `json:"safetyRatings"` SafetyRatings []GeminiChatSafetyRating `json:"safetyRatings"`
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment