Skip to content

Commit

Permalink
Merge pull request #136 from JohnStrunk/prompt
Browse files Browse the repository at this point in the history
Prompt tuning
  • Loading branch information
mergify[bot] authored Jun 24, 2024
2 parents 9ec0287 + d2daa84 commit 19e2f75
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 7 deletions.
13 changes: 12 additions & 1 deletion summarize_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def main():
action="store_true",
help="Do not update the Jira issues with the summaries",
)
parser.add_argument(
"-p",
"--prompt-only",
action="store_true",
help="Print the LLM prompt, but do not generate the summary",
)
parser.add_argument(
"-r",
"--regenerate",
Expand All @@ -51,12 +57,17 @@ def main():
max_depth = args.max_depth
regenerate = args.regenerate
send_updates = not args.no_update
prompt_only = args.prompt_only

jira = Jira(url=os.environ["JIRA_URL"], token=os.environ["JIRA_TOKEN"])

issue = Issue(jira, args.jira_issue_key)
out = summarize_issue(
issue, regenerate=regenerate, max_depth=max_depth, send_updates=send_updates
issue,
regenerate=regenerate,
max_depth=max_depth,
send_updates=send_updates,
return_prompt_only=prompt_only,
)
print(out)

Expand Down
79 changes: 73 additions & 6 deletions summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@ def summarize_issue( # pylint: disable=too-many-arguments,too-many-branches,too

# If the current summary is up-to-date and we're not asked to regenerate it,
# return what's there
if not regenerate and is_summary_current(issue):
if not regenerate and is_summary_current(issue) and not return_prompt_only:
_logger.info("Summarizing (using current): %s", issue)
return _wrapper.get(issue.status_summary) or ""

if return_prompt_only:
send_updates = False

_logger.info("Summarizing: %s", issue)
# if we have not reached max-depth, summarize the child issues for inclusion in this summary
child_summaries: List[Tuple[RelatedIssue, str]] = []
Expand Down Expand Up @@ -159,7 +162,7 @@ def summarize_issue( # pylint: disable=too-many-arguments,too-many-branches,too
related_block.write(f"* {issue.key} {child.how} {ri}\n")
else:
related_block.write(
f"* {issue.key} {child.how} {child.key} which can be summarized as:\n"
f"* {issue.key} {child.how} {child.key}, and {child.key} can be summarized as:\n"
)
related_block.write(
textwrap.fill(
Expand Down Expand Up @@ -188,9 +191,7 @@ def summarize_issue( # pylint: disable=too-many-arguments,too-many-branches,too

llm_prompt = f"""\
You are a helpful assistant who is an expert in software development.
* Summarize the status of the following Jira issue in a few sentences.
* Include an overview of any significant discussions or decisions, with their reasoning and outcome.
* Highlight any recent updates or changes that effect the completion of the issue.
{_prompt_for_type(issue)}
* Use only the information below to create your summary.
* Include only the text of your summary in the response with no formatting.
* Limit your summary to 100 words or less.
Expand All @@ -217,6 +218,71 @@ def summarize_issue( # pylint: disable=too-many-arguments,too-many-branches,too
return folded_summary


def _prompt_for_type(issue: Issue) -> str:
"""
Generate a prompt for the type of issue.
Parameters:
- issue: The issue to generate the prompt for
Returns:
The prompt
"""
# pylint: disable=line-too-long
default_prompt = textwrap.dedent(
f"""\
You are an AI assistant summarizing a Jira {issue.issue_type} for software engineers.
Provide a concise summary focusing on:
1. Technical details and implementation challenges
2. Decisions on technical approaches or tools
3. Blockers or dependencies affecting progress
4. Overall purpose and current status
5. Relevant information from child issues
6. Recent, impactful updates or changes
Use only the provided information. Limit your summary to 100 words or
fewer, with no additional formatting. Today's date is {datetime.now().strftime("%A, %B %d, %Y")}.
"""
).strip()
if issue.level == 3: # Epic, Release Milestone
return textwrap.dedent(
f"""\
You are an AI assistant summarizing a Jira {issue.issue_type} for product
managers. Provide a concise summary focusing on:
1. Overall progress and timeline adherence
2. Major risks or obstacles to completion
3. Key decisions impacting the product roadmap
4. High-level purpose and current status
5. Relevant information from child issues
6. Recent, impactful updates or changes
Use only the provided information. Limit your summary to 100 words or fewer,
with no additional formatting. Today's date is {datetime.now().strftime("%A, %B %d, %Y")}.
"""
).strip()
if issue.level >= 4: # Feature, Initiative, Requirement
return textwrap.dedent(
f"""\
You are an AI assistant summarizing a Jira {issue.issue_type} for corporate leaders. Provide a concise summary
focusing on:
1. High-level overview of progress towards the goal
2. Significant milestones achieved or upcoming
3. Major risks or opportunities identified
4. Overall purpose and current status
5. Key information from child issues
6. Recent, impactful updates affecting the outcome
Use only the provided information. Limit your summary to 100 words
or fewer, with no additional formatting. Today's date is
{datetime.now().strftime("%A, %B %d, %Y")}.
"""
).strip()
return default_prompt


def summary_last_updated(issue: Issue) -> datetime:
"""
Get the last time the summary was updated.
Expand Down Expand Up @@ -400,7 +466,8 @@ def get_issues_to_summarize(
updated_issues = check_response(
with_retry(
lambda: client.jql(
f"labels = '{SUMMARY_ALLOWED_LABEL}' and updated >= '{since_string}' ORDER BY updated ASC", # pylint: disable=line-too-long
f"labels = '{SUMMARY_ALLOWED_LABEL}' and updated >= '{
since_string}' ORDER BY updated ASC", # pylint: disable=line-too-long
limit=limit,
fields="key,updated",
)
Expand Down

0 comments on commit 19e2f75

Please sign in to comment.