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

Update azopenai API #793

Merged
merged 5 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ require (
)

require (
github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai v0.3.0
github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai v0.4.0
github.com/IBM/netaddr v1.5.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai v0.3.0 h1:x7fb22Q43h2DRFCvp9rAua8PoV3gwtl1bK5+pihnihA=
github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai v0.3.0/go.mod h1:zPJgGMjMheJJrYgrQ4W8NrNCWtWXAkjI3KWYFnTtwdA=
github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai v0.4.0 h1:3OEsdrBVDaV+b0KW+CuXjp3wGh/RBuQhTCMSpGa9SjE=
github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai v0.4.0/go.mod h1:VXAmay6g9K3DQcHfedhb8tvpTlsTtvAdkecDmJKH8+0=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1 h1:lGlwhPtrX6EVml1hO0ivjkUxsSyl4dsiw9qcA1k/3IQ=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1/go.mod h1:RKUqNu35KJYcVG/fqTRqmuXJZYNhYkBrnC/hX7yGbTA=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 h1:vcYCAze6p19qBW7MhZybIsqD8sMV8js0NyQM8JDnVtg=
Expand Down
43 changes: 18 additions & 25 deletions tools/release/gpt/gpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/edgenesis/shifu/pkg/logger"
"github.com/edgenesis/shifu/tools/release/prompts"
Expand All @@ -21,7 +22,7 @@ var (

type Helper struct {
client *azopenai.Client
messages []azopenai.ChatMessage
messages []azopenai.ChatRequestMessageClassification
}

func Start(releaseNoteResp string) error {
Expand All @@ -44,48 +45,40 @@ func Start(releaseNoteResp string) error {
}

func newGPT() (*azopenai.Client, error) {
ky, err := azopenai.NewKeyCredential(API_KEY)
if err != nil {
return nil, fmt.Errorf("error new key credential %s", err.Error())
}
keyCredential := azcore.NewKeyCredential(API_KEY)

client, err := azopenai.NewClientWithKeyCredential(HOST, ky, nil)
client, err := azopenai.NewClientWithKeyCredential(HOST, keyCredential, nil)
if err != nil {
return nil, fmt.Errorf("error new azure client %s", err.Error())
}
return client, nil
}

func (h *Helper) generateMessages(releaseNoteResp string) {
h.messages = []azopenai.ChatMessage{
{
Role: to.Ptr(azopenai.ChatRoleUser),
Content: to.Ptr(prompts.GreetingPrompts),
h.messages = []azopenai.ChatRequestMessageClassification{
&azopenai.ChatRequestUserMessage{
Content: azopenai.NewChatRequestUserMessageContent(prompts.GreetingPrompts),
},
{
Role: to.Ptr(azopenai.ChatRoleUser),
Content: to.Ptr(prompts.TemplateENPrompts),
&azopenai.ChatRequestUserMessage{
Content: azopenai.NewChatRequestUserMessageContent(prompts.TemplateENPrompts),
},
{
Role: to.Ptr(azopenai.ChatRoleUser),
Content: to.Ptr(prompts.TemplateZHPrompts),
&azopenai.ChatRequestUserMessage{
Content: azopenai.NewChatRequestUserMessageContent(prompts.TemplateZHPrompts),
},
{
Role: to.Ptr(azopenai.ChatRoleUser),
Content: to.Ptr(prompts.GeneratePrompts),
&azopenai.ChatRequestUserMessage{
Content: azopenai.NewChatRequestUserMessageContent(prompts.GeneratePrompts),
},
{
Role: to.Ptr(azopenai.ChatRoleUser),
Content: to.Ptr(releaseNoteResp),
&azopenai.ChatRequestUserMessage{
Content: azopenai.NewChatRequestUserMessageContent(releaseNoteResp),
},
}
}

func (h *Helper) generateChangelog() error {
resp, err := h.client.GetChatCompletions(context.Background(), azopenai.ChatCompletionsOptions{
Messages: h.messages,
Deployment: DEPLOYMENT_NAME,
Temperature: toPointer(float32(0)),
Messages: h.messages,
DeploymentName: to.Ptr(DEPLOYMENT_NAME),
Temperature: toPointer(float32(0)),
}, nil)
if err != nil {
return fmt.Errorf("error get chat completions %s", err.Error())
Expand Down
Loading