Skip to content

Commit 0dd5864

Browse files
author
Brandon Meyerowitz
committed
fix: index out of bounds error
1 parent 1c489f5 commit 0dd5864

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

commonbase/completion_response.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def name(self) -> str:
1515
def arguments(self) -> dict[str, Any]:
1616
try:
1717
return json.loads(
18-
self.json["arguments"] or "" if "arguments" in self.json else ""
18+
self.json["arguments"] or "{}" if "arguments" in self.json else "{}"
1919
)
2020
except:
2121
return {}
@@ -35,7 +35,7 @@ def role(self) -> Optional[str]:
3535

3636
@property
3737
def index(self) -> int:
38-
return self.json["index"]
38+
return self.json["index"] if "index" in self.json else 0
3939

4040
@property
4141
def finish_reason(self) -> Optional[str]:
@@ -91,4 +91,7 @@ def choices(self) -> list[CompletionChoice]:
9191

9292
@property
9393
def best_choice(self) -> CompletionChoice:
94-
return CompletionChoice(self.json["choices"][0])
94+
try:
95+
return CompletionChoice(self.json["choices"][0])
96+
except IndexError:
97+
return CompletionChoice({})

0 commit comments

Comments
 (0)