yao/kb/types/provider.go
Max 7fa825a334 Remove obsolete configuration and test files for Knowledge Base
- Deleted config.go, config_test.go, types.go, and related test files to streamline the codebase and remove deprecated components.
- Refactored Knowledge Base loading logic to utilize updated configuration structures, enhancing clarity and maintainability.
- Updated references in kb.go to align with the new configuration types, ensuring compatibility with the latest changes.
2025-07-25 11:36:15 +08:00

43 lines
811 B
Go

package types
import jsoniter "github.com/json-iterator/go"
// GetOption returns the option for a provider
func (p *Provider) GetOption(id string) (*ProviderOption, bool) {
if p.Options == nil {
return nil, false
}
// Find the option by id
for _, option := range p.Options {
if option.Value == id {
return option, true
}
}
return nil, false
}
// GetOptionByIndex returns the option by index
func (p *Provider) GetOptionByIndex(index int) (*ProviderOption, bool) {
if len(p.Options) <= index {
return nil, false
}
return p.Options[index], true
}
// Parse parses the provider option
func (p *ProviderOption) Parse(v interface{}) error {
raw, err := jsoniter.Marshal(p)
if err != nil {
return err
}
err = jsoniter.Unmarshal(raw, v)
if err != nil {
return err
}
return nil
}