mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-01-23 06:18:02 -05:00
Compare commits
1 Commits
config-yam
...
config-res
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbbf377a1f |
@@ -869,7 +869,8 @@ func TestParseToolFile(t *testing.T) {
|
||||
ToolNames: []string{"example_tool"},
|
||||
},
|
||||
},
|
||||
Prompts: nil,
|
||||
AuthServices: nil,
|
||||
Prompts: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -973,7 +974,7 @@ func TestParseToolFile(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Prompts: server.PromptConfigs{
|
||||
"code_review": custom.Config{
|
||||
"code_review": &custom.Config{
|
||||
Name: "code_review",
|
||||
Description: "ask llm to analyze code quality",
|
||||
Arguments: prompts.Arguments{
|
||||
@@ -989,8 +990,8 @@ func TestParseToolFile(t *testing.T) {
|
||||
{
|
||||
description: "only prompts",
|
||||
in: `
|
||||
kind: prompts
|
||||
name: my-prompt
|
||||
kind: prompts
|
||||
name: my-prompt
|
||||
description: A prompt template for data analysis.
|
||||
arguments:
|
||||
- name: country
|
||||
@@ -1066,17 +1067,17 @@ func TestParseToolFileWithAuth(t *testing.T) {
|
||||
database: my_db
|
||||
user: my_user
|
||||
password: my_pass
|
||||
---
|
||||
---
|
||||
kind: authServices
|
||||
name: my-google-service
|
||||
type: google
|
||||
clientId: my-client-id
|
||||
---
|
||||
---
|
||||
kind: authServices
|
||||
name: other-google-service
|
||||
type: google
|
||||
clientId: other-client-id
|
||||
---
|
||||
---
|
||||
kind: tools
|
||||
name: example_tool
|
||||
type: postgres-sql
|
||||
@@ -1102,7 +1103,7 @@ func TestParseToolFileWithAuth(t *testing.T) {
|
||||
field: email
|
||||
- name: other-google-service
|
||||
field: other_email
|
||||
---
|
||||
---
|
||||
kind: toolsets
|
||||
name: example_toolset
|
||||
tools:
|
||||
@@ -1270,17 +1271,17 @@ func TestParseToolFileWithAuth(t *testing.T) {
|
||||
database: my_db
|
||||
user: my_user
|
||||
password: my_pass
|
||||
---
|
||||
---
|
||||
kind: authServices
|
||||
name: my-google-service
|
||||
type: google
|
||||
clientId: my-client-id
|
||||
---
|
||||
---
|
||||
kind: authServices
|
||||
name: other-google-service
|
||||
type: google
|
||||
clientId: other-client-id
|
||||
---
|
||||
---
|
||||
kind: tools
|
||||
name: example_tool
|
||||
type: postgres-sql
|
||||
@@ -1308,7 +1309,7 @@ func TestParseToolFileWithAuth(t *testing.T) {
|
||||
field: email
|
||||
- name: other-google-service
|
||||
field: other_email
|
||||
---
|
||||
---
|
||||
kind: toolsets
|
||||
name: example_toolset
|
||||
tools:
|
||||
@@ -1567,17 +1568,17 @@ func TestEnvVarReplacement(t *testing.T) {
|
||||
Authorization: ${TestHeader}
|
||||
queryParams:
|
||||
api-key: ${API_KEY}
|
||||
---
|
||||
---
|
||||
kind: authServices
|
||||
name: my-google-service
|
||||
type: google
|
||||
clientId: ${clientId}
|
||||
---
|
||||
---
|
||||
kind: authServices
|
||||
name: other-google-service
|
||||
type: google
|
||||
clientId: ${clientId2}
|
||||
---
|
||||
---
|
||||
kind: tools
|
||||
name: example_tool
|
||||
type: http
|
||||
@@ -1618,12 +1619,12 @@ func TestEnvVarReplacement(t *testing.T) {
|
||||
- name: Language
|
||||
type: string
|
||||
description: language string
|
||||
---
|
||||
---
|
||||
kind: toolsets
|
||||
name: ${toolset_name}
|
||||
tools:
|
||||
- example_tool
|
||||
---
|
||||
---
|
||||
kind: prompts
|
||||
name: ${prompt_name}
|
||||
description: A test prompt for {{.name}}.
|
||||
@@ -2601,6 +2602,7 @@ description: "Dummy"
|
||||
---
|
||||
kind: toolsets
|
||||
name: sqlite_database_tools
|
||||
tools:
|
||||
- dummy_tool
|
||||
`
|
||||
toolsetConflictFile := filepath.Join(t.TempDir(), "toolset_conflict.yaml")
|
||||
|
||||
@@ -136,12 +136,12 @@ type PromptsetConfigs map[string]prompts.PromptsetConfig
|
||||
|
||||
func UnmarshalResourceConfig(ctx context.Context, raw []byte) (SourceConfigs, AuthServiceConfigs, EmbeddingModelConfigs, ToolConfigs, ToolsetConfigs, PromptConfigs, error) {
|
||||
// prepare configs map
|
||||
sourceConfigs := make(map[string]sources.SourceConfig)
|
||||
authServiceConfigs := make(AuthServiceConfigs)
|
||||
embeddingModelConfigs := make(EmbeddingModelConfigs)
|
||||
toolConfigs := make(ToolConfigs)
|
||||
toolsetConfigs := make(ToolsetConfigs)
|
||||
promptConfigs := make(PromptConfigs)
|
||||
var sourceConfigs SourceConfigs
|
||||
var authServiceConfigs AuthServiceConfigs
|
||||
var embeddingModelConfigs EmbeddingModelConfigs
|
||||
var toolConfigs ToolConfigs
|
||||
var toolsetConfigs ToolsetConfigs
|
||||
var promptConfigs PromptConfigs
|
||||
// promptset configs is not yet supported
|
||||
|
||||
decoder := yaml.NewDecoder(bytes.NewReader(raw))
|
||||
@@ -171,36 +171,54 @@ func UnmarshalResourceConfig(ctx context.Context, raw []byte) (SourceConfigs, Au
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, nil, fmt.Errorf("error unmarshaling %s: %s", kind, err)
|
||||
}
|
||||
if sourceConfigs == nil {
|
||||
sourceConfigs = make(SourceConfigs)
|
||||
}
|
||||
sourceConfigs[name] = c
|
||||
case "authServices":
|
||||
c, err := UnmarshalYAMLAuthServiceConfig(ctx, name, resource)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, nil, fmt.Errorf("error unmarshaling %s: %s", kind, err)
|
||||
}
|
||||
if authServiceConfigs == nil {
|
||||
authServiceConfigs = make(AuthServiceConfigs)
|
||||
}
|
||||
authServiceConfigs[name] = c
|
||||
case "tools":
|
||||
c, err := UnmarshalYAMLToolConfig(ctx, name, resource)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, nil, fmt.Errorf("error unmarshaling %s: %s", kind, err)
|
||||
}
|
||||
if toolConfigs == nil {
|
||||
toolConfigs = make(ToolConfigs)
|
||||
}
|
||||
toolConfigs[name] = c
|
||||
case "toolsets":
|
||||
c, err := UnmarshalYAMLToolsetConfig(ctx, name, resource)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, nil, fmt.Errorf("error unmarshaling %s: %s", kind, err)
|
||||
}
|
||||
if toolsetConfigs == nil {
|
||||
toolsetConfigs = make(ToolsetConfigs)
|
||||
}
|
||||
toolsetConfigs[name] = c
|
||||
case "embeddingModels":
|
||||
c, err := UnmarshalYAMLEmbeddingModelConfig(ctx, name, resource)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, nil, fmt.Errorf("error unmarshaling %s: %s", kind, err)
|
||||
}
|
||||
if embeddingModelConfigs == nil {
|
||||
embeddingModelConfigs = make(EmbeddingModelConfigs)
|
||||
}
|
||||
embeddingModelConfigs[name] = c
|
||||
case "prompts":
|
||||
c, err := UnmarshalYAMLPromptConfig(ctx, name, resource)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, nil, fmt.Errorf("error unmarshaling %s: %s", kind, err)
|
||||
}
|
||||
if promptConfigs == nil {
|
||||
promptConfigs = make(PromptConfigs)
|
||||
}
|
||||
promptConfigs[name] = c
|
||||
default:
|
||||
return nil, nil, nil, nil, nil, nil, fmt.Errorf("invalid kind %s", kind)
|
||||
|
||||
@@ -53,7 +53,7 @@ func (t *getInstancesTransport) RoundTrip(req *http.Request) (*http.Response, er
|
||||
|
||||
type instance struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Kind string `json:"kind"`
|
||||
}
|
||||
|
||||
type handler struct {
|
||||
@@ -95,7 +95,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
func TestGetInstancesToolEndpoints(t *testing.T) {
|
||||
h := &handler{
|
||||
instances: map[string]*instance{
|
||||
"instance-1": {Name: "instance-1", Type: "sql#instance"},
|
||||
"instance-1": {Name: "instance-1", Kind: "sql#instance"},
|
||||
},
|
||||
t: t,
|
||||
}
|
||||
@@ -151,7 +151,7 @@ func TestGetInstancesToolEndpoints(t *testing.T) {
|
||||
name: "successful get instance",
|
||||
toolName: "get-instance-1",
|
||||
body: `{"projectId": "p1", "instanceId": "instance-1"}`,
|
||||
want: `{"name":"instance-1","type":"sql#instance"}`,
|
||||
want: `{"name":"instance-1","kind":"sql#instance"}`,
|
||||
},
|
||||
{
|
||||
name: "failed get instance",
|
||||
|
||||
Reference in New Issue
Block a user