Skip to content

Commit 9249f29

Browse files
committed
🐛 Fix commit message handling for structured output
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. 🌍✨
1 parent 1515086 commit 9249f29

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

aicodebot/commands/commit.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,17 @@ def commit(response_token_size, yes, skip_pre_commit, files): # noqa: PLR0915
102102
chain = prompt | structured_llm
103103
response = chain.invoke({"diff_context": diff_context, "languages": languages})
104104

105-
commit_message = response.git_message_summary
106-
if response.git_message_detail:
107-
commit_message += f"\n\n{response.git_message_detail}"
105+
# Handle both object and dict responses,
106+
# The structured output sometimes returns a dict and sometimes returns an object?!
107+
def get_attr_or_item(obj, key):
108+
return obj[key] if isinstance(obj, dict) else getattr(obj, key, None)
109+
110+
git_message_summary = get_attr_or_item(response, "git_message_summary")
111+
git_message_detail = get_attr_or_item(response, "git_message_detail")
112+
113+
commit_message = git_message_summary or "No summary provided"
114+
if git_message_detail:
115+
commit_message += f"\n\n{git_message_detail}"
108116

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

0 commit comments

Comments
 (0)