mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-08-09 03:37:23 +00:00
feat: add proxysettings for azureopenai and openai (#987)
Signed-off-by: tanujd11 <dwiveditanuj41@gmail.com> Co-authored-by: Aris Boutselis <arisboutselis08@gmail.com> Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
parent
aab8d77feb
commit
307710eddc
@ -73,6 +73,7 @@ var ServeCmd = &cobra.Command{
|
|||||||
model := os.Getenv("K8SGPT_MODEL")
|
model := os.Getenv("K8SGPT_MODEL")
|
||||||
baseURL := os.Getenv("K8SGPT_BASEURL")
|
baseURL := os.Getenv("K8SGPT_BASEURL")
|
||||||
engine := os.Getenv("K8SGPT_ENGINE")
|
engine := os.Getenv("K8SGPT_ENGINE")
|
||||||
|
proxyEndpoint := os.Getenv("K8SGPT_PROXY_ENDPOINT")
|
||||||
// If the envs are set, allocate in place to the aiProvider
|
// If the envs are set, allocate in place to the aiProvider
|
||||||
// else exit with error
|
// else exit with error
|
||||||
envIsSet := backend != "" || password != "" || model != ""
|
envIsSet := backend != "" || password != "" || model != ""
|
||||||
@ -83,6 +84,7 @@ var ServeCmd = &cobra.Command{
|
|||||||
Model: model,
|
Model: model,
|
||||||
BaseURL: baseURL,
|
BaseURL: baseURL,
|
||||||
Engine: engine,
|
Engine: engine,
|
||||||
|
ProxyEndpoint: proxyEndpoint,
|
||||||
Temperature: temperature(),
|
Temperature: temperature(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ package ai
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"github.com/sashabaranov/go-openai"
|
"github.com/sashabaranov/go-openai"
|
||||||
)
|
)
|
||||||
@ -21,6 +23,7 @@ func (c *AzureAIClient) Configure(config IAIConfig) error {
|
|||||||
token := config.GetPassword()
|
token := config.GetPassword()
|
||||||
baseURL := config.GetBaseURL()
|
baseURL := config.GetBaseURL()
|
||||||
engine := config.GetEngine()
|
engine := config.GetEngine()
|
||||||
|
proxyEndpoint := config.GetProxyEndpoint()
|
||||||
defaultConfig := openai.DefaultAzureConfig(token, baseURL)
|
defaultConfig := openai.DefaultAzureConfig(token, baseURL)
|
||||||
|
|
||||||
defaultConfig.AzureModelMapperFunc = func(model string) string {
|
defaultConfig.AzureModelMapperFunc = func(model string) string {
|
||||||
@ -31,6 +34,20 @@ func (c *AzureAIClient) Configure(config IAIConfig) error {
|
|||||||
return azureModelMapping[model]
|
return azureModelMapping[model]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if proxyEndpoint != "" {
|
||||||
|
proxyUrl, err := url.Parse(proxyEndpoint)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
transport := &http.Transport{
|
||||||
|
Proxy: http.ProxyURL(proxyUrl),
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultConfig.HTTPClient = &http.Client{
|
||||||
|
Transport: transport,
|
||||||
|
}
|
||||||
|
}
|
||||||
client := openai.NewClientWithConfig(defaultConfig)
|
client := openai.NewClientWithConfig(defaultConfig)
|
||||||
if client == nil {
|
if client == nil {
|
||||||
return errors.New("error creating Azure OpenAI client")
|
return errors.New("error creating Azure OpenAI client")
|
||||||
|
@ -64,6 +64,7 @@ type IAIConfig interface {
|
|||||||
GetPassword() string
|
GetPassword() string
|
||||||
GetModel() string
|
GetModel() string
|
||||||
GetBaseURL() string
|
GetBaseURL() string
|
||||||
|
GetProxyEndpoint() string
|
||||||
GetEndpointName() string
|
GetEndpointName() string
|
||||||
GetEngine() string
|
GetEngine() string
|
||||||
GetTemperature() float32
|
GetTemperature() float32
|
||||||
@ -92,6 +93,8 @@ type AIProvider struct {
|
|||||||
Model string `mapstructure:"model"`
|
Model string `mapstructure:"model"`
|
||||||
Password string `mapstructure:"password" yaml:"password,omitempty"`
|
Password string `mapstructure:"password" yaml:"password,omitempty"`
|
||||||
BaseURL string `mapstructure:"baseurl" yaml:"baseurl,omitempty"`
|
BaseURL string `mapstructure:"baseurl" yaml:"baseurl,omitempty"`
|
||||||
|
ProxyEndpoint string `mapstructure:"proxyEndpoint" yaml:"proxyEndpoint,omitempty"`
|
||||||
|
ProxyPort string `mapstructure:"proxyPort" yaml:"proxyPort,omitempty"`
|
||||||
EndpointName string `mapstructure:"endpointname" yaml:"endpointname,omitempty"`
|
EndpointName string `mapstructure:"endpointname" yaml:"endpointname,omitempty"`
|
||||||
Engine string `mapstructure:"engine" yaml:"engine,omitempty"`
|
Engine string `mapstructure:"engine" yaml:"engine,omitempty"`
|
||||||
Temperature float32 `mapstructure:"temperature" yaml:"temperature,omitempty"`
|
Temperature float32 `mapstructure:"temperature" yaml:"temperature,omitempty"`
|
||||||
@ -104,6 +107,10 @@ func (p *AIProvider) GetBaseURL() string {
|
|||||||
return p.BaseURL
|
return p.BaseURL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *AIProvider) GetProxyEndpoint() string {
|
||||||
|
return p.ProxyEndpoint
|
||||||
|
}
|
||||||
|
|
||||||
func (p *AIProvider) GetEndpointName() string {
|
func (p *AIProvider) GetEndpointName() string {
|
||||||
return p.EndpointName
|
return p.EndpointName
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@ package ai
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"github.com/sashabaranov/go-openai"
|
"github.com/sashabaranov/go-openai"
|
||||||
)
|
)
|
||||||
@ -41,12 +43,27 @@ const (
|
|||||||
func (c *OpenAIClient) Configure(config IAIConfig) error {
|
func (c *OpenAIClient) Configure(config IAIConfig) error {
|
||||||
token := config.GetPassword()
|
token := config.GetPassword()
|
||||||
defaultConfig := openai.DefaultConfig(token)
|
defaultConfig := openai.DefaultConfig(token)
|
||||||
|
proxyEndpoint := config.GetProxyEndpoint()
|
||||||
|
|
||||||
baseURL := config.GetBaseURL()
|
baseURL := config.GetBaseURL()
|
||||||
if baseURL != "" {
|
if baseURL != "" {
|
||||||
defaultConfig.BaseURL = baseURL
|
defaultConfig.BaseURL = baseURL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if proxyEndpoint != "" {
|
||||||
|
proxyUrl, err := url.Parse(proxyEndpoint)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
transport := &http.Transport{
|
||||||
|
Proxy: http.ProxyURL(proxyUrl),
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultConfig.HTTPClient = &http.Client{
|
||||||
|
Transport: transport,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
client := openai.NewClientWithConfig(defaultConfig)
|
client := openai.NewClientWithConfig(defaultConfig)
|
||||||
if client == nil {
|
if client == nil {
|
||||||
return errors.New("error creating OpenAI client")
|
return errors.New("error creating OpenAI client")
|
||||||
|
Loading…
Reference in New Issue
Block a user