mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-01-11 08:28:11 -05:00
Compare commits
7 Commits
dgraph-int
...
fix-922
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b58d959de1 | ||
|
|
8c532476e0 | ||
|
|
b8b59f0a4d | ||
|
|
ec6942c94b | ||
|
|
c92e84f869 | ||
|
|
0f30709050 | ||
|
|
175277fcad |
@@ -16,6 +16,7 @@ package redis
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
yaml "github.com/goccy/go-yaml"
|
||||
"github.com/googleapis/genai-toolbox/internal/sources"
|
||||
@@ -193,21 +194,32 @@ func replaceCommandsParams(commands [][]string, params tools.Parameters, paramVa
|
||||
for i, cmd := range commands {
|
||||
newCmd := make([]any, 0)
|
||||
for _, part := range cmd {
|
||||
v, ok := paramMap[part]
|
||||
if !ok {
|
||||
// Command part is not a Parameter placeholder
|
||||
newCmd = append(newCmd, part)
|
||||
continue
|
||||
replaced := part
|
||||
isArray := false
|
||||
var arrayItems []any
|
||||
|
||||
if v, ok := paramMap[part]; ok {
|
||||
if typeMap[part] == "array" {
|
||||
isArray = true
|
||||
arrayItems = v.([]any)
|
||||
} else {
|
||||
replaced = fmt.Sprintf("%v", v)
|
||||
}
|
||||
} else {
|
||||
for placeholder, v := range paramMap {
|
||||
replaced = strings.ReplaceAll(replaced, placeholder, fmt.Sprintf("%v", v))
|
||||
}
|
||||
}
|
||||
if typeMap[part] == "array" {
|
||||
for _, item := range v.([]any) {
|
||||
|
||||
if isArray {
|
||||
for _, item := range arrayItems {
|
||||
// Nested arrays will only be expanded once
|
||||
// e.g., [A, [B, C]] --> ["A", "[B C]"]
|
||||
newCmd = append(newCmd, fmt.Sprintf("%s", item))
|
||||
}
|
||||
continue
|
||||
}
|
||||
newCmd = append(newCmd, fmt.Sprintf("%s", v))
|
||||
newCmd = append(newCmd, replaced)
|
||||
}
|
||||
newCommands[i] = newCmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user