Commit 2511659
committed
Fix #1559: Handle empty choices array in LiteLLM model
Add defensive checks before accessing response.choices[0] to prevent
IndexError when Gemini or other providers return an empty choices array.
This follows the same pattern as PR #935 which fixed the identical issue
in openai_chatcompletions.py.
Changes:
- Add null checks for response.choices before array access
- Return empty output when choices array is empty
- Preserve usage information even when choices is empty
- Add appropriate type annotations for litellm types1 parent 03dca68 commit 2511659
1 file changed
+24
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
114 | 121 | | |
115 | 122 | | |
116 | 123 | | |
117 | 124 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
125 | 134 | | |
126 | 135 | | |
127 | 136 | | |
| |||
151 | 160 | | |
152 | 161 | | |
153 | 162 | | |
154 | | - | |
155 | | - | |
| 163 | + | |
| 164 | + | |
156 | 165 | | |
157 | 166 | | |
158 | 167 | | |
159 | 168 | | |
160 | 169 | | |
161 | | - | |
162 | | - | |
163 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
164 | 175 | | |
165 | 176 | | |
166 | 177 | | |
| |||
0 commit comments