Skip to content

Commit

Permalink
fix(playground): add tool call id to input and output messages (#5400)
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerHYang authored Nov 20, 2024
1 parent d1b1ccc commit 283c3e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/phoenix/server/api/helpers/playground_spans.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ def _llm_output_messages(
if content := "".join(chunk.content for chunk in text_chunks):
yield f"{LLM_OUTPUT_MESSAGES}.0.{MESSAGE_CONTENT}", content
for tool_call_index, (_tool_call_id, tool_call_chunks_) in enumerate(tool_call_chunks.items()):
if _tool_call_id:
yield (
f"{LLM_OUTPUT_MESSAGES}.0.{MESSAGE_TOOL_CALLS}.{tool_call_index}.{TOOL_CALL_ID}",
_tool_call_id,
)
if tool_call_chunks_ and (name := tool_call_chunks_[0].function.name):
yield (
f"{LLM_OUTPUT_MESSAGES}.0.{MESSAGE_TOOL_CALLS}.{tool_call_index}.{TOOL_CALL_FUNCTION_NAME}",
Expand Down Expand Up @@ -441,6 +446,7 @@ def _serialize_event(event: SpanEvent) -> dict[str, Any]:
MESSAGE_ROLE = MessageAttributes.MESSAGE_ROLE
MESSAGE_TOOL_CALLS = MessageAttributes.MESSAGE_TOOL_CALLS

TOOL_CALL_ID = ToolCallAttributes.TOOL_CALL_ID
TOOL_CALL_FUNCTION_NAME = ToolCallAttributes.TOOL_CALL_FUNCTION_NAME
TOOL_CALL_FUNCTION_ARGUMENTS_JSON = ToolCallAttributes.TOOL_CALL_FUNCTION_ARGUMENTS_JSON
TOOL_CALL_ID = ToolCallAttributes.TOOL_CALL_ID
Expand Down
6 changes: 6 additions & 0 deletions src/phoenix/server/api/mutations/chat_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,11 @@ def _llm_output_messages(
if text_content:
yield f"{LLM_OUTPUT_MESSAGES}.0.{MESSAGE_CONTENT}", text_content
for tool_call_index, tool_call in enumerate(tool_calls.values()):
if tool_call_id := tool_call.id:
yield (
f"{LLM_OUTPUT_MESSAGES}.0.{MESSAGE_TOOL_CALLS}.{tool_call_index}.{TOOL_CALL_ID}",
tool_call_id,
)
yield (
f"{LLM_OUTPUT_MESSAGES}.0.{MESSAGE_TOOL_CALLS}.{tool_call_index}.{TOOL_CALL_FUNCTION_NAME}",
tool_call.function.name,
Expand Down Expand Up @@ -546,6 +551,7 @@ def _serialize_event(event: SpanException) -> dict[str, Any]:
MESSAGE_ROLE = MessageAttributes.MESSAGE_ROLE
MESSAGE_TOOL_CALLS = MessageAttributes.MESSAGE_TOOL_CALLS

TOOL_CALL_ID = ToolCallAttributes.TOOL_CALL_ID
TOOL_CALL_FUNCTION_NAME = ToolCallAttributes.TOOL_CALL_FUNCTION_NAME
TOOL_CALL_FUNCTION_ARGUMENTS_JSON = ToolCallAttributes.TOOL_CALL_FUNCTION_ARGUMENTS_JSON

Expand Down

0 comments on commit 283c3e9

Please sign in to comment.