-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add gemini vertex model provider #297
base: main
Are you sure you want to change the base?
feat: add gemini vertex model provider #297
Conversation
b1d1b1f
to
9b9764a
Compare
9b9764a
to
cfbf03f
Compare
My concern with this is that it is not I noticed that there is a Go package: https://github.com/googleapis/go-genai In your opinion, would this work for us? |
Back to draft for the rewrite to Go... |
98cb57c
to
69fd5cf
Compare
Go Rewrite is done, but I'll continue implementing the embeddings API as well |
With the Go rewrite, I also the /embeddings endpoint (needed a custom implementation as it's not part of their SDK and I couldn't get it working with what they have there so far... I re-used a bunch of code from knowledge, so it's fine). |
c8d48dc
to
0fa890a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bunch of nits, but I there are a couple comments that should be addressed.
} | ||
|
||
func configure(ctx context.Context) (*genai.Client, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
if err := validate(ctx); err != nil { | ||
fmt.Printf("{\"error\": \"%s\"}\n", err) | ||
} | ||
os.Exit(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't want to always exit 1
for `validate.
} | ||
|
||
func Run(client *genai.Client, port string) error { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
mux.HandleFunc("/v1/models", s.listModels) | ||
mux.HandleFunc("/v1/chat/completions", s.chatCompletions) | ||
mux.HandleFunc("/v1/embeddings", s.embeddings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mux.HandleFunc("/v1/models", s.listModels) | |
mux.HandleFunc("/v1/chat/completions", s.chatCompletions) | |
mux.HandleFunc("/v1/embeddings", s.embeddings) | |
mux.HandleFunc("GET /v1/models", s.listModels) | |
mux.HandleFunc("POST /v1/chat/completions", s.chatCompletions) | |
mux.HandleFunc("POST /v1/embeddings", s.embeddings) |
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
return choices, nil | ||
} | ||
|
||
func mapToOpenAIChoice(candidates []*genai.Candidate) ([]openai.ChatCompletionChoice, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same nits on this function
} | ||
|
||
func mapMessagesFromOpenAI(messages []openai.ChatCompletionMessage) ([]*genai.Content, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
|
||
// embeddings - not (yet) provided by the Google GenAI package | ||
func (s *server) embeddings(w http.ResponseWriter, r *http.Request) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
http.Error(w, fmt.Sprintf("unexpected status code: %d", resp.StatusCode), http.StatusInternalServerError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this make sense?
http.Error(w, fmt.Sprintf("unexpected status code: %d", resp.StatusCode), http.StatusInternalServerError) | |
http.Error(w, fmt.Sprintf("unexpected status code: %d", resp.StatusCode), resp.StatusCode) |
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
http.Error(w, fmt.Sprintf("couldn't read response body: %v", err), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
var embeddingResponse vertexEmbeddingResponse | ||
err = json.Unmarshal(body, &embeddingResponse) | ||
if err != nil { | ||
http.Error(w, fmt.Sprintf("couldn't unmarshal response body: %v", err), http.StatusInternalServerError) | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we combine these with json.NewDecoder(resp.Body).Decode(&embeddingResponse)
?
Already implements the /validate endpoint from obot-platform/obot#1019
Ref: obot-platform/obot#872