Skip to content

Commit 7a8024e

Browse files
authored
Merge pull request #1540 from ksylvan/0623-langdock-ai
Add Langdock AI and enhance generic OpenAI compatible support
2 parents a2c954b + b5bf75a commit 7a8024e

File tree

1 file changed

+52
-19
lines changed

1 file changed

+52
-19
lines changed

plugins/ai/openai_compatible/providers_config.go

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package openai_compatible
22

33
import (
4+
"os"
5+
"strings"
6+
47
"github.com/danielmiessler/fabric/plugins/ai/openai"
58
)
69

@@ -24,29 +27,37 @@ func NewClient(providerConfig ProviderConfig) *Client {
2427

2528
// ProviderMap is a map of provider name to ProviderConfig for O(1) lookup
2629
var ProviderMap = map[string]ProviderConfig{
27-
"Mistral": {
28-
Name: "Mistral",
29-
BaseURL: "https://api.mistral.ai/v1",
30+
"AIML": {
31+
Name: "AIML",
32+
BaseURL: "https://api.aimlapi.com/v1",
3033
},
31-
"LiteLLM": {
32-
Name: "LiteLLM",
33-
BaseURL: "http://localhost:4000",
34+
"Cerebras": {
35+
Name: "Cerebras",
36+
BaseURL: "https://api.cerebras.ai/v1",
3437
},
35-
"Groq": {
36-
Name: "Groq",
37-
BaseURL: "https://api.groq.com/openai/v1",
38+
"DeepSeek": {
39+
Name: "DeepSeek",
40+
BaseURL: "https://api.deepseek.com",
3841
},
3942
"GrokAI": {
4043
Name: "GrokAI",
4144
BaseURL: "https://api.x.ai/v1",
4245
},
43-
"DeepSeek": {
44-
Name: "DeepSeek",
45-
BaseURL: "https://api.deepseek.com",
46+
"Groq": {
47+
Name: "Groq",
48+
BaseURL: "https://api.groq.com/openai/v1",
4649
},
47-
"Cerebras": {
48-
Name: "Cerebras",
49-
BaseURL: "https://api.cerebras.ai/v1",
50+
"Langdock": {
51+
Name: "Langdock",
52+
BaseURL: "https://api.langdock.com/openai/{{REGION=us}}/v1",
53+
},
54+
"LiteLLM": {
55+
Name: "LiteLLM",
56+
BaseURL: "http://localhost:4000",
57+
},
58+
"Mistral": {
59+
Name: "Mistral",
60+
BaseURL: "https://api.mistral.ai/v1",
5061
},
5162
"OpenRouter": {
5263
Name: "OpenRouter",
@@ -56,15 +67,37 @@ var ProviderMap = map[string]ProviderConfig{
5667
Name: "SiliconCloud",
5768
BaseURL: "https://api.siliconflow.cn/v1",
5869
},
59-
"AIML": {
60-
Name: "AIML",
61-
BaseURL: "https://api.aimlapi.com/v1",
62-
},
6370
}
6471

6572
// GetProviderByName returns the provider configuration for a given name with O(1) lookup
6673
func GetProviderByName(name string) (ProviderConfig, bool) {
6774
provider, found := ProviderMap[name]
75+
if strings.Contains(provider.BaseURL, "{{") && strings.Contains(provider.BaseURL, "}}") {
76+
// Extract the template variable and default value
77+
start := strings.Index(provider.BaseURL, "{{")
78+
end := strings.Index(provider.BaseURL, "}}") + 2
79+
template := provider.BaseURL[start:end]
80+
81+
// Parse the template to get variable name and default value
82+
inner := template[2 : len(template)-2] // Remove {{ and }}
83+
parts := strings.Split(inner, "=")
84+
if len(parts) == 2 {
85+
varName := strings.TrimSpace(parts[0])
86+
defaultValue := strings.TrimSpace(parts[1])
87+
88+
// Create environment variable name
89+
envVarName := strings.ToUpper(provider.Name) + "_" + varName
90+
91+
// Get value from environment or use default
92+
envValue := os.Getenv(envVarName)
93+
if envValue == "" {
94+
envValue = defaultValue
95+
}
96+
97+
// Replace the template with the actual value
98+
provider.BaseURL = strings.Replace(provider.BaseURL, template, envValue, 1)
99+
}
100+
}
68101
return provider, found
69102
}
70103

0 commit comments

Comments
 (0)