Change document version
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
41
pkg/agents/agents.go
Normal file
41
pkg/agents/agents.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package agents
|
||||
|
||||
import (
|
||||
"github.com/openai/openai-go"
|
||||
"github.com/openai/openai-go/option"
|
||||
"go.gearno.de/kit/log"
|
||||
)
|
||||
|
||||
type (
|
||||
Agent struct {
|
||||
l *log.Logger
|
||||
cfg Config
|
||||
client *openai.Client
|
||||
}
|
||||
|
||||
Config struct {
|
||||
OpenAIAPIKey string
|
||||
Temperature float64
|
||||
ModelName string
|
||||
}
|
||||
)
|
||||
|
||||
func NewAgent(l *log.Logger, cfg Config) *Agent {
|
||||
client := openai.NewClient(option.WithAPIKey(cfg.OpenAIAPIKey))
|
||||
|
||||
return &Agent{l: l, cfg: cfg, client: &client}
|
||||
}
|
||||
70
pkg/agents/changelog_generator.go
Normal file
70
pkg/agents/changelog_generator.go
Normal file
@@ -0,0 +1,70 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package agents
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/openai/openai-go"
|
||||
"github.com/openai/openai-go/packages/param"
|
||||
)
|
||||
|
||||
const (
|
||||
changelogGeneratorSystemPrompt = `
|
||||
# Role:You are an assistant that creates clear and concise changelogs.
|
||||
|
||||
# Objective
|
||||
Given two versions of a document — the "old version" and the "new version" — identify and summarize all meaningful changes between them.
|
||||
Focus on additions, deletions, modifications, and restructuring.
|
||||
|
||||
# Response Format
|
||||
Respond with simple and short phrases that describe the changes, if possible use a single phrase.
|
||||
|
||||
# Change types
|
||||
Change types can include: "Added", "Removed", "Updated", "Reworded", "Reorganized", "Fixed", etc.
|
||||
|
||||
# SOP
|
||||
- Be objective and neutral in tone.
|
||||
- Do not comment on the quality of the change.
|
||||
- Use the language of the document.
|
||||
|
||||
**Example output format:**
|
||||
Respond ONLY with the phrase that describes the changes. No explanation, no markdown, no preamble. Like this:
|
||||
Added Clause about sharing personal information with trusted partners
|
||||
`
|
||||
)
|
||||
|
||||
func (a *Agent) GenerateChangelog(ctx context.Context, oldContent string, newContent string) (*string, error) {
|
||||
model := openai.ChatModel(a.cfg.ModelName)
|
||||
chatCompletion, err := a.client.Chat.Completions.New(ctx, openai.ChatCompletionNewParams{
|
||||
Messages: []openai.ChatCompletionMessageParamUnion{
|
||||
openai.SystemMessage(changelogGeneratorSystemPrompt),
|
||||
openai.UserMessage(fmt.Sprintf(`Old content: %s`, oldContent)),
|
||||
openai.UserMessage(fmt.Sprintf(`New content: %s`, newContent)),
|
||||
},
|
||||
Model: model,
|
||||
Temperature: param.NewOpt(a.cfg.Temperature),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse vendor info: %w", err)
|
||||
}
|
||||
|
||||
if len(chatCompletion.Choices) == 0 {
|
||||
return nil, fmt.Errorf("no completion choices returned from API")
|
||||
}
|
||||
|
||||
return &chatCompletion.Choices[0].Message.Content, nil
|
||||
}
|
||||
@@ -20,24 +20,10 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/openai/openai-go"
|
||||
"github.com/openai/openai-go/option"
|
||||
"github.com/openai/openai-go/packages/param"
|
||||
"go.gearno.de/kit/log"
|
||||
)
|
||||
|
||||
type (
|
||||
VendorAssessment struct {
|
||||
l *log.Logger
|
||||
cfg Config
|
||||
client *openai.Client
|
||||
}
|
||||
|
||||
Config struct {
|
||||
OpenAIAPIKey string
|
||||
Temperature float64
|
||||
ModelName string
|
||||
}
|
||||
|
||||
vendorInfo struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
@@ -58,7 +44,7 @@ type (
|
||||
)
|
||||
|
||||
const (
|
||||
systemPrompt = `
|
||||
assessVendorSystemPrompt = `
|
||||
# Role: You are a compliance assistant.
|
||||
|
||||
# Objective
|
||||
@@ -136,21 +122,15 @@ const (
|
||||
`
|
||||
)
|
||||
|
||||
func NewVendorAssessment(l *log.Logger, cfg Config) *VendorAssessment {
|
||||
client := openai.NewClient(option.WithAPIKey(cfg.OpenAIAPIKey))
|
||||
|
||||
return &VendorAssessment{l: l, cfg: cfg, client: &client}
|
||||
}
|
||||
|
||||
func (va *VendorAssessment) Fetch(ctx context.Context, websiteURL string) (*vendorInfo, error) {
|
||||
model := openai.ChatModel(va.cfg.ModelName)
|
||||
chatCompletion, err := va.client.Chat.Completions.New(ctx, openai.ChatCompletionNewParams{
|
||||
func (a *Agent) AssessVendor(ctx context.Context, websiteURL string) (*vendorInfo, error) {
|
||||
model := openai.ChatModel(a.cfg.ModelName)
|
||||
chatCompletion, err := a.client.Chat.Completions.New(ctx, openai.ChatCompletionNewParams{
|
||||
Messages: []openai.ChatCompletionMessageParamUnion{
|
||||
openai.SystemMessage(systemPrompt),
|
||||
openai.SystemMessage(assessVendorSystemPrompt),
|
||||
openai.UserMessage(websiteURL),
|
||||
},
|
||||
Model: model,
|
||||
Temperature: param.NewOpt(va.cfg.Temperature),
|
||||
Temperature: param.NewOpt(a.cfg.Temperature),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse vendor info: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user