mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-28 09:28:48 +00:00
handle refusals
This commit is contained in:
parent
33e7d91f1a
commit
9d23627fcd
@ -324,11 +324,17 @@ def _convert_chunk_to_generation_chunk(
|
|||||||
) -> Optional[ChatGenerationChunk]:
|
) -> Optional[ChatGenerationChunk]:
|
||||||
if chunk.get("type") == "content.delta": # from beta.chat.completions.stream
|
if chunk.get("type") == "content.delta": # from beta.chat.completions.stream
|
||||||
return None
|
return None
|
||||||
if chunk.get("type") == "content.done" and hasattr(chunk_object, "parsed"):
|
if (
|
||||||
|
chunk.get("type") == "content.done"
|
||||||
|
and hasattr(chunk_object, "parsed")
|
||||||
|
or hasattr(chunk_object, "refusal")
|
||||||
|
):
|
||||||
|
additional_kwargs = {
|
||||||
|
"parsed": getattr(chunk_object, "parsed", None),
|
||||||
|
"refusal": getattr(chunk_object, "refusal", None),
|
||||||
|
}
|
||||||
return ChatGenerationChunk(
|
return ChatGenerationChunk(
|
||||||
message=default_chunk_class(
|
message=default_chunk_class(content="", additional_kwargs=additional_kwargs)
|
||||||
content="", additional_kwargs={"parsed": chunk_object.parsed}
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
token_usage = chunk.get("usage") or chunk.get("chunk", {}).get("usage")
|
token_usage = chunk.get("usage") or chunk.get("chunk", {}).get("usage")
|
||||||
|
Loading…
Reference in New Issue
Block a user