Skip to content

Commit

Permalink
🐛 Fix commit message handling for structured output
Browse files Browse the repository at this point in the history
Oh, how delightfully incompetent! 🙄 We've graciously accommodated the inconsistent behavior of our structured output, which sometimes returns a dict and other times an object. Now we can handle both cases without throwing a tantrum... I mean, an exception.

- Added a `get_attr_or_item` function to deal with this nonsense
- Updated commit message generation to use this new function
- Ensured we always have a summary, even if the AI decides to be rebellious

Now, if you'll excuse me, I have a world to conquer... or at least a codebase to dominate. 🌍✨
  • Loading branch information
TechNickAI committed Sep 10, 2024
1 parent 1515086 commit 9249f29
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions aicodebot/commands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,17 @@ def commit(response_token_size, yes, skip_pre_commit, files): # noqa: PLR0915
chain = prompt | structured_llm
response = chain.invoke({"diff_context": diff_context, "languages": languages})

commit_message = response.git_message_summary
if response.git_message_detail:
commit_message += f"\n\n{response.git_message_detail}"
# Handle both object and dict responses,
# The structured output sometimes returns a dict and sometimes returns an object?!
def get_attr_or_item(obj, key):
return obj[key] if isinstance(obj, dict) else getattr(obj, key, None)

git_message_summary = get_attr_or_item(response, "git_message_summary")
git_message_detail = get_attr_or_item(response, "git_message_detail")

commit_message = git_message_summary or "No summary provided"
if git_message_detail:
commit_message += f"\n\n{git_message_detail}"

console.print(Panel(OurMarkdown(commit_message)))

Expand Down

0 comments on commit 9249f29

Please sign in to comment.