1
1
package openai_compatible
2
2
3
3
import (
4
+ "os"
5
+ "strings"
6
+
4
7
"github.com/danielmiessler/fabric/plugins/ai/openai"
5
8
)
6
9
@@ -24,29 +27,37 @@ func NewClient(providerConfig ProviderConfig) *Client {
24
27
25
28
// ProviderMap is a map of provider name to ProviderConfig for O(1) lookup
26
29
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" ,
30
33
},
31
- "LiteLLM " : {
32
- Name : "LiteLLM " ,
33
- BaseURL : "http ://localhost:4000 " ,
34
+ "Cerebras " : {
35
+ Name : "Cerebras " ,
36
+ BaseURL : "https ://api.cerebras.ai/v1 " ,
34
37
},
35
- "Groq " : {
36
- Name : "Groq " ,
37
- BaseURL : "https://api.groq .com/openai/v1 " ,
38
+ "DeepSeek " : {
39
+ Name : "DeepSeek " ,
40
+ BaseURL : "https://api.deepseek .com" ,
38
41
},
39
42
"GrokAI" : {
40
43
Name : "GrokAI" ,
41
44
BaseURL : "https://api.x.ai/v1" ,
42
45
},
43
- "DeepSeek " : {
44
- Name : "DeepSeek " ,
45
- BaseURL : "https://api.deepseek .com" ,
46
+ "Groq " : {
47
+ Name : "Groq " ,
48
+ BaseURL : "https://api.groq .com/openai/v1 " ,
46
49
},
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" ,
50
61
},
51
62
"OpenRouter" : {
52
63
Name : "OpenRouter" ,
@@ -56,15 +67,37 @@ var ProviderMap = map[string]ProviderConfig{
56
67
Name : "SiliconCloud" ,
57
68
BaseURL : "https://api.siliconflow.cn/v1" ,
58
69
},
59
- "AIML" : {
60
- Name : "AIML" ,
61
- BaseURL : "https://api.aimlapi.com/v1" ,
62
- },
63
70
}
64
71
65
72
// GetProviderByName returns the provider configuration for a given name with O(1) lookup
66
73
func GetProviderByName (name string ) (ProviderConfig , bool ) {
67
74
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
+ }
68
101
return provider , found
69
102
}
70
103
0 commit comments