Skip to content

Commit 559ec15

Browse files
ref(feedback): update summary prompt and response parsing (#93847)
1 parent 018bd22 commit 559ec15

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

src/sentry/feedback/usecases/feedback_summaries.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,22 @@ def make_input_prompt(
1111
feedbacks,
1212
):
1313
feedbacks_string = "\n".join(f"- {msg}" for msg in feedbacks)
14-
return f"""Task:
15-
Instructions: You are an AI assistant that analyzes customer feedback.
16-
Create a summary based on the user feedbacks that is at most three sentences, and complete the sentence "Users say...". Be concise, but specific in the summary.
14+
return f"""Instructions:
15+
16+
You are an assistant that summarizes customer feedback. Given a list of customer feedback entries, generate a concise summary of 1-2 sentences that reflects the key themes. Begin the summary with "Users...", for example, "Users say...".
17+
18+
Balance specificity and generalization based on the size of the input based *only* on the themes and topics present in the list of customer feedback entries. Prioritize brevity and clarity and trying to capture what users are saying, over trying to mention random specific topics. Please don't write overly long sentences, you can leave certain things out and the decision to mention specific topics or themes should be proportional to the number of times they appear in the user feedback entries.
1719
1820
User Feedbacks:
1921
2022
{feedbacks_string}
2123
2224
Output Format:
2325
24-
Summary: <1-3 sentence summary>
26+
<1-2 sentence summary>
2527
"""
2628

2729

28-
SUMMARY_REGEX = re.compile(r"Summary:\s*(.*)", re.DOTALL)
29-
30-
3130
@metrics.wraps("feedback.summaries", sample_rate=1.0)
3231
def generate_summary(
3332
feedbacks: list[str],
@@ -50,10 +49,4 @@ def generate_summary(
5049
def parse_response(
5150
text,
5251
):
53-
summary_match = SUMMARY_REGEX.search(text)
54-
if summary_match:
55-
raw_summary_text = summary_match.group(1)
56-
summary_text = re.sub(r"\s+", " ", raw_summary_text).strip()
57-
return summary_text
58-
else:
59-
raise ValueError("Failed to parse AI feedback summary response")
52+
return re.sub(r"\s+", " ", text).strip()
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
1-
import pytest
2-
31
from sentry.feedback.usecases.feedback_summaries import parse_response
42

53

64
def test_parse_response_valid():
7-
response = "Summary: This is a test summary"
5+
response = "This is a test summary"
86
summary = parse_response(response)
97
assert summary == "This is a test summary"
108

119

1210
def test_parse_response_valid_extra_whitespace():
13-
response = """Summary: This is a test summary.
11+
response = """ This is a test summary.
1412
1513
And this is a continuation of the
1614
summary."""
1715
summary = parse_response(response)
1816
assert summary == "This is a test summary. And this is a continuation of the summary."
19-
20-
21-
def test_parse_response_response_invalid():
22-
invalid_response = "This is not a valid summary"
23-
24-
with pytest.raises(ValueError, match="Failed to parse AI feedback summary response"):
25-
parse_response(invalid_response)

0 commit comments

Comments
 (0)