mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-13 04:18:58 +08:00
fix(llm/nodes.py): Ensure that the output returns without any exceptions (#14880)
This commit is contained in:
parent
cef49da576
commit
4f6a4f244c
@ -191,6 +191,22 @@ class LLMNode(BaseNode[LLMNodeData]):
|
|||||||
# deduct quota
|
# deduct quota
|
||||||
self.deduct_llm_quota(tenant_id=self.tenant_id, model_instance=model_instance, usage=usage)
|
self.deduct_llm_quota(tenant_id=self.tenant_id, model_instance=model_instance, usage=usage)
|
||||||
break
|
break
|
||||||
|
outputs = {"text": result_text, "usage": jsonable_encoder(usage), "finish_reason": finish_reason}
|
||||||
|
|
||||||
|
yield RunCompletedEvent(
|
||||||
|
run_result=NodeRunResult(
|
||||||
|
status=WorkflowNodeExecutionStatus.SUCCEEDED,
|
||||||
|
inputs=node_inputs,
|
||||||
|
process_data=process_data,
|
||||||
|
outputs=outputs,
|
||||||
|
metadata={
|
||||||
|
NodeRunMetadataKey.TOTAL_TOKENS: usage.total_tokens,
|
||||||
|
NodeRunMetadataKey.TOTAL_PRICE: usage.total_price,
|
||||||
|
NodeRunMetadataKey.CURRENCY: usage.currency,
|
||||||
|
},
|
||||||
|
llm_usage=usage,
|
||||||
|
)
|
||||||
|
)
|
||||||
except LLMNodeError as e:
|
except LLMNodeError as e:
|
||||||
yield RunCompletedEvent(
|
yield RunCompletedEvent(
|
||||||
run_result=NodeRunResult(
|
run_result=NodeRunResult(
|
||||||
@ -211,23 +227,6 @@ class LLMNode(BaseNode[LLMNodeData]):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
outputs = {"text": result_text, "usage": jsonable_encoder(usage), "finish_reason": finish_reason}
|
|
||||||
|
|
||||||
yield RunCompletedEvent(
|
|
||||||
run_result=NodeRunResult(
|
|
||||||
status=WorkflowNodeExecutionStatus.SUCCEEDED,
|
|
||||||
inputs=node_inputs,
|
|
||||||
process_data=process_data,
|
|
||||||
outputs=outputs,
|
|
||||||
metadata={
|
|
||||||
NodeRunMetadataKey.TOTAL_TOKENS: usage.total_tokens,
|
|
||||||
NodeRunMetadataKey.TOTAL_PRICE: usage.total_price,
|
|
||||||
NodeRunMetadataKey.CURRENCY: usage.currency,
|
|
||||||
},
|
|
||||||
llm_usage=usage,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def _invoke_llm(
|
def _invoke_llm(
|
||||||
self,
|
self,
|
||||||
node_data_model: ModelConfig,
|
node_data_model: ModelConfig,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user