Skip to content

Commit

Permalink
feat: add orgId on openai backend
Browse files Browse the repository at this point in the history
Signed-off-by: JuHyung-Son <[email protected]>
  • Loading branch information
JuHyung-Son committed Jun 6, 2024
1 parent 2792e81 commit 89162f4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
12 changes: 9 additions & 3 deletions pkg/ai/azureopenai.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ const azureAIClientName = "azureopenai"
type AzureAIClient struct {
nopCloser

client *openai.Client
model string
temperature float32
client *openai.Client
model string
temperature float32
organizationId string

Check failure on line 20 in pkg/ai/azureopenai.go

View workflow job for this annotation

GitHub Actions / golangci-lint

[golangci] reported by reviewdog 🐶 field `organizationId` is unused (unused) Raw Output: pkg/ai/azureopenai.go:20:2: field `organizationId` is unused (unused) organizationId string ^
}

func (c *AzureAIClient) Configure(config IAIConfig) error {
Expand All @@ -25,6 +26,7 @@ func (c *AzureAIClient) Configure(config IAIConfig) error {
engine := config.GetEngine()
proxyEndpoint := config.GetProxyEndpoint()
defaultConfig := openai.DefaultAzureConfig(token, baseURL)
orgId := config.GetOrganizationId()

defaultConfig.AzureModelMapperFunc = func(model string) string {
// If you use a deployment name different from the model name, you can customize the AzureModelMapperFunc function
Expand All @@ -48,6 +50,10 @@ func (c *AzureAIClient) Configure(config IAIConfig) error {
Transport: transport,
}
}
if orgId != "" {
defaultConfig.OrgID = orgId
}

client := openai.NewClientWithConfig(defaultConfig)
if client == nil {
return errors.New("error creating Azure OpenAI client")
Expand Down
6 changes: 6 additions & 0 deletions pkg/ai/iai.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type IAIConfig interface {
GetMaxTokens() int
GetProviderId() string
GetCompartmentId() string
GetOrganizationId() string
}

func NewClient(provider string) IAI {
Expand Down Expand Up @@ -111,6 +112,7 @@ type AIProvider struct {
TopP float32 `mapstructure:"topp" yaml:"topp,omitempty"`
TopK int32 `mapstructure:"topk" yaml:"topk,omitempty"`
MaxTokens int `mapstructure:"maxtokens" yaml:"maxtokens,omitempty"`
OrganizationId string `mapstructure:"organizationid" yaml:"organizationid,omitempty"`
}

func (p *AIProvider) GetBaseURL() string {
Expand Down Expand Up @@ -164,6 +166,10 @@ func (p *AIProvider) GetCompartmentId() string {
return p.CompartmentId
}

func (p *AIProvider) GetOrganizationId() string {
return p.OrganizationId
}

var passwordlessProviders = []string{"localai", "amazonsagemaker", "amazonbedrock", "googlevertexai", "oci"}

func NeedPassword(backend string) bool {
Expand Down
14 changes: 10 additions & 4 deletions pkg/ai/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ const openAIClientName = "openai"
type OpenAIClient struct {
nopCloser

client *openai.Client
model string
temperature float32
topP float32
client *openai.Client
model string
temperature float32
topP float32
organizationId string

Check failure on line 34 in pkg/ai/openai.go

View workflow job for this annotation

GitHub Actions / golangci-lint

[golangci] reported by reviewdog 🐶 field `organizationId` is unused (unused) Raw Output: pkg/ai/openai.go:34:2: field `organizationId` is unused (unused) organizationId string ^
}

const (
Expand All @@ -43,6 +44,7 @@ const (
func (c *OpenAIClient) Configure(config IAIConfig) error {
token := config.GetPassword()
defaultConfig := openai.DefaultConfig(token)
orgId := config.GetOrganizationId()
proxyEndpoint := config.GetProxyEndpoint()

baseURL := config.GetBaseURL()
Expand All @@ -64,6 +66,10 @@ func (c *OpenAIClient) Configure(config IAIConfig) error {
}
}

if orgId != "" {
defaultConfig.OrgID = orgId
}

client := openai.NewClientWithConfig(defaultConfig)
if client == nil {
return errors.New("error creating OpenAI client")
Expand Down

0 comments on commit 89162f4

Please sign in to comment.