Skip to content

Commit dd15d27

Browse files
committed
adds support for gemini format (native and openai)
1 parent bf89395 commit dd15d27

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ module github.com/maximhq/maxim-go
33
go 1.21
44

55
require github.com/google/uuid v1.6.0
6+
7+
require github.com/joho/godotenv v1.5.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
22
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
3+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
4+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=

logging/base.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const (
1111
ProviderAzure = "azure"
1212
ProviderAnthropic = "anthropic"
1313
ProviderBedrock = "aws"
14+
ProviderGemini = "gemini"
1415
)
1516

1617
// baseConfig is the configuration for a base entity.

logging/generation.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package logging
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"log"
67
"time"
78
)
@@ -165,6 +166,11 @@ type Generation struct {
165166
}
166167

167168
func newGeneration(c *GenerationConfig, w *writer) *Generation {
169+
// Validating provider
170+
if c.Provider != ProviderOpenAI && c.Provider != ProviderAzure && c.Provider != ProviderBedrock && c.Provider != ProviderAnthropic && c.Provider != ProviderGemini {
171+
fmt.Printf("[MaximSDK] Invalid provider %s, allowed providers are %s, %s, %s, %s, %s\n", c.Provider, ProviderOpenAI, ProviderAzure, ProviderBedrock, ProviderAnthropic, ProviderGemini)
172+
return nil
173+
}
168174
return &Generation{
169175
base: newBase(EntityGeneration, c.Id, &baseConfig{
170176
SpanId: c.SpanId,
@@ -219,6 +225,11 @@ func (g *Generation) handleAnthropicResult(jsonData []byte) (*MaximLLMResult, er
219225
return ParseAnthropicResult(jsonData)
220226
}
221227

228+
// handleGeminiResult extracts and logs data from a Gemini completion
229+
func (g *Generation) handleGeminiResult(jsonData []byte) (*MaximLLMResult, error) {
230+
return ParseGeminiResult(jsonData)
231+
}
232+
222233
// handleAzure extracts and logs data from an Azure OpenAI completion
223234
func (g *Generation) handleAzure(jsonData []byte, _ time.Duration) (*MaximLLMResult, error) {
224235
// Azure OpenAI has the same response format as OpenAI
@@ -255,6 +266,8 @@ func (g *Generation) SetResult(r interface{}) {
255266
finalResult, err = g.handleBedrockConverseResult(jsonData)
256267
case ProviderAnthropic:
257268
finalResult, err = g.handleAnthropicResult(jsonData)
269+
case ProviderGemini:
270+
finalResult, err = g.handleGeminiResult(jsonData)
258271
}
259272
if err != nil {
260273
log.Println("[MaximSDK] Failed to parse result", err)

logging/parser.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ func ParseResult(provider, model string, r interface{}) (*MaximLLMResult, error)
2424
finalResult, err = ParseBedrockResult(model, jsonData)
2525
case ProviderAnthropic:
2626
finalResult, err = ParseAnthropicResult(jsonData)
27+
case ProviderGemini:
28+
finalResult, err = ParseGeminiResult(jsonData)
2729
}
2830
return finalResult, err
2931
}

0 commit comments

Comments
 (0)