Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lint failure for openai binding #3000

Merged
merged 7 commits into from
Jul 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 5 additions & 19 deletions bindings/azure/openai/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/dapr/components-contrib/bindings"
azauth "github.com/dapr/components-contrib/internal/authentication/azure"
"github.com/dapr/components-contrib/metadata"
"github.com/dapr/kit/config"
"github.com/dapr/kit/logger"
)

Expand Down Expand Up @@ -64,15 +63,6 @@ type openAIMetadata struct {
Endpoint string `mapstructure:"endpoint"`
}

type ChatSettings struct {
Temperature float32 `mapstructure:"temperature"`
MaxTokens int32 `mapstructure:"maxTokens"`
TopP float32 `mapstructure:"topP"`
N int32 `mapstructure:"n"`
PresencePenalty float32 `mapstructure:"presencePenalty"`
FrequencyPenalty float32 `mapstructure:"frequencyPenalty"`
}

// ChatMessages type for chat completion API.
type ChatMessages struct {
Messages []Message `json:"messages"`
Expand Down Expand Up @@ -208,10 +198,6 @@ func (p *AzOpenAI) Invoke(ctx context.Context, req *bindings.InvokeRequest) (res
return resp, nil
}

func (s *ChatSettings) Decode(in any) error {
return config.Decode(in, s)
}

func (p *AzOpenAI) completion(ctx context.Context, message []byte, metadata map[string]string) (response []azopenai.Choice, err error) {
prompt := Prompt{
Temperature: 1.0,
Expand All @@ -231,7 +217,7 @@ func (p *AzOpenAI) completion(ctx context.Context, message []byte, metadata map[
}

resp, err := p.client.GetCompletions(ctx, azopenai.CompletionsOptions{
Prompt: []*string{&prompt.Prompt},
Prompt: []string{prompt.Prompt},
MaxTokens: &prompt.MaxTokens,
Temperature: &prompt.Temperature,
TopP: &prompt.TopP,
Expand All @@ -249,7 +235,7 @@ func (p *AzOpenAI) completion(ctx context.Context, message []byte, metadata map[
choices := resp.Completions.Choices
response = make([]azopenai.Choice, len(choices))
for i, c := range choices {
response[i] = *c
response[i] = c
}

return response, nil
Expand All @@ -272,9 +258,9 @@ func (p *AzOpenAI) chatCompletion(ctx context.Context, messageRequest []byte, me
return nil, fmt.Errorf("messages are required for chat-completion operation")
}

messageReq := make([]*azopenai.ChatMessage, len(messages.Messages))
messageReq := make([]azopenai.ChatMessage, len(messages.Messages))
for i, m := range messages.Messages {
messageReq[i] = &azopenai.ChatMessage{
messageReq[i] = azopenai.ChatMessage{
Role: to.Ptr(azopenai.ChatRole(m.Role)),
Content: to.Ptr(m.Message),
}
Expand Down Expand Up @@ -304,7 +290,7 @@ func (p *AzOpenAI) chatCompletion(ctx context.Context, messageRequest []byte, me
choices := res.ChatCompletions.Choices
response = make([]azopenai.ChatChoice, len(choices))
for i, c := range choices {
response[i] = *c
response[i] = c
}

return response, nil
Expand Down
Loading