From 78621cc3ba77805a9a3769d6eb46513403df936b Mon Sep 17 00:00:00 2001 From: Grant Linville Date: Thu, 16 Jan 2025 12:05:40 -0500 Subject: [PATCH] review feedback Signed-off-by: Grant Linville --- anthropic-bedrock-model-provider/tool.gpt | 2 +- anthropic-model-provider/tool.gpt | 2 +- auth-providers-common/go.mod | 3 + .../pkg/env/env.go | 0 azure-openai-model-provider/tool.gpt | 2 +- github-auth-provider/go.mod | 10 +++- github-auth-provider/main.go | 11 ++-- github-auth-provider/tool.gpt | 2 +- google-auth-provider/go.mod | 10 +++- google-auth-provider/main.go | 11 ++-- google-auth-provider/pkg/env/env.go | 57 ------------------- google-auth-provider/tool.gpt | 2 +- groq-model-provider/tool.gpt | 2 +- model-provider-credential/tool.gpt | 7 --- ollama-model-provider/tool.gpt | 2 +- openai-model-provider/tool.gpt | 2 +- placeholder-credential/tool.gpt | 7 +++ vllm-model-provider/tool.gpt | 2 +- voyage-model-provider/tool.gpt | 2 +- xai-model-provider/tool.gpt | 2 +- 20 files changed, 45 insertions(+), 93 deletions(-) create mode 100644 auth-providers-common/go.mod rename {github-auth-provider => auth-providers-common}/pkg/env/env.go (100%) delete mode 100644 google-auth-provider/pkg/env/env.go delete mode 100644 model-provider-credential/tool.gpt create mode 100644 placeholder-credential/tool.gpt diff --git a/anthropic-bedrock-model-provider/tool.gpt b/anthropic-bedrock-model-provider/tool.gpt index 040b2b36..7e103c3c 100644 --- a/anthropic-bedrock-model-provider/tool.gpt +++ b/anthropic-bedrock-model-provider/tool.gpt @@ -2,7 +2,7 @@ Name: Anthropic on AWS Bedrock Description: Model provider for AWS Bedrock hosted Anthropic models Metadata: envVars: OBOT_ANTHROPIC_BEDROCK_MODEL_PROVIDER_ACCESS_KEY_ID,OBOT_ANTHROPIC_BEDROCK_MODEL_PROVIDER_SECRET_ACCESS_KEY,OBOT_ANTHROPIC_BEDROCK_MODEL_PROVIDER_REGION,OBOT_ANTHROPIC_BEDROCK_MODEL_PROVIDER_SESSION_TOKEN Model Provider: true -Credential: ../model-provider-credential as anthropic-bedrock-model-provider +Credential: ../placeholder-credential as anthropic-bedrock-model-provider #!sys.daemon /usr/bin/env python3 ${GPTSCRIPT_TOOL_DIR}/main.py diff --git a/anthropic-model-provider/tool.gpt b/anthropic-model-provider/tool.gpt index eceed8e2..9455655d 100644 --- a/anthropic-model-provider/tool.gpt +++ b/anthropic-model-provider/tool.gpt @@ -2,7 +2,7 @@ Name: Anthropic Description: Model provider for Anthropic hosted Claude3 models Metadata: envVars: OBOT_ANTHROPIC_MODEL_PROVIDER_API_KEY Model Provider: true -Credential: ../model-provider-credential as anthropic-model-provider +Credential: ../placeholder-credential as anthropic-model-provider #!sys.daemon /usr/bin/env python3 ${GPTSCRIPT_TOOL_DIR}/main.py diff --git a/auth-providers-common/go.mod b/auth-providers-common/go.mod new file mode 100644 index 00000000..cba88be5 --- /dev/null +++ b/auth-providers-common/go.mod @@ -0,0 +1,3 @@ +module github.com/obot-platform/tools/auth-providers-common + +go 1.23.4 diff --git a/github-auth-provider/pkg/env/env.go b/auth-providers-common/pkg/env/env.go similarity index 100% rename from github-auth-provider/pkg/env/env.go rename to auth-providers-common/pkg/env/env.go diff --git a/azure-openai-model-provider/tool.gpt b/azure-openai-model-provider/tool.gpt index 6105715a..361bca38 100644 --- a/azure-openai-model-provider/tool.gpt +++ b/azure-openai-model-provider/tool.gpt @@ -3,7 +3,7 @@ Description: Model provider for Azure OpenAI hosted models Metadata: envVars: OBOT_AZURE_OPENAI_MODEL_PROVIDER_ENDPOINT,OBOT_AZURE_OPENAI_MODEL_PROVIDER_CLIENT_ID,OBOT_AZURE_OPENAI_MODEL_PROVIDER_CLIENT_SECRET,OBOT_AZURE_OPENAI_MODEL_PROVIDER_TENANT_ID,OBOT_AZURE_OPENAI_MODEL_PROVIDER_SUBSCRIPTION_ID,OBOT_AZURE_OPENAI_MODEL_PROVIDER_RESOURCE_GROUP Metadata: optionalEnvVars: OBOT_AZURE_OPENAI_MODEL_PROVIDER_API_VERSION=2024-10-21 Model Provider: true -Credential: ../model-provider-credential as azure-openai-model-provider +Credential: ../placeholder-credential as azure-openai-model-provider #!sys.daemon /usr/bin/env python3 ${GPTSCRIPT_TOOL_DIR}/main.py diff --git a/github-auth-provider/go.mod b/github-auth-provider/go.mod index e6051d04..3362c79e 100644 --- a/github-auth-provider/go.mod +++ b/github-auth-provider/go.mod @@ -2,9 +2,15 @@ module github.com/obot-platform/tools/github-auth-provider go 1.23.4 -replace github.com/oauth2-proxy/oauth2-proxy/v7 => github.com/obot-platform/oauth2-proxy/v7 v7.0.0-20241008204315-265dabe17f43 +replace ( + github.com/oauth2-proxy/oauth2-proxy/v7 => github.com/obot-platform/oauth2-proxy/v7 v7.0.0-20241008204315-265dabe17f43 + github.com/obot-platform/tools/auth-providers-common => ../auth-providers-common +) -require github.com/oauth2-proxy/oauth2-proxy/v7 v7.7.1 +require ( + github.com/oauth2-proxy/oauth2-proxy/v7 v7.7.1 + github.com/obot-platform/tools/auth-providers-common v0.0.0-20241008222508-3c6174b443e7 +) require ( cloud.google.com/go/auth v0.9.4 // indirect diff --git a/github-auth-provider/main.go b/github-auth-provider/main.go index 98ea867c..3b0a0438 100644 --- a/github-auth-provider/main.go +++ b/github-auth-provider/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "errors" "fmt" "net/http" "os" @@ -11,7 +12,7 @@ import ( oauth2proxy "github.com/oauth2-proxy/oauth2-proxy/v7" "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options" "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/validation" - "github.com/obot-platform/tools/github-auth-provider/pkg/env" + "github.com/obot-platform/tools/auth-providers-common/pkg/env" "github.com/obot-platform/tools/github-auth-provider/pkg/profile" ) @@ -111,7 +112,7 @@ func main() { mux.HandleFunc("/", oauthProxy.ServeHTTP) fmt.Printf("listening on 127.0.0.1:%s\n", port) - if err := http.ListenAndServe("127.0.0.1:"+port, mux); err != nil { + if err := http.ListenAndServe("127.0.0.1:"+port, mux); !errors.Is(err, http.ErrServerClosed) { fmt.Printf("failed to listen and serve: %v\n", err) os.Exit(1) } @@ -145,9 +146,7 @@ func obotGetState(p *oauth2proxy.OAuthProxy) http.HandlerFunc { return } - for k, v := range sr.Header { - reqObj.Header[k] = v - } + reqObj.Header = sr.Header state, err := p.LoadCookiedSession(reqObj) if err != nil { @@ -202,6 +201,4 @@ func obotGetIconURL(w http.ResponseWriter, r *http.Request) { http.Error(w, fmt.Sprintf("failed to encode response: %v", err), http.StatusInternalServerError) return } - - w.WriteHeader(http.StatusOK) } diff --git a/github-auth-provider/tool.gpt b/github-auth-provider/tool.gpt index d72350ac..eb8e8581 100644 --- a/github-auth-provider/tool.gpt +++ b/github-auth-provider/tool.gpt @@ -2,7 +2,7 @@ Name: GitHub Description: Auth provider for GitHub Metadata: envVars: OBOT_GITHUB_AUTH_PROVIDER_CLIENT_ID,OBOT_GITHUB_AUTH_PROVIDER_CLIENT_SECRET,OBOT_AUTH_PROVIDER_COOKIE_SECRET,OBOT_AUTH_PROVIDER_EMAIL_DOMAINS Metadata: optionalEnvVars: OBOT_GITHUB_AUTH_PROVIDER_TEAMS,OBOT_GITHUB_AUTH_PROVIDER_ORG,OBOT_GITHUB_AUTH_PROVIDER_REPO,OBOT_GITHUB_AUTH_PROVIDER_TOKEN,OBOT_GITHUB_AUTH_PROVIDER_ALLOW_USERS -Credential: ../model-provider-credential as github-auth-provider +Credential: ../placeholder-credential as github-auth-provider #!sys.daemon ${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool diff --git a/google-auth-provider/go.mod b/google-auth-provider/go.mod index f93f4b03..6ebcfed5 100644 --- a/google-auth-provider/go.mod +++ b/google-auth-provider/go.mod @@ -2,9 +2,15 @@ module github.com/obot-platform/tools/google-auth-provider go 1.23.4 -replace github.com/oauth2-proxy/oauth2-proxy/v7 => github.com/obot-platform/oauth2-proxy/v7 v7.0.0-20241008204315-265dabe17f43 +replace ( + github.com/oauth2-proxy/oauth2-proxy/v7 => github.com/obot-platform/oauth2-proxy/v7 v7.0.0-20241008204315-265dabe17f43 + github.com/obot-platform/tools/auth-providers-common => ../auth-providers-common +) -require github.com/oauth2-proxy/oauth2-proxy/v7 v7.7.1 +require ( + github.com/oauth2-proxy/oauth2-proxy/v7 v7.7.1 + github.com/obot-platform/tools/auth-providers-common v0.0.0-20241008222508-3c6174b443e7 +) require ( cloud.google.com/go/auth v0.9.4 // indirect diff --git a/google-auth-provider/main.go b/google-auth-provider/main.go index 47c8be60..eda7185f 100644 --- a/google-auth-provider/main.go +++ b/google-auth-provider/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "errors" "fmt" "net/http" "os" @@ -11,7 +12,7 @@ import ( oauth2proxy "github.com/oauth2-proxy/oauth2-proxy/v7" "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options" "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/validation" - "github.com/obot-platform/tools/google-auth-provider/pkg/env" + "github.com/obot-platform/tools/auth-providers-common/pkg/env" "github.com/obot-platform/tools/google-auth-provider/pkg/profile" ) @@ -89,7 +90,7 @@ func main() { mux.HandleFunc("/", oauthProxy.ServeHTTP) fmt.Printf("listening on 127.0.0.1:%s\n", port) - if err := http.ListenAndServe("127.0.0.1:"+port, mux); err != nil { + if err := http.ListenAndServe("127.0.0.1:"+port, mux); !errors.Is(err, http.ErrServerClosed) { fmt.Printf("failed to listen and serve: %v\n", err) os.Exit(1) } @@ -123,9 +124,7 @@ func obotGetState(p *oauth2proxy.OAuthProxy) http.HandlerFunc { return } - for k, v := range sr.Header { - reqObj.Header[k] = v - } + reqObj.Header = sr.Header state, err := p.LoadCookiedSession(reqObj) if err != nil { @@ -180,6 +179,4 @@ func obotGetIconURL(w http.ResponseWriter, r *http.Request) { http.Error(w, fmt.Sprintf("failed to encode response: %v", err), http.StatusInternalServerError) return } - - w.WriteHeader(http.StatusOK) } diff --git a/google-auth-provider/pkg/env/env.go b/google-auth-provider/pkg/env/env.go deleted file mode 100644 index b6fbd682..00000000 --- a/google-auth-provider/pkg/env/env.go +++ /dev/null @@ -1,57 +0,0 @@ -package env - -import ( - "fmt" - "os" - "reflect" - "strings" -) - -func LoadEnvForStruct[T any](s *T) error { - v := reflect.ValueOf(s).Elem() // Dereference pointer to get struct value - t := v.Type() - - if t.Kind() != reflect.Struct { - return fmt.Errorf("expected a struct, got %v", t.Kind()) - } - - for i := 0; i < t.NumField(); i++ { - field := t.Field(i) - varName := field.Tag.Get("env") - if varName == "" { - continue - } - - // Check environment and default if set - value := os.Getenv(varName) - if value == "" { - defaultValue := field.Tag.Get("default") - if defaultValue != "" { - value = defaultValue - } else { - return fmt.Errorf("missing required environment variable %s", varName) - } - } - - fieldValue := v.Field(i) - if !fieldValue.CanSet() { - return fmt.Errorf("cannot set value for field %s", field.Name) - } - - // We can add more types as needed - switch field.Type.Kind() { - case reflect.String: - fieldValue.SetString(value) - case reflect.Slice: - if field.Type.Elem().Kind() == reflect.String { - fieldValue.Set(reflect.ValueOf(strings.Split(value, ","))) - } else { - return fmt.Errorf("unsupported slice element type %v for field %s", field.Type.Elem().Kind(), field.Name) - } - default: - return fmt.Errorf("unsupported type %v for field %s", field.Type.Kind(), field.Name) - } - } - - return nil -} diff --git a/google-auth-provider/tool.gpt b/google-auth-provider/tool.gpt index ff941f2a..a4e07540 100644 --- a/google-auth-provider/tool.gpt +++ b/google-auth-provider/tool.gpt @@ -1,7 +1,7 @@ Name: Google Description: Auth provider for Google Metadata: envVars: OBOT_GOOGLE_AUTH_PROVIDER_CLIENT_ID,OBOT_GOOGLE_AUTH_PROVIDER_CLIENT_SECRET,OBOT_AUTH_PROVIDER_COOKIE_SECRET,OBOT_AUTH_PROVIDER_EMAIL_DOMAINS -Credential: ../model-provider-credential as google-auth-provider +Credential: ../placeholder-credential as google-auth-provider #!sys.daemon ${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool diff --git a/groq-model-provider/tool.gpt b/groq-model-provider/tool.gpt index bc1c1eab..2b4dc473 100644 --- a/groq-model-provider/tool.gpt +++ b/groq-model-provider/tool.gpt @@ -2,7 +2,7 @@ Name: Groq Description: Model provider for models running on Groq Metadata: envVars: OBOT_GROQ_MODEL_PROVIDER_API_KEY Model Provider: true -Credential: ../model-provider-credential as groq-model-provider +Credential: ../placeholder-credential as groq-model-provider #!sys.daemon /usr/bin/env python3 ${GPTSCRIPT_TOOL_DIR}/main.py diff --git a/model-provider-credential/tool.gpt b/model-provider-credential/tool.gpt deleted file mode 100644 index f6ad5939..00000000 --- a/model-provider-credential/tool.gpt +++ /dev/null @@ -1,7 +0,0 @@ -Name: Model Provider credential -Description: This is a fake credential tool for the model providers. These credentials are handled in Acorn and this tool should never be called. - -#!/bin/bash - -echo "The credential has not been properly configured" -exit 1 \ No newline at end of file diff --git a/ollama-model-provider/tool.gpt b/ollama-model-provider/tool.gpt index d7032372..a8ebd69b 100644 --- a/ollama-model-provider/tool.gpt +++ b/ollama-model-provider/tool.gpt @@ -2,7 +2,7 @@ Name: Ollama Description: Model provider for models running on Ollama Metadata: envVars: OBOT_OLLAMA_MODEL_PROVIDER_HOST Model Provider: true -Credential: ../model-provider-credential as ollama-model-provider +Credential: ../placeholder-credential as ollama-model-provider #!sys.daemon /usr/bin/env python3 ${GPTSCRIPT_TOOL_DIR}/main.py diff --git a/openai-model-provider/tool.gpt b/openai-model-provider/tool.gpt index 929c7511..7d441e7c 100644 --- a/openai-model-provider/tool.gpt +++ b/openai-model-provider/tool.gpt @@ -2,7 +2,7 @@ Name: OpenAI Description: Model Provider for OpenAI Metadata: envVars: OBOT_OPENAI_MODEL_PROVIDER_API_KEY Model Provider: true -Credential: ../model-provider-credential as openai-model-provider +Credential: ../placeholder-credential as openai-model-provider #!sys.daemon ${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool diff --git a/placeholder-credential/tool.gpt b/placeholder-credential/tool.gpt new file mode 100644 index 00000000..de2b47d2 --- /dev/null +++ b/placeholder-credential/tool.gpt @@ -0,0 +1,7 @@ +Name: Placeholder credential +Description: This is a fake credential tool for the model and auth providers. These credentials are handled in Obot and this tool should never be called. + +#!/bin/bash + +echo "The credential has not been properly configured" +exit 1 diff --git a/vllm-model-provider/tool.gpt b/vllm-model-provider/tool.gpt index 5f2f9fce..8e2e556c 100644 --- a/vllm-model-provider/tool.gpt +++ b/vllm-model-provider/tool.gpt @@ -2,7 +2,7 @@ Name: vLLM Description: Model Provider for vLLM Metadata: envVars: OBOT_VLLM_MODEL_PROVIDER_ENDPOINT,OBOT_VLLM_MODEL_PROVIDER_API_KEY Model Provider: true -Credential: ../model-provider-credential as vllm-model-provider +Credential: ../placeholder-credential as vllm-model-provider #!sys.daemon ${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool diff --git a/voyage-model-provider/tool.gpt b/voyage-model-provider/tool.gpt index 39150088..f51699f4 100644 --- a/voyage-model-provider/tool.gpt +++ b/voyage-model-provider/tool.gpt @@ -2,7 +2,7 @@ Name: Voyage Description: Model provider for Voyage Embeddings Metadata: envVars: OBOT_VOYAGE_MODEL_PROVIDER_API_KEY Model Provider: true -Credential: ../model-provider-credential as voyage-model-provider +Credential: ../placeholder-credential as voyage-model-provider #!sys.daemon /usr/bin/env python3 ${GPTSCRIPT_TOOL_DIR}/main.py diff --git a/xai-model-provider/tool.gpt b/xai-model-provider/tool.gpt index 0e32e965..3e0e5f72 100644 --- a/xai-model-provider/tool.gpt +++ b/xai-model-provider/tool.gpt @@ -2,7 +2,7 @@ Name: xAI Description: Model Provider for xAI Metadata: envVars: OBOT_XAI_MODEL_PROVIDER_API_KEY Model Provider: true -Credential: ../model-provider-credential as xai-model-provider +Credential: ../placeholder-credential as xai-model-provider #!sys.daemon ${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool