Skip to content

Commit e3cad5d

Browse files
author
yankee-oi
committed
fix(commit): handle empty chunks in streaming response
- Skip stream chunks with no choices or empty delta to prevent index errors - Bump openai to 3.24.0 and regenerate uv.lock
1 parent 07f1089 commit e3cad5d

3 files changed

Lines changed: 184 additions & 144 deletions

File tree

‎ai_commit/app.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ def generate_commit_message(staged_changes: str, regenerate: bool = False) -> st
102102
commit_message = ""
103103

104104
for chunk in stream:
105-
content = chunk.choices[0].delta.content
105+
if not chunk.choices:
106+
continue
107+
delta = chunk.choices[0].delta
108+
if delta is None or delta.content is None:
109+
continue
110+
content = delta.content
106111
if content:
107112
print(content, end="", flush=True)
108113
commit_message += content

‎pyproject.toml‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ include = ["ai_commit"]
88
[project]
99
name = "ai-gen-commit"
1010
version = "0.1.2"
11-
authors = [
12-
{ name = "Yankee Maharjan" },
13-
]
11+
authors = [{ name = "Yankee Maharjan" }]
1412
description = "AI generated commit messages!"
1513
readme = "README.md"
16-
keywords = ["ai commit", "commit ai", "ai generated commit", "llm commit", "generative ai commit"]
14+
keywords = [
15+
"ai commit",
16+
"commit ai",
17+
"ai generated commit",
18+
"llm commit",
19+
"generative ai commit",
20+
]
1721
requires-python = ">=3.10"
1822
classifiers = [
1923
"Programming Language :: Python :: 3.10",
@@ -22,18 +26,13 @@ classifiers = [
2226
"Development Status :: 4 - Beta",
2327
]
2428

25-
dependencies = [
26-
"openai==1.101.0",
27-
]
29+
dependencies = ["openai==3.24.0"]
2830

2931
[dependency-groups]
30-
dev = [
31-
"ruff==0.12.8",
32-
]
32+
dev = ["ruff==0.12.8"]
3333

3434
[project.urls]
3535
Repository = "https://github.com/yankeexe/ai-gen-commit"
3636

3737
[project.scripts]
3838
aic = "ai_commit.app:run"
39-

0 commit comments

Comments
 (0)