refactor: split SummarizeData into buildPrompt and callSummarizationEndpoint functions
Co-authored-by: aider (openai/qwen3-coder:30b-a3b-q4_K_M) <aider@aider.chat>
This commit is contained in:
parent
dff9c6fb86
commit
038ee769bb
1 changed files with 23 additions and 4 deletions
|
|
@ -19,8 +19,8 @@ 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 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.`
|
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.`
|
||||||
|
|
||||||
// SummarizeData takes GitHub PRs and Jira issues data and sends it to an OpenAI-compatible endpoint for summarization.
|
// buildPrompt constructs the prompt string from PRs, issues, and tasks
|
||||||
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 buildPrompt(employeename string, prs map[string][]contributions.PullRequest, issues []issues.Issue, tasks []vikunja.Task, prompt string) string {
|
||||||
// Build a prompt string
|
// Build a prompt string
|
||||||
fullPrompt := prompt + fmt.Sprintf("\n\nHere's the PRs and Tickets for the employee %s:\n\n", employeename)
|
fullPrompt := prompt + fmt.Sprintf("\n\nHere's the PRs and Tickets for the employee %s:\n\n", employeename)
|
||||||
for repo, prList := range prs {
|
for repo, prList := range prs {
|
||||||
|
|
@ -36,6 +36,8 @@ func SummarizeData(employeename string, prs map[string][]contributions.PullReque
|
||||||
fullPrompt += fmt.Sprintf("Description: %s\n", issue.Description)
|
fullPrompt += fmt.Sprintf("Description: %s\n", issue.Description)
|
||||||
fullPrompt += "--------\n"
|
fullPrompt += "--------\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save prompt to file for debugging
|
||||||
promptf, err := os.Create(fmt.Sprintf("prompt-%s-%d.json", employeename, time.Now().Unix()))
|
promptf, err := os.Create(fmt.Sprintf("prompt-%s-%d.json", employeename, time.Now().Unix()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(fmt.Errorf("error creating PR file: %w", err))
|
fmt.Println(fmt.Errorf("error creating PR file: %w", err))
|
||||||
|
|
@ -43,7 +45,12 @@ func SummarizeData(employeename string, prs map[string][]contributions.PullReque
|
||||||
}
|
}
|
||||||
promptf.WriteString(fullPrompt)
|
promptf.WriteString(fullPrompt)
|
||||||
defer promptf.Close()
|
defer promptf.Close()
|
||||||
|
|
||||||
|
return fullPrompt
|
||||||
|
}
|
||||||
|
|
||||||
|
// callSummarizationEndpoint sends the prompt to an OpenAI-compatible endpoint for summarization
|
||||||
|
func callSummarizationEndpoint(fullPrompt string, openaiEndpoint string, openaiToken string, openaiModel string) (string, error) {
|
||||||
// Create a JSON payload for the OpenAI API
|
// Create a JSON payload for the OpenAI API
|
||||||
payload := struct {
|
payload := struct {
|
||||||
Model string `json:"model"`
|
Model string `json:"model"`
|
||||||
|
|
@ -85,7 +92,19 @@ func SummarizeData(employeename string, prs map[string][]contributions.PullReque
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
//parts := strings.Split(body, "think")
|
|
||||||
|
|
||||||
return string(body), nil
|
return string(body), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue