diff --git a/libs/community/langchain_community/chat_models/openai.py b/libs/community/langchain_community/chat_models/openai.py index 7026624c1b067..acbcc943f0dec 100644 --- a/libs/community/langchain_community/chat_models/openai.py +++ b/libs/community/langchain_community/chat_models/openai.py @@ -454,9 +454,12 @@ def _create_chat_result(self, response: Union[dict, BaseModel]) -> ChatResult: response = response.dict() for res in response["choices"]: message = convert_dict_to_message(res["message"]) + generation_info = dict(finish_reason=res.get("finish_reason")) + if "logprobs" in res: + generation_info["logprobs"] = res["logprobs"] gen = ChatGeneration( message=message, - generation_info=dict(finish_reason=res.get("finish_reason")), + generation_info=generation_info, ) generations.append(gen) token_usage = response.get("usage", {})