Skip to content

Commit ee4e5a4

Browse files
qiaodevcopybara-github
authored andcommitted
feat!: Make some numeric fields to pointer type and bool fields to value type, and rename ControlReferenceTypeControlType* constants
PiperOrigin-RevId: 718535424
1 parent 765c9b7 commit ee4e5a4

File tree

7 files changed

+124
-133
lines changed

7 files changed

+124
-133
lines changed

client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ type Backend int
4040
const (
4141
// BackendUnspecified causes the backend determined automatically. If the
4242
// GOOGLE_GENAI_USE_VERTEXAI environment variable is set to "1" or "true", then
43-
// the backend is `BackendVertexAI`. Otherwise, if GOOGLE_GENAI_USE_VERTEXAI
44-
// is unset or set to any other value, then `BackendGeminiAPI` is used. Explicitly
43+
// the backend is BackendVertexAI. Otherwise, if GOOGLE_GENAI_USE_VERTEXAI
44+
// is unset or set to any other value, then BackendGeminiAPI is used. Explicitly
4545
// setting the backend in ClientConfig overrides the environment variable.
4646
BackendUnspecified Backend = iota
4747
// BackendGeminiAPI is the Gemini API backend.

example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ func ExampleModels_GenerateContent_config_vertexai() {
617617
TopK: genai.Ptr(2.0),
618618
ResponseMIMEType: "application/json",
619619
StopSequences: []string{"\n"},
620-
CandidateCount: 2,
620+
CandidateCount: genai.Ptr(int64(2)),
621621
Seed: genai.Ptr[int64](42),
622622
MaxOutputTokens: genai.Ptr[int64](128),
623623
PresencePenalty: genai.Ptr(0.5),
@@ -651,7 +651,7 @@ func ExampleModels_GenerateContent_config_geminiapi() {
651651
TopK: genai.Ptr(2.0),
652652
ResponseMIMEType: "application/json",
653653
StopSequences: []string{"\n"},
654-
CandidateCount: 2,
654+
CandidateCount: genai.Ptr(int64(2)),
655655
Seed: genai.Ptr(int64(42)),
656656
MaxOutputTokens: genai.Ptr(int64(128)),
657657
PresencePenalty: genai.Ptr(0.5),

live.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ import (
2323
"github.com/gorilla/websocket"
2424
)
2525

26-
// Live struct encapsulates the configuration for realtime interaction with the Generative Language API.
26+
// Live can be used to create a realtime connection to the API.
27+
// It is initiated when creating a client. You don't need to create a new Live object.
28+
//
29+
// client, _ := genai.NewClient(ctx, &genai.ClientConfig{})
30+
// session, _ := client.Live.Connect(model, &genai.LiveConnectConfig{}).
2731
type Live struct {
2832
apiClient *apiClient
2933
}
3034

31-
// Session struct represents a realtime connection to the API.
35+
// Session is a realtime connection to the API.
3236
type Session struct {
3337
conn *websocket.Conn
3438
apiClient *apiClient
@@ -116,7 +120,7 @@ func (r *Live) Connect(model string, config *LiveConnectConfig) (*Session, error
116120
return s, nil
117121
}
118122

119-
// Send transmits a LiveClientMessage over the established websocket connection.
123+
// Send transmits a LiveClientMessage over the established connection.
120124
// It returns an error if sending the message fails.
121125
func (s *Session) Send(input *LiveClientMessage) error {
122126
if input.Setup != nil {
@@ -146,7 +150,7 @@ func (s *Session) Send(input *LiveClientMessage) error {
146150
return s.conn.WriteMessage(websocket.TextMessage, []byte(data))
147151
}
148152

149-
// Receive reads a LiveServerMessage from the websocket connection.
153+
// Receive reads a LiveServerMessage from the connection.
150154
// It returns the received message or an error if reading or unmarshalling fails.
151155
func (s *Session) Receive() (*LiveServerMessage, error) {
152156
messageType, msgBytes, err := s.conn.ReadMessage()
@@ -181,7 +185,7 @@ func (s *Session) Receive() (*LiveServerMessage, error) {
181185
return message, err
182186
}
183187

184-
// Close terminates the websocket connection.
188+
// Close terminates the connection.
185189
func (s *Session) Close() {
186190
s.conn.Close()
187191
}

models_helpers.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ func (c *GenerateContentConfig) setDefaults() {
3030
if c == nil {
3131
return
3232
}
33-
if c.CandidateCount == 0 {
34-
c.CandidateCount = 1
35-
}
3633
if c.SystemInstruction != nil && c.SystemInstruction.Role == "" {
3734
c.SystemInstruction.setDefaults()
3835
}

models_helpers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestContentHelpers(t *testing.T) {
4343
})
4444

4545
t.Run("GenerateContentConfig_setDefaults", func(t *testing.T) {
46-
expected := &GenerateContentConfig{SystemInstruction: &Content{Parts: []*Part{{Text: "Hello"}}, Role: roleUser}, CandidateCount: 1}
46+
expected := &GenerateContentConfig{SystemInstruction: &Content{Parts: []*Part{{Text: "Hello"}}, Role: roleUser}}
4747
got := &GenerateContentConfig{SystemInstruction: &Content{Parts: []*Part{{Text: "Hello"}}}}
4848
got.setDefaults()
4949
if diff := cmp.Diff(got, expected); diff != "" {

0 commit comments

Comments
 (0)