From b20b657008827c5de6ab03d4875ed05d6c94a320 Mon Sep 17 00:00:00 2001 From: William Petit Date: Thu, 7 Aug 2025 12:25:39 +0200 Subject: [PATCH] feat: trim llm response --- internal/core/service/forge_manager.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/internal/core/service/forge_manager.go b/internal/core/service/forge_manager.go index f65b878..18a76fe 100644 --- a/internal/core/service/forge_manager.go +++ b/internal/core/service/forge_manager.go @@ -173,8 +173,12 @@ func (m *ForgeManager) GeneratePullRequest(ctx context.Context, user *model.User body := res.Message().Content() + body = strings.TrimSpace(body) + body = strings.TrimPrefix(body, "```markdown") + body = strings.TrimSuffix(body, "```") + messages = append(messages, res.Message()) - messages = append(messages, llm.NewMessage(llm.RoleUser, "Generate a title for this issue. Keep it descriptive, simple and short. Do not write anything else.")) + messages = append(messages, llm.NewMessage(llm.RoleUser, "Generate a title for this pull request. Keep it descriptive, simple and short. Do not write anything else. Use the same language.")) res, err = m.llmClient.ChatCompletion(ctx, llm.WithMessages(messages...)) if err != nil { @@ -184,7 +188,7 @@ func (m *ForgeManager) GeneratePullRequest(ctx context.Context, user *model.User title := toTitle(res.Message().Content()) messages = append(messages, res.Message()) - messages = append(messages, llm.NewMessage(llm.RoleUser, "Give me a list of questions as Markdown that could help clarify the request. Only write the list without additional headings.")) + messages = append(messages, llm.NewMessage(llm.RoleUser, "Give me a list of questions as Markdown that could help clarify the request. Only write the list without additional headings. Use the same language.")) res, err = m.llmClient.ChatCompletion(ctx, llm.WithMessages(messages...)) if err != nil { @@ -300,8 +304,12 @@ func (m *ForgeManager) GenerateIssue(ctx context.Context, user *model.User, proj body := res.Message().Content() + body = strings.TrimSpace(body) + body = strings.TrimPrefix(body, "```markdown") + body = strings.TrimSuffix(body, "```") + messages = append(messages, res.Message()) - messages = append(messages, llm.NewMessage(llm.RoleUser, "Generate a title for this issue. Keep it descriptive, simple and short. Do not write anything else.")) + messages = append(messages, llm.NewMessage(llm.RoleUser, "Generate a title for this issue. Keep it descriptive, simple and short. Do not write anything else. Use the same language.")) res, err = m.llmClient.ChatCompletion(ctx, llm.WithMessages(messages...)) if err != nil { @@ -311,7 +319,7 @@ func (m *ForgeManager) GenerateIssue(ctx context.Context, user *model.User, proj title := toTitle(res.Message().Content()) messages = append(messages, res.Message()) - messages = append(messages, llm.NewMessage(llm.RoleUser, "Give me a list of questions as Markdown that could help clarify the request. Only write the list without additional headings.")) + messages = append(messages, llm.NewMessage(llm.RoleUser, "Give me a list of questions as Markdown that could help clarify the request. Only write the list without additional headings. Use the same language.")) res, err = m.llmClient.ChatCompletion(ctx, llm.WithMessages(messages...)) if err != nil {