| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package genai |
| 16 |
|
| 17 |
import ( |
| 18 |
"google.golang.org/api/option" |
| 19 |
"google.golang.org/api/option/internaloption" |
| 20 |
) |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
func WithREST() option.ClientOption { |
| 25 |
return &withREST{} |
| 26 |
} |
| 27 |
|
| 28 |
type withREST struct { |
| 29 |
internaloption.EmbeddableAdapter |
| 30 |
} |
| 31 |
|
| 32 |
func (w *withREST) applyVertexaiOpt(c *config) { |
| 33 |
c.withREST = true |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
func WithClientInfo(key, value string) option.ClientOption { |
| 39 |
return &withClientInfo{key: key, value: value} |
| 40 |
} |
| 41 |
|
| 42 |
type withClientInfo struct { |
| 43 |
internaloption.EmbeddableAdapter |
| 44 |
key, value string |
| 45 |
} |
| 46 |
|
| 47 |
func (w *withClientInfo) applyVertexaiOpt(c *config) { |
| 48 |
c.ciKey = w.key |
| 49 |
c.ciValue = w.value |
| 50 |
} |
| 51 |
|
| 52 |
type config struct { |
| 53 |
|
| 54 |
withREST bool |
| 55 |
|
| 56 |
ciKey string |
| 57 |
ciValue string |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
func newConfig(opts ...option.ClientOption) config { |
| 63 |
var conf config |
| 64 |
for _, opt := range opts { |
| 65 |
if vOpt, ok := opt.(vertexaiClientOption); ok { |
| 66 |
vOpt.applyVertexaiOpt(&conf) |
| 67 |
} |
| 68 |
} |
| 69 |
return conf |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
type vertexaiClientOption interface { |
| 74 |
option.ClientOption |
| 75 |
applyVertexaiOpt(*config) |
| 76 |
} |