-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add generic-openai-model-provider (#378)
- Loading branch information
1 parent
d95edf2
commit 7ca907b
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module github.com/obot-platform/tools/generic-openai-model-provider | ||
|
||
go 1.23.4 | ||
|
||
replace github.com/obot-platform/tools/openai-model-provider => ../openai-model-provider | ||
|
||
require github.com/obot-platform/tools/openai-model-provider v0.0.0 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"os" | ||
"strings" | ||
|
||
"github.com/obot-platform/tools/openai-model-provider/proxy" | ||
) | ||
|
||
func main() { | ||
isValidate := len(os.Args) > 1 && os.Args[1] == "validate" | ||
|
||
baseURL := os.Getenv("OBOT_GENERIC_OPENAI_MODEL_PROVIDER_BASE_URL") | ||
if baseURL == "" { | ||
fmt.Fprintln(os.Stderr, "OBOT_GENERIC_OPENAI_MODEL_PROVIDER_BASE_URL environment variable not set") | ||
fmt.Printf("{ \"error\": \"BaseURL is required\" }\n") | ||
os.Exit(1) | ||
} | ||
|
||
u, err := url.Parse(strings.TrimRight(baseURL, "/")) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Invalid baseURL %q: %v\n", baseURL, err) | ||
fmt.Printf("{ \"error\": \"Invalid BaseURL: %v\" }\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
if u.Scheme == "" { | ||
if u.Hostname() == "localhost" || u.Hostname() == "127.0.0.1" { | ||
u.Scheme = "http" | ||
} else { | ||
u.Scheme = "https" | ||
} | ||
} | ||
|
||
cfg := &proxy.Config{ | ||
APIKey: os.Getenv("OBOT_GENERIC_OPENAI_MODEL_PROVIDER_API_KEY"), // optional, as e.g. Ollama doesn't require an API key | ||
ListenPort: os.Getenv("PORT"), | ||
BaseURL: u.String(), | ||
RewriteModelsFn: proxy.RewriteAllModelsWithUsage("llm"), | ||
Name: "Generic OpenAI", | ||
} | ||
|
||
if err := cfg.Validate("/tools/generic-openai-model-provider/validate"); err != nil { | ||
os.Exit(1) | ||
} | ||
|
||
if isValidate { | ||
return | ||
} | ||
|
||
if err := proxy.Run(cfg); err != nil { | ||
fmt.Printf("failed to run generic-openai-model-provider proxy: %v\n", err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Name: OpenAI Compatible Generic Provider | ||
Description: Model Provider for generic OpenAI API compatible model providers | ||
Metadata: envVars: OBOT_GENERIC_OPENAI_MODEL_PROVIDER_BASE_URL | ||
Metadata: optionalEnvVars: OBOT_GENERIC_OPENAI_MODEL_PROVIDER_API_KEY | ||
Model Provider: true | ||
Credential: ../placeholder-credential as generic-openai-model-provider with OBOT_GENERIC_OPENAI_MODEL_PROVIDER_BASE_URL;OBOT_GENERIC_OPENAI_MODEL_PROVIDER_API_KEY as env_vars | ||
Metadata: noUserAuth: generic-openai-model-provider | ||
|
||
#!sys.daemon ${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool | ||
|
||
--- | ||
!metadata:*:icon | ||
/admin/assets/obot_openai_antenna_icon.png | ||
|
||
--- | ||
Name: validate | ||
Description: Validate the generic OpenAI API configuration | ||
|
||
#!${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool validate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters