-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #3: Update dependencies, fix package names, add validators * #3: Remove unused fields in ProviderConfig struct * #3: Update OpenAI provider configuration validation * #3: Refactor OpenAI provider config structure * #3: Update go.mod and go.sum files * #3: add comments * #3: Refactor package name in OpenAI API and chat files * #3: build OpenAI config * #3: Build API Request * #3: Refactor param checking in BuildAPIRequest function * #3: build request based on client parameters --------- Co-authored-by: Max <[email protected]>
- Loading branch information
1 parent
27f7118
commit bd1d4d3
Showing
7 changed files
with
78 additions
and
39 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
module glide | ||
|
||
go 1.21.5 | ||
|
||
require ( | ||
github.com/cloudwego/hertz v0.7.3 | ||
github.com/spf13/cobra v1.8.0 | ||
|
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,44 @@ | ||
package pkg | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
type ProviderConfigs map[string]interface{} // TODO: import from types.go | ||
|
||
func BuildAPIRequest(provider string, params map[string]string, mode string, configList map[string]interface{}) (interface{}, error) { | ||
// provider is the name of the provider, e.g. "openai", params is the map of parameters from the client, | ||
// mode is the mode of the provider, e.g. "chat", configList is the list of provider configurations | ||
|
||
|
||
var providerConfig map[string]interface{} | ||
if config, ok := configList[provider].(ProviderConfigs); ok { | ||
if modeConfig, ok := config[mode].(map[string]interface{}); ok { | ||
providerConfig = modeConfig | ||
} | ||
} | ||
|
||
// If the provider is not supported, return an error | ||
if providerConfig == nil { | ||
return nil, errors.New("unsupported provider") | ||
} | ||
|
||
|
||
// TODO: Next need to build the request based on the params from the client | ||
// First for each param in param check if present. If yes then add it to the request. | ||
// If not & the param is required, return a default value from the provider config | ||
|
||
for key := range providerConfig { | ||
if value, exists := params[key]; exists { | ||
providerConfig[key] = value | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
// For now, return providerConfig and nil error to satisfy the function signature | ||
return providerConfig, nil | ||
|
||
|
||
} |
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
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
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,8 @@ | ||
package pkg | ||
|
||
type ProviderConfigs map[string]interface{} // TODO: import from types.go | ||
|
||
var OpenAIConfig = ProviderConfigs{ | ||
"api": OpenAIAPIConfig, | ||
"chat": OpenAiChatDefaultConfig, | ||
} |
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,3 @@ | ||
package pkg | ||
|
||
type ProviderConfigs map[string]interface{} |