MCPcopy
hub / github.com/wavetermdev/waveterm / buildGeminiHTTPRequest

Function buildGeminiHTTPRequest

pkg/aiusechat/gemini/gemini-backend.go:58–177  ·  view source on GitHub ↗

buildGeminiHTTPRequest creates an HTTP request for the Gemini API

(ctx context.Context, contents []GeminiContent, chatOpts uctypes.WaveChatOpts)

Source from the content-addressed store, hash-verified

56
57// buildGeminiHTTPRequest creates an HTTP request for the Gemini API
58func buildGeminiHTTPRequest(ctx context.Context, contents []GeminiContent, chatOpts uctypes.WaveChatOpts) (*http.Request, error) {
59 opts := chatOpts.Config
60
61 if opts.Model == "" {
62 return nil, errors.New("ai:model is required")
63 }
64 if opts.APIToken == "" {
65 return nil, errors.New("ai:apitoken is required")
66 }
67 if opts.Endpoint == "" {
68 return nil, errors.New("ai:endpoint is required")
69 }
70
71 maxTokens := opts.MaxTokens
72 if maxTokens <= 0 {
73 maxTokens = GeminiDefaultMaxTokens
74 }
75
76 // Build request body
77 reqBody := &GeminiRequest{
78 Contents: contents,
79 GenerationConfig: &GeminiGenerationConfig{
80 MaxOutputTokens: int32(maxTokens),
81 Temperature: 0.7, // Default temperature
82 },
83 }
84
85 // Map thinking level for Gemini 3+ models
86 if opts.ThinkingLevel != "" && strings.Contains(opts.Model, "gemini-3") {
87 geminiThinkingLevel := "high"
88 if opts.ThinkingLevel == uctypes.ThinkingLevelLow {
89 geminiThinkingLevel = "low"
90 }
91 reqBody.GenerationConfig.ThinkingConfig = &GeminiThinkingConfig{
92 ThinkingLevel: geminiThinkingLevel,
93 }
94 }
95
96 // Add system instruction if provided
97 if len(chatOpts.SystemPrompt) > 0 {
98 systemText := strings.Join(chatOpts.SystemPrompt, "\n\n")
99 reqBody.SystemInstruction = &GeminiContent{
100 Parts: []GeminiMessagePart{
101 {Text: systemText},
102 },
103 }
104 }
105
106 // Add tools if provided
107 var allTools []uctypes.ToolDefinition
108 allTools = append(allTools, chatOpts.Tools...)
109 allTools = append(allTools, chatOpts.TabTools...)
110
111 if len(allTools) > 0 {
112 var functionDeclarations []GeminiFunctionDeclaration
113 for _, tool := range allTools {
114 // Only include tools whose capabilities are met
115 if !tool.HasRequiredCapabilities(opts.Capabilities) {

Callers 1

RunGeminiChatStepFunction · 0.85

Calls 7

IsDevModeFunction · 0.92
JsonEncodeRequestBodyFunction · 0.92
ensureAltSseFunction · 0.85
SetMethod · 0.45

Tested by

no test coverage detected