MCPcopy Create free account
hub / github.com/github/gh-aw / buildPiModelsJSON

Function buildPiModelsJSON

pkg/workflow/pi_engine.go:130–148  ·  view source on GitHub ↗

buildPiModelsJSON returns a minimal Pi models.json payload that registers a single custom provider named "aw-gateway" pointing at the AWF LLM gateway sidecar. Pi's resolveConfigValue() resolves the "apiKey" value by looking up process.env[apiKey], so passing the secret env-var name (e.g. "COPILOT_G

(gatewayPort int, secretEnvVarName, modelID string)

Source from the content-addressed store, hash-verified

128//
129// All dynamic values are marshaled via encoding/json to prevent JSON injection.
130func buildPiModelsJSON(gatewayPort int, secretEnvVarName, modelID string) string {
131 payload := map[string]any{
132 "providers": map[string]any{
133 "aw-gateway": map[string]any{
134 "baseUrl": fmt.Sprintf("http://api-proxy:%d", gatewayPort),
135 "api": "openai-completions",
136 "apiKey": secretEnvVarName,
137 "models": []map[string]any{{"id": modelID}},
138 },
139 },
140 }
141 b, err := json.Marshal(payload)
142 if err != nil {
143 // json.Marshal only fails for non-serialisable types; our map is always
144 // serialisable, so this branch is unreachable in practice.
145 panic(fmt.Sprintf("BUG: buildPiModelsJSON failed to marshal JSON: %v", err))
146 }
147 return string(b)
148}
149
150func resolvePiGatewaySecretEnvVar(profile universalLLMBackendProfile, backend UniversalLLMBackend) string {
151 if len(profile.coreSecretNames) > 0 {

Calls

no outgoing calls