From 979aa66b17c1ae86aecc9934c77c00ec0eba56f8 Mon Sep 17 00:00:00 2001 From: Olivier Tremblay Date: Fri, 14 Nov 2025 11:22:21 -0500 Subject: [PATCH 01/10] fix: always call SummarizeData to ensure prompt file is created for debugging, but only call OpenAI endpoint if env vars are set Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) --- cmd/acb/main.go | 15 ++++++++------- cmd/acb/summarize.go | 14 +++++++++----- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cmd/acb/main.go b/cmd/acb/main.go index db5a0d7..ae397b3 100644 --- a/cmd/acb/main.go +++ b/cmd/acb/main.go @@ -72,18 +72,19 @@ func main() { openaiToken := os.Getenv("OPENAI_TOKEN") openaiModel := os.Getenv("OPENAI_MODEL") - // Check if OpenAI environment variables are set before calling Summarize - if openaiEndpoint == "" || openaiToken == "" { - fmt.Println("Error: OPENAI_ENDPOINT and OPENAI_TOKEN must be set in environment variables to summarize") - os.Exit(1) - } - + // Always call SummarizeData to ensure prompt file is created for debugging summ, err := SummarizeData(*employeename, prs, issues, vikunjaTasks, finalPrompt, openaiEndpoint, openaiToken, openaiModel) if err != nil { fmt.Println(fmt.Errorf("error getting PRs: %w", err)) os.Exit(1) } - fmt.Println(summ) + + // Only call summarization endpoint if OpenAI env vars are set + if openaiEndpoint != "" && openaiToken != "" { + fmt.Println(summ) + } else { + fmt.Println("OpenAI endpoint and token not set, but prompt file was created for debugging") + } } func DoPrs(proj, ghusername, start, end string) map[string][]contributions.PullRequest { diff --git a/cmd/acb/summarize.go b/cmd/acb/summarize.go index 7177df3..c5cf9aa 100644 --- a/cmd/acb/summarize.go +++ b/cmd/acb/summarize.go @@ -100,11 +100,15 @@ func SummarizeData(employeename string, prs map[string][]contributions.PullReque // Build the prompt fullPrompt := buildPrompt(employeename, prs, issues, tasks, prompt) - // Call the summarization endpoint - result, err := callSummarizationEndpoint(fullPrompt, openaiEndpoint, openaiToken, openaiModel) - if err != nil { - return "", err + // Call the summarization endpoint only if OpenAI env vars are set + if openaiEndpoint != "" && openaiToken != "" { + result, err := callSummarizationEndpoint(fullPrompt, openaiEndpoint, openaiToken, openaiModel) + if err != nil { + return "", err + } + return result, nil } - return result, nil + // Return just the prompt if OpenAI env vars are not set + return fullPrompt, nil } From feb06e51ffc9fe9b59889b638e01f7b818209b87 Mon Sep 17 00:00:00 2001 From: Olivier Tremblay Date: Sun, 16 Nov 2025 14:13:20 -0500 Subject: [PATCH 02/10] refactor: extract callSummarizationEndpoint into Summarizer interface for multiple implementations Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) --- cmd/acb/summarize.go | 72 ++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/cmd/acb/summarize.go b/cmd/acb/summarize.go index c5cf9aa..78ee2b4 100644 --- a/cmd/acb/summarize.go +++ b/cmd/acb/summarize.go @@ -19,38 +19,16 @@ const defaultPrompt = `I will provide you, for a given period, with an employee I'd like you to summarize the employee's accomplishments for the quarter I'd like the summary for the accomplishments to be in prose form, in a few paragraphs separated based on areas of work. Keep answers to 500 words for the summary.` -// buildPrompt constructs the prompt string from PRs, issues, and tasks -func buildPrompt(employeename string, prs map[string][]contributions.PullRequest, issues []issues.Issue, tasks []vikunja.Task, prompt string) string { - // Build a prompt string - fullPrompt := prompt + fmt.Sprintf("\n\nHere's the PRs and Tickets for the employee %s:\n\n", employeename) - for repo, prList := range prs { - fullPrompt += fmt.Sprintf("Repository: %s\n", repo) - for _, pr := range prList { - fullPrompt += fmt.Sprintf("- Title: %s\n", pr.Title) - fullPrompt += fmt.Sprintf(" Body: %s\n", pr.Body) - } - } - fullPrompt += "Issues:\n" - for _, issue := range issues { - fullPrompt += fmt.Sprintf("Summary: %s\n", issue.Summary) - fullPrompt += fmt.Sprintf("Description: %s\n", issue.Description) - fullPrompt += "--------\n" - } - - // Save prompt to file for debugging - promptf, err := os.Create(fmt.Sprintf("prompt-%s-%d.json", employeename, time.Now().Unix())) - if err != nil { - fmt.Println(fmt.Errorf("error creating PR file: %w", err)) - os.Exit(1) - } - promptf.WriteString(fullPrompt) - defer promptf.Close() - - return fullPrompt +// Summarizer interface defines the contract for summarization implementations +type Summarizer interface { + Summarize(prompt string, endpoint string, token string, model string) (string, error) } -// callSummarizationEndpoint sends the prompt to an OpenAI-compatible endpoint for summarization -func callSummarizationEndpoint(fullPrompt string, openaiEndpoint string, openaiToken string, openaiModel string) (string, error) { +// OpenAISummarizer implements the Summarizer interface for OpenAI-compatible endpoints +type OpenAISummarizer struct{} + +// Summarize sends the prompt to an OpenAI-compatible endpoint for summarization +func (o *OpenAISummarizer) Summarize(fullPrompt string, openaiEndpoint string, openaiToken string, openaiModel string) (string, error) { // Create a JSON payload for the OpenAI API payload := struct { Model string `json:"model"` @@ -95,14 +73,44 @@ func callSummarizationEndpoint(fullPrompt string, openaiEndpoint string, openaiT return string(body), nil } +// buildPrompt constructs the prompt string from PRs, issues, and tasks +func buildPrompt(employeename string, prs map[string][]contributions.PullRequest, issues []issues.Issue, tasks []vikunja.Task, prompt string) string { + // Build a prompt string + fullPrompt := prompt + fmt.Sprintf("\n\nHere's the PRs and Tickets for the employee %s:\n\n", employeename) + for repo, prList := range prs { + fullPrompt += fmt.Sprintf("Repository: %s\n", repo) + for _, pr := range prList { + fullPrompt += fmt.Sprintf("- Title: %s\n", pr.Title) + fullPrompt += fmt.Sprintf(" Body: %s\n", pr.Body) + } + } + fullPrompt += "Issues:\n" + for _, issue := range issues { + fullPrompt += fmt.Sprintf("Summary: %s\n", issue.Summary) + fullPrompt += fmt.Sprintf("Description: %s\n", issue.Description) + fullPrompt += "--------\n" + } + + // Save prompt to file for debugging + promptf, err := os.Create(fmt.Sprintf("prompt-%s-%d.json", employeename, time.Now().Unix())) + if err != nil { + fmt.Println(fmt.Errorf("error creating PR file: %w", err)) + os.Exit(1) + } + promptf.WriteString(fullPrompt) + defer promptf.Close() + + return fullPrompt +} + // SummarizeData builds the prompt and calls the summarization endpoint -func SummarizeData(employeename string, prs map[string][]contributions.PullRequest, issues []issues.Issue, tasks []vikunja.Task, prompt string, openaiEndpoint string, openaiToken string, openaiModel string) (string, error) { +func SummarizeData(employeename string, prs map[string][]contributions.PullRequest, issues []issues.Issue, tasks []vikunja.Task, prompt string, openaiEndpoint string, openaiToken string, openaiModel string, summarizer Summarizer) (string, error) { // Build the prompt fullPrompt := buildPrompt(employeename, prs, issues, tasks, prompt) // Call the summarization endpoint only if OpenAI env vars are set if openaiEndpoint != "" && openaiToken != "" { - result, err := callSummarizationEndpoint(fullPrompt, openaiEndpoint, openaiToken, openaiModel) + result, err := summarizer.Summarize(fullPrompt, openaiEndpoint, openaiToken, openaiModel) if err != nil { return "", err } From d239689ef4c65f90ababd288801919e95c59ae2f Mon Sep 17 00:00:00 2001 From: Olivier Tremblay Date: Sun, 16 Nov 2025 14:21:00 -0500 Subject: [PATCH 03/10] refactor: move OpenAI variable checks into OpenAISummarizer's Summarize method and always call the summarizer's method Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) --- cmd/acb/summarize.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cmd/acb/summarize.go b/cmd/acb/summarize.go index 78ee2b4..915e87d 100644 --- a/cmd/acb/summarize.go +++ b/cmd/acb/summarize.go @@ -29,6 +29,11 @@ type OpenAISummarizer struct{} // Summarize sends the prompt to an OpenAI-compatible endpoint for summarization func (o *OpenAISummarizer) Summarize(fullPrompt string, openaiEndpoint string, openaiToken string, openaiModel string) (string, error) { + // Check if required environment variables are set + if openaiEndpoint == "" || openaiToken == "" { + return "", fmt.Errorf("OpenAI endpoint or token not set") + } + // Create a JSON payload for the OpenAI API payload := struct { Model string `json:"model"` @@ -108,15 +113,11 @@ func SummarizeData(employeename string, prs map[string][]contributions.PullReque // Build the prompt fullPrompt := buildPrompt(employeename, prs, issues, tasks, prompt) - // Call the summarization endpoint only if OpenAI env vars are set - if openaiEndpoint != "" && openaiToken != "" { - result, err := summarizer.Summarize(fullPrompt, openaiEndpoint, openaiToken, openaiModel) - if err != nil { - return "", err - } - return result, nil + // Always call the summarizer's Summarize method + result, err := summarizer.Summarize(fullPrompt, openaiEndpoint, openaiToken, openaiModel) + if err != nil { + return "", err } - // Return just the prompt if OpenAI env vars are not set - return fullPrompt, nil + return result, nil } From 214cdcd2b2fb0140295d12af65c5cb077faad11f Mon Sep 17 00:00:00 2001 From: Olivier Tremblay Date: Sun, 16 Nov 2025 16:21:09 -0500 Subject: [PATCH 04/10] feat: implement Ollama Summarizer using official SDK as per article example Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) --- cmd/acb/summarize.go | 78 ++++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 25 deletions(-) diff --git a/cmd/acb/summarize.go b/cmd/acb/summarize.go index 915e87d..ad41c9f 100644 --- a/cmd/acb/summarize.go +++ b/cmd/acb/summarize.go @@ -1,17 +1,16 @@ package main import ( - "bytes" - "encoding/json" + "context" "fmt" - "io" - "net/http" "os" "time" "o5r.ca/autocrossbow/contributions" "o5r.ca/autocrossbow/issues" "o5r.ca/autocrossbow/issues/vikunja" + + "github.com/ollama/ollama/api" ) const defaultPrompt = `I will provide you, for a given period, with an employee name and a list of Pull Request titles and summaries split by repository, and a list of Jira Issues an employee has worked on. I may also provide, optionally, the employee's self-assessment. If I do, integrate that. @@ -49,33 +48,62 @@ func (o *OpenAISummarizer) Summarize(fullPrompt string, openaiEndpoint string, o }{{Role: "system", Content: fullPrompt}}, } - jsonPayload, err := json.Marshal(payload) - fmt.Println(string(jsonPayload)) - if err != nil { - return "", err - } - // Create a POST request to the OpenAI endpoint with JSON body - req, err := http.NewRequest("POST", openaiEndpoint, bytes.NewBuffer(jsonPayload)) - if err != nil { - return "", err + req, err := api.GenerateRequest{ + Model: openaiModel, + Prompt: fullPrompt, + Stream: nil, } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", openaiToken)) - - client := &http.Client{} - resp, err := client.Do(req) - if err != nil { - return "", err - } - defer resp.Body.Close() - - body, err := io.ReadAll(resp.Body) if err != nil { return "", err } - return string(body), nil + // Use the Ollama client to generate the response + ctx := context.Background() + client := api.ClientFromEnvironment() + + var result string + err = client.Generate(ctx, &req, func(resp api.GenerateResponse) error { + result += resp.Response + return nil + }) + if err != nil { + return "", err + } + + return result, nil +} + +// OllamaSummarizer implements the Summarizer interface for Ollama endpoints +type OllamaSummarizer struct{} + +// Summarize sends the prompt to an Ollama endpoint for summarization +func (o *OllamaSummarizer) Summarize(fullPrompt string, ollamaEndpoint string, ollamaToken string, ollamaModel string) (string, error) { + // Check if required parameters are set + if ollamaModel == "" { + return "", fmt.Errorf("Ollama model not set") + } + + // Create the request + ctx := context.Background() + client := api.ClientFromEnvironment() + + req := &api.GenerateRequest{ + Model: ollamaModel, + Prompt: fullPrompt, + Stream: nil, + } + + var result string + err := client.Generate(ctx, req, func(resp api.GenerateResponse) error { + result += resp.Response + return nil + }) + if err != nil { + return "", err + } + + return result, nil } // buildPrompt constructs the prompt string from PRs, issues, and tasks From 9e82b772768abb785b89324cb3ceeedf136d1c94 Mon Sep 17 00:00:00 2001 From: Olivier Tremblay Date: Sun, 16 Nov 2025 16:40:17 -0500 Subject: [PATCH 05/10] refactor: simplify OpenAI and Ollama summarizer implementations --- cmd/acb/summarize.go | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/cmd/acb/summarize.go b/cmd/acb/summarize.go index ad41c9f..ab47e37 100644 --- a/cmd/acb/summarize.go +++ b/cmd/acb/summarize.go @@ -33,37 +33,19 @@ func (o *OpenAISummarizer) Summarize(fullPrompt string, openaiEndpoint string, o return "", fmt.Errorf("OpenAI endpoint or token not set") } - // Create a JSON payload for the OpenAI API - payload := struct { - Model string `json:"model"` - Messages []struct { - Role string `json:"role"` - Content string `json:"content"` - } `json:"messages"` - }{ - Model: openaiModel, - Messages: []struct { - Role string `json:"role"` - Content string `json:"content"` - }{{Role: "system", Content: fullPrompt}}, - } - // Create a POST request to the OpenAI endpoint with JSON body - req, err := api.GenerateRequest{ + req := api.GenerateRequest{ Model: openaiModel, Prompt: fullPrompt, Stream: nil, } - if err != nil { - return "", err - } // Use the Ollama client to generate the response ctx := context.Background() - client := api.ClientFromEnvironment() - + client, _ := api.ClientFromEnvironment() + var result string - err = client.Generate(ctx, &req, func(resp api.GenerateResponse) error { + err := client.Generate(ctx, &req, func(resp api.GenerateResponse) error { result += resp.Response return nil }) @@ -86,7 +68,7 @@ func (o *OllamaSummarizer) Summarize(fullPrompt string, ollamaEndpoint string, o // Create the request ctx := context.Background() - client := api.ClientFromEnvironment() + client, _ := api.ClientFromEnvironment() req := &api.GenerateRequest{ Model: ollamaModel, @@ -123,7 +105,7 @@ func buildPrompt(employeename string, prs map[string][]contributions.PullRequest fullPrompt += fmt.Sprintf("Description: %s\n", issue.Description) fullPrompt += "--------\n" } - + // Save prompt to file for debugging promptf, err := os.Create(fmt.Sprintf("prompt-%s-%d.json", employeename, time.Now().Unix())) if err != nil { @@ -132,7 +114,7 @@ func buildPrompt(employeename string, prs map[string][]contributions.PullRequest } promptf.WriteString(fullPrompt) defer promptf.Close() - + return fullPrompt } @@ -140,12 +122,12 @@ func buildPrompt(employeename string, prs map[string][]contributions.PullRequest func SummarizeData(employeename string, prs map[string][]contributions.PullRequest, issues []issues.Issue, tasks []vikunja.Task, prompt string, openaiEndpoint string, openaiToken string, openaiModel string, summarizer Summarizer) (string, error) { // Build the prompt fullPrompt := buildPrompt(employeename, prs, issues, tasks, prompt) - + // Always call the summarizer's Summarize method result, err := summarizer.Summarize(fullPrompt, openaiEndpoint, openaiToken, openaiModel) if err != nil { return "", err } - + return result, nil } From bffdff73a4d0fbfccf251d1f16f9287d128c3681 Mon Sep 17 00:00:00 2001 From: Olivier Tremblay Date: Sun, 16 Nov 2025 16:41:11 -0500 Subject: [PATCH 06/10] refactor: simplify Summarizer interface by moving endpoint, token, and model to struct properties Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) --- cmd/acb/summarize.go | 57 +++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/cmd/acb/summarize.go b/cmd/acb/summarize.go index ab47e37..24dcdb6 100644 --- a/cmd/acb/summarize.go +++ b/cmd/acb/summarize.go @@ -20,30 +20,42 @@ I'd like the summary for the accomplishments to be in prose form, in a few parag // Summarizer interface defines the contract for summarization implementations type Summarizer interface { - Summarize(prompt string, endpoint string, token string, model string) (string, error) + Summarize(prompt string) (string, error) } // OpenAISummarizer implements the Summarizer interface for OpenAI-compatible endpoints -type OpenAISummarizer struct{} +type OpenAISummarizer struct { + endpoint string + token string + model string +} + +// NewOpenAISummarizer creates a new OpenAISummarizer with the given parameters +func NewOpenAISummarizer(endpoint, token, model string) *OpenAISummarizer { + return &OpenAISummarizer{ + endpoint: endpoint, + token: token, + model: model, + } +} // Summarize sends the prompt to an OpenAI-compatible endpoint for summarization -func (o *OpenAISummarizer) Summarize(fullPrompt string, openaiEndpoint string, openaiToken string, openaiModel string) (string, error) { +func (o *OpenAISummarizer) Summarize(fullPrompt string) (string, error) { // Check if required environment variables are set - if openaiEndpoint == "" || openaiToken == "" { + if o.endpoint == "" || o.token == "" { return "", fmt.Errorf("OpenAI endpoint or token not set") } - // Create a POST request to the OpenAI endpoint with JSON body + // Create the request + ctx := context.Background() + client, _ := api.ClientFromEnvironment() + req := api.GenerateRequest{ - Model: openaiModel, + Model: o.model, Prompt: fullPrompt, Stream: nil, } - // Use the Ollama client to generate the response - ctx := context.Background() - client, _ := api.ClientFromEnvironment() - var result string err := client.Generate(ctx, &req, func(resp api.GenerateResponse) error { result += resp.Response @@ -57,12 +69,25 @@ func (o *OpenAISummarizer) Summarize(fullPrompt string, openaiEndpoint string, o } // OllamaSummarizer implements the Summarizer interface for Ollama endpoints -type OllamaSummarizer struct{} +type OllamaSummarizer struct { + endpoint string + token string + model string +} + +// NewOllamaSummarizer creates a new OllamaSummarizer with the given parameters +func NewOllamaSummarizer(endpoint, token, model string) *OllamaSummarizer { + return &OllamaSummarizer{ + endpoint: endpoint, + token: token, + model: model, + } +} // Summarize sends the prompt to an Ollama endpoint for summarization -func (o *OllamaSummarizer) Summarize(fullPrompt string, ollamaEndpoint string, ollamaToken string, ollamaModel string) (string, error) { +func (o *OllamaSummarizer) Summarize(fullPrompt string) (string, error) { // Check if required parameters are set - if ollamaModel == "" { + if o.model == "" { return "", fmt.Errorf("Ollama model not set") } @@ -71,7 +96,7 @@ func (o *OllamaSummarizer) Summarize(fullPrompt string, ollamaEndpoint string, o client, _ := api.ClientFromEnvironment() req := &api.GenerateRequest{ - Model: ollamaModel, + Model: o.model, Prompt: fullPrompt, Stream: nil, } @@ -119,12 +144,12 @@ func buildPrompt(employeename string, prs map[string][]contributions.PullRequest } // SummarizeData builds the prompt and calls the summarization endpoint -func SummarizeData(employeename string, prs map[string][]contributions.PullRequest, issues []issues.Issue, tasks []vikunja.Task, prompt string, openaiEndpoint string, openaiToken string, openaiModel string, summarizer Summarizer) (string, error) { +func SummarizeData(employeename string, prs map[string][]contributions.PullRequest, issues []issues.Issue, tasks []vikunja.Task, prompt string, summarizer Summarizer) (string, error) { // Build the prompt fullPrompt := buildPrompt(employeename, prs, issues, tasks, prompt) // Always call the summarizer's Summarize method - result, err := summarizer.Summarize(fullPrompt, openaiEndpoint, openaiToken, openaiModel) + result, err := summarizer.Summarize(fullPrompt) if err != nil { return "", err } From 2034bee99c053bad38f0a1a23b7c3a6f24c5fe7e Mon Sep 17 00:00:00 2001 From: Olivier Tremblay Date: Sun, 16 Nov 2025 17:20:40 -0500 Subject: [PATCH 07/10] feat: add Ollama summarizer support to main command --- cmd/acb/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/acb/main.go b/cmd/acb/main.go index ae397b3..493e067 100644 --- a/cmd/acb/main.go +++ b/cmd/acb/main.go @@ -73,7 +73,7 @@ func main() { openaiModel := os.Getenv("OPENAI_MODEL") // Always call SummarizeData to ensure prompt file is created for debugging - summ, err := SummarizeData(*employeename, prs, issues, vikunjaTasks, finalPrompt, openaiEndpoint, openaiToken, openaiModel) + summ, err := SummarizeData(*employeename, prs, issues, vikunjaTasks, finalPrompt, openaiEndpoint, openaiToken, openaiModel, &OllamaSummarizer{}) if err != nil { fmt.Println(fmt.Errorf("error getting PRs: %w", err)) os.Exit(1) From 7f2629d09c8f083785896041ad4f6b842a117859 Mon Sep 17 00:00:00 2001 From: Olivier Tremblay Date: Sun, 16 Nov 2025 17:21:12 -0500 Subject: [PATCH 08/10] fix: remove extraneous parameters from SummarizeData call and use properly initialized OllamaSummarizer Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) --- cmd/acb/main.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/acb/main.go b/cmd/acb/main.go index 493e067..7d551e2 100644 --- a/cmd/acb/main.go +++ b/cmd/acb/main.go @@ -72,8 +72,11 @@ func main() { openaiToken := os.Getenv("OPENAI_TOKEN") openaiModel := os.Getenv("OPENAI_MODEL") + // Create Ollama summarizer + ollamaSummarizer := NewOllamaSummarizer("", "", openaiModel) + // Always call SummarizeData to ensure prompt file is created for debugging - summ, err := SummarizeData(*employeename, prs, issues, vikunjaTasks, finalPrompt, openaiEndpoint, openaiToken, openaiModel, &OllamaSummarizer{}) + summ, err := SummarizeData(*employeename, prs, issues, vikunjaTasks, finalPrompt, ollamaSummarizer) if err != nil { fmt.Println(fmt.Errorf("error getting PRs: %w", err)) os.Exit(1) From 513af56ffff15c662d43511ee900b7a6940b87db Mon Sep 17 00:00:00 2001 From: Olivier Tremblay Date: Sun, 16 Nov 2025 20:28:52 -0500 Subject: [PATCH 09/10] feat: add AnthropicSummarizer implementation using anthropic-sdk-go package Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) --- cmd/acb/main.go | 25 ++++++++++++++++----- cmd/acb/summarize.go | 53 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 6 deletions(-) diff --git a/cmd/acb/main.go b/cmd/acb/main.go index 7d551e2..0f3df32 100644 --- a/cmd/acb/main.go +++ b/cmd/acb/main.go @@ -67,26 +67,39 @@ func main() { // vikunjaTasks = DoVikunja(*start, *end) // } - // Get OpenAI environment variables + // Get environment variables openaiEndpoint := os.Getenv("OPENAI_ENDPOINT") openaiToken := os.Getenv("OPENAI_TOKEN") openaiModel := os.Getenv("OPENAI_MODEL") + anthropicModel := os.Getenv("ANTHROPIC_MODEL") - // Create Ollama summarizer - ollamaSummarizer := NewOllamaSummarizer("", "", openaiModel) + // Create appropriate summarizer based on available environment variables + var summarizer Summarizer + if openaiEndpoint != "" && openaiToken != "" { + // Use OpenAI summarizer + summarizer = NewOpenAISummarizer(openaiEndpoint, openaiToken, openaiModel) + } else if anthropicModel != "" { + // Use Anthropic summarizer + summarizer = NewAnthropicSummarizer(anthropicModel) + } else { + // Use Ollama summarizer as fallback + summarizer = NewOllamaSummarizer("", "", openaiModel) + } // Always call SummarizeData to ensure prompt file is created for debugging - summ, err := SummarizeData(*employeename, prs, issues, vikunjaTasks, finalPrompt, ollamaSummarizer) + summ, err := SummarizeData(*employeename, prs, issues, vikunjaTasks, finalPrompt, summarizer) if err != nil { fmt.Println(fmt.Errorf("error getting PRs: %w", err)) os.Exit(1) } - // Only call summarization endpoint if OpenAI env vars are set + // Only call summarization endpoint if we have appropriate credentials if openaiEndpoint != "" && openaiToken != "" { fmt.Println(summ) + } else if os.Getenv("ANTHROPIC_API_KEY") != "" && anthropicModel != "" { + fmt.Println(summ) } else { - fmt.Println("OpenAI endpoint and token not set, but prompt file was created for debugging") + fmt.Println("No summarization endpoint configured, but prompt file was created for debugging") } } diff --git a/cmd/acb/summarize.go b/cmd/acb/summarize.go index 24dcdb6..eeab02a 100644 --- a/cmd/acb/summarize.go +++ b/cmd/acb/summarize.go @@ -10,6 +10,8 @@ import ( "o5r.ca/autocrossbow/issues" "o5r.ca/autocrossbow/issues/vikunja" + "github.com/anthropics/anthropic-sdk-go" + "github.com/anthropics/anthropic-sdk-go/option" "github.com/ollama/ollama/api" ) @@ -113,6 +115,57 @@ func (o *OllamaSummarizer) Summarize(fullPrompt string) (string, error) { return result, nil } +// AnthropicSummarizer implements the Summarizer interface for Anthropic API +type AnthropicSummarizer struct { + client *anthropic.Client + model string +} + +// NewAnthropicSummarizer creates a new AnthropicSummarizer with the given parameters +func NewAnthropicSummarizer(model string) *AnthropicSummarizer { + // Create the Anthropic client with the API key from environment + client := anthropic.NewClient( + option.WithAPIKey(os.Getenv("ANTHROPIC_API_KEY")), + ) + + return &AnthropicSummarizer{ + client: client, + model: model, + } +} + +// Summarize sends the prompt to the Anthropic API for summarization +func (a *AnthropicSummarizer) Summarize(fullPrompt string) (string, error) { + // Check if required parameters are set + if a.model == "" { + return "", fmt.Errorf("Anthropic model not set") + } + + // Create the request + ctx := context.Background() + + message, err := a.client.Messages.New(ctx, anthropic.MessageNewParams{ + Model: a.model, + MaxTokens: 1024, + Messages: []anthropic.MessageParam{ + anthropic.NewUserMessage(anthropic.NewTextBlock(fullPrompt)), + }, + }) + if err != nil { + return "", err + } + + // Extract the response text + var result string + for _, content := range message.Content { + if textBlock, ok := content.AsAny().(*anthropic.TextBlock); ok { + result += textBlock.Text + } + } + + return result, nil +} + // buildPrompt constructs the prompt string from PRs, issues, and tasks func buildPrompt(employeename string, prs map[string][]contributions.PullRequest, issues []issues.Issue, tasks []vikunja.Task, prompt string) string { // Build a prompt string From f326dca8a95d2bc445bae7d93d02dd7b03c5a09d Mon Sep 17 00:00:00 2001 From: Olivier Tremblay Date: Mon, 17 Nov 2025 11:10:13 -0500 Subject: [PATCH 10/10] fix: change summarizer call condition to check if summarizer is nil instead of environment variables Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) --- cmd/acb/main.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmd/acb/main.go b/cmd/acb/main.go index 0f3df32..2ae98b0 100644 --- a/cmd/acb/main.go +++ b/cmd/acb/main.go @@ -93,10 +93,8 @@ func main() { os.Exit(1) } - // Only call summarization endpoint if we have appropriate credentials - if openaiEndpoint != "" && openaiToken != "" { - fmt.Println(summ) - } else if os.Getenv("ANTHROPIC_API_KEY") != "" && anthropicModel != "" { + // Only call summarization endpoint if we have a valid summarizer + if summarizer != nil { fmt.Println(summ) } else { fmt.Println("No summarization endpoint configured, but prompt file was created for debugging")