mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 23:55:55 +08:00
feat: add langfuse llm node input and output (#17368)
This commit is contained in:
parent
12faecdf89
commit
a83318cf4b
@ -213,9 +213,24 @@ class LangFuseDataTrace(BaseTraceInstance):
|
|||||||
|
|
||||||
if process_data and process_data.get("model_mode") == "chat":
|
if process_data and process_data.get("model_mode") == "chat":
|
||||||
total_token = metadata.get("total_tokens", 0)
|
total_token = metadata.get("total_tokens", 0)
|
||||||
|
prompt_tokens = 0
|
||||||
|
completion_tokens = 0
|
||||||
|
try:
|
||||||
|
if outputs.get("usage"):
|
||||||
|
prompt_tokens = outputs.get("usage", {}).get("prompt_tokens", 0)
|
||||||
|
completion_tokens = outputs.get("usage", {}).get("completion_tokens", 0)
|
||||||
|
else:
|
||||||
|
prompt_tokens = process_data.get("usage", {}).get("prompt_tokens", 0)
|
||||||
|
completion_tokens = process_data.get("usage", {}).get("completion_tokens", 0)
|
||||||
|
except Exception:
|
||||||
|
logger.error("Failed to extract usage", exc_info=True)
|
||||||
|
|
||||||
# add generation
|
# add generation
|
||||||
generation_usage = GenerationUsage(
|
generation_usage = GenerationUsage(
|
||||||
|
input=prompt_tokens,
|
||||||
|
output=completion_tokens,
|
||||||
total=total_token,
|
total=total_token,
|
||||||
|
unit=UnitEnum.TOKENS,
|
||||||
)
|
)
|
||||||
|
|
||||||
node_generation_data = LangfuseGeneration(
|
node_generation_data = LangfuseGeneration(
|
||||||
|
@ -199,6 +199,7 @@ class LangSmithDataTrace(BaseTraceInstance):
|
|||||||
)
|
)
|
||||||
|
|
||||||
process_data = json.loads(node_execution.process_data) if node_execution.process_data else {}
|
process_data = json.loads(node_execution.process_data) if node_execution.process_data else {}
|
||||||
|
|
||||||
if process_data and process_data.get("model_mode") == "chat":
|
if process_data and process_data.get("model_mode") == "chat":
|
||||||
run_type = LangSmithRunType.llm
|
run_type = LangSmithRunType.llm
|
||||||
metadata.update(
|
metadata.update(
|
||||||
@ -212,9 +213,23 @@ class LangSmithDataTrace(BaseTraceInstance):
|
|||||||
else:
|
else:
|
||||||
run_type = LangSmithRunType.tool
|
run_type = LangSmithRunType.tool
|
||||||
|
|
||||||
|
prompt_tokens = 0
|
||||||
|
completion_tokens = 0
|
||||||
|
try:
|
||||||
|
if outputs.get("usage"):
|
||||||
|
prompt_tokens = outputs.get("usage", {}).get("prompt_tokens", 0)
|
||||||
|
completion_tokens = outputs.get("usage", {}).get("completion_tokens", 0)
|
||||||
|
else:
|
||||||
|
prompt_tokens = process_data.get("usage", {}).get("prompt_tokens", 0)
|
||||||
|
completion_tokens = process_data.get("usage", {}).get("completion_tokens", 0)
|
||||||
|
except Exception:
|
||||||
|
logger.error("Failed to extract usage", exc_info=True)
|
||||||
|
|
||||||
node_dotted_order = generate_dotted_order(node_execution_id, created_at, workflow_dotted_order)
|
node_dotted_order = generate_dotted_order(node_execution_id, created_at, workflow_dotted_order)
|
||||||
langsmith_run = LangSmithRunModel(
|
langsmith_run = LangSmithRunModel(
|
||||||
total_tokens=node_total_tokens,
|
total_tokens=node_total_tokens,
|
||||||
|
input_tokens=prompt_tokens,
|
||||||
|
output_tokens=completion_tokens,
|
||||||
name=node_type,
|
name=node_type,
|
||||||
inputs=inputs,
|
inputs=inputs,
|
||||||
run_type=run_type,
|
run_type=run_type,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user