Skip to content

Commit

Permalink
add gemini 1.5 pro model (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhu327 authored Mar 27, 2024
1 parent 0c97675 commit 6b51aec
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 54 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ Gemini-OpenAI-Proxy offers a straightforward way to integrate OpenAI functionali
}'
```

If you already have access to the Gemini 1.5 Pro api, you can use:

```bash
curl http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $YOUR_GOOGLE_AI_STUDIO_API_KEY" \
-d '{
"model": "gpt-4-turbo-preview",
"messages": [{"role": "user", "content": "Say this is a test!"}],
"temperature": 0.7
}'
```

4. **Handle Responses:**
Process the responses from the Gemini-OpenAI-Proxy in the same way you would handle responses from OpenAI.

Expand Down
23 changes: 20 additions & 3 deletions api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"log"
"net/http"
"strings"

"github.com/gin-gonic/gin"
"github.com/google/generative-ai-go/genai"
Expand All @@ -30,6 +31,18 @@ func ModelListHandler(c *gin.Context) {
Object: "model",
OwnedBy: "openai",
},
openai.Model{
CreatedAt: 1686935002,
ID: openai.GPT4,
Object: "model",
OwnedBy: "openai",
},
openai.Model{
CreatedAt: 1686935002,
ID: openai.GPT4TurboPreview,
Object: "model",
OwnedBy: "openai",
},
openai.Model{
CreatedAt: 1686935002,
ID: openai.GPT4VisionPreview,
Expand Down Expand Up @@ -88,11 +101,15 @@ func ChatProxyHandler(c *gin.Context) {
defer client.Close()

var gemini adapter.GenaiModelAdapter
switch req.Model {
case openai.GPT4VisionPreview:
switch {
case req.Model == openai.GPT4VisionPreview:
gemini = adapter.NewGeminiProVisionAdapter(client)
case req.Model == openai.GPT4TurboPreview || req.Model == openai.GPT4Turbo1106 || req.Model == openai.GPT4Turbo0125:
gemini = adapter.NewGeminiProAdapter(client, adapter.Gemini1Dot5Pro)
case strings.HasPrefix(req.Model, openai.GPT4):
gemini = adapter.NewGeminiProAdapter(client, adapter.Gemini1Ultra)
default:
gemini = adapter.NewGeminiProAdapter(client)
gemini = adapter.NewGeminiProAdapter(client, adapter.Gemini1Pro)
}

if !req.Stream {
Expand Down
74 changes: 39 additions & 35 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,66 @@ module github.com/zhu327/gemini-openai-proxy
go 1.21.1

require (
cloud.google.com/go/ai v0.3.0 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
github.com/gin-contrib/cors v1.7.1
github.com/gin-gonic/gin v1.9.1
github.com/google/generative-ai-go v0.10.0
github.com/google/uuid v1.6.0
github.com/pkg/errors v0.9.1
github.com/sashabaranov/go-openai v1.20.4
google.golang.org/api v0.171.0
)

require (
cloud.google.com/go v0.112.1 // indirect
cloud.google.com/go/ai v0.3.4 // indirect
cloud.google.com/go/compute v1.25.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/longrunning v0.5.4 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
cloud.google.com/go/longrunning v0.5.6 // indirect
github.com/bytedance/sonic v1.11.3 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/cors v1.5.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.16.0 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/generative-ai-go v0.5.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sashabaranov/go-openai v1.17.9 // indirect
github.com/pelletier/go-toml/v2 v2.2.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
golang.org/x/arch v0.6.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.154.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240325203815-454cdb8f5daa // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240325203815-454cdb8f5daa // indirect
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 6b51aec

Please sign in to comment.