Skip to content

Commit 1abf050

Browse files
authored
Fix: Add instance check before casting ChatGeneration object (#1607)
My case - When receiving responses from headline and summary extractors, etc., they are delivered as a Generation object, not ChatGeneration. ``` { "generations": [ [ { "text": "{\"text\": \"ABCD\"}", "generation_info": null, "type": "Generation" } ] ], "llm_output": null, "run": null, "type": "LLMResult" } ``` Occurrence message - unable to apply transformation: 'Generation' object has no attribute 'message' How to fix - Add code to first check if it is an instance of that object before casting to a ChatGeneration object.
1 parent 20fa51c commit 1abf050

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/ragas/llms/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def is_finished(self, response: LLMResult) -> bool:
157157

158158
# if generation_info is empty, we parse the response_metadata
159159
# this is less reliable
160-
elif t.cast(ChatGeneration, resp).message is not None:
160+
elif isinstance(resp, ChatGeneration) and t.cast(ChatGeneration, resp).message is not None:
161161
resp_message: BaseMessage = t.cast(ChatGeneration, resp).message
162162
if resp_message.response_metadata.get("finish_reason") is not None:
163163
is_finished_list.append(

0 commit comments

Comments
 (0)