-
Notifications
You must be signed in to change notification settings - Fork 22
feat: map legacy conversational eval inputs and outputs #1276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shannonsuhendra
wants to merge
16
commits into
main
Choose a base branch
from
feat/conversational-evals
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+858
−2
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c4d83ff
feat: get conversational output and map to eval output
shannonsuhendra 4e0872c
Merge branch 'main' into feat/conversational-evals
maxduu 344dc58
Merge branch 'main' into feat/conversational-evals
maxduu f9fa507
Merge branch 'main' into feat/conversational-evals
maxduu 24ac544
feat(temp): preliminary eval mapper changes
maxduu 64fdd48
Merge branch 'main' into feat/conversational-evals
maxduu c225c79
feat: map legacy conversation eval inputs and outputs
maxduu 7086fe7
fix: remove logs
maxduu b271a94
Merge branch 'main' into feat/conversational-evals
maxduu 81aa04b
Merge branch 'main' into feat/conversational-evals
maxduu 10cf34f
fix: attachment aliases
maxduu 9c6cd46
feat: add tests for conversational_utils
maxduu 27df9df
fix: test mypy issues
maxduu dc93263
fix: add tests and handle empty content
maxduu dd669d6
Merge branch 'main' into feat/conversational-evals
maxduu fe731c0
chore: update version
maxduu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,289 @@ | ||
| import uuid | ||
| from datetime import datetime, timezone | ||
| from typing import Any, List, Literal | ||
|
|
||
| from pydantic import BaseModel, Field | ||
| from uipath.core.chat import ( | ||
| UiPathConversationContentPart, | ||
| UiPathConversationContentPartData, | ||
| UiPathConversationMessage, | ||
| UiPathConversationMessageData, | ||
| UiPathConversationToolCall, | ||
| UiPathConversationToolCallData, | ||
| UiPathConversationToolCallResult, | ||
| UiPathInlineValue, | ||
| ) | ||
|
|
||
| # Types for legacy conversational-agent evaluation input/outputs. | ||
|
|
||
|
|
||
| class LegacyConversationalEvalJobAttachmentReference(BaseModel): | ||
| """File attachment reference in eval messages.""" | ||
|
|
||
| id: str = Field(..., alias="ID") | ||
| full_name: str = Field(..., alias="FullName") | ||
| mime_type: str = Field(..., alias="MimeType") | ||
|
|
||
|
|
||
| class LegacyConversationalEvalOutputToolCall(BaseModel): | ||
| """Tool call in eval output schema (no result field).""" | ||
|
|
||
| name: str | ||
| arguments: dict[str, Any] | ||
|
|
||
|
|
||
| class LegacyConversationalEvalInputToolCallResult(BaseModel): | ||
| """Tool call result in eval input schema.""" | ||
|
|
||
| value: Any | ||
| is_error: bool | None = Field(default=None, alias="isError") | ||
|
|
||
|
|
||
| class LegacyConversationalEvalInputToolCall(LegacyConversationalEvalOutputToolCall): | ||
| """Tool call in eval input schema (extends output tool call with result).""" | ||
|
|
||
| result: LegacyConversationalEvalInputToolCallResult | ||
|
|
||
|
|
||
| class LegacyConversationalEvalMessage(BaseModel): | ||
| """Base eval message type.""" | ||
|
|
||
| role: Literal["agent", "user"] | ||
| text: str | ||
|
|
||
|
|
||
| class LegacyConversationalEvalUserMessage(LegacyConversationalEvalMessage): | ||
| """User message in eval schema.""" | ||
|
|
||
| role: Literal["user"] = "user" | ||
| attachments: list[LegacyConversationalEvalJobAttachmentReference] | None = Field( | ||
| default=None | ||
| ) | ||
|
|
||
|
|
||
| class LegacyConversationalEvalInputAgentMessage(LegacyConversationalEvalMessage): | ||
| """Agent message in eval input schema (input tool-calls contain results field).""" | ||
|
|
||
| role: Literal["agent"] = "agent" | ||
| tool_calls: list[LegacyConversationalEvalInputToolCall] | None = Field( | ||
| default=None, alias="toolCalls" | ||
| ) | ||
|
|
||
|
|
||
| class LegacyConversationalEvalOutputAgentMessage(LegacyConversationalEvalMessage): | ||
| """Agent message in eval output schema (output tool-calls don't contain result field).""" | ||
|
|
||
| role: Literal["agent"] = "agent" | ||
| tool_calls: list[LegacyConversationalEvalOutputToolCall] | None = Field( | ||
| default=None, alias="toolCalls" | ||
| ) | ||
|
|
||
|
|
||
| class LegacyConversationalEvalInput(BaseModel): | ||
| """Complete conversational eval input schema. | ||
|
|
||
| conversationHistory: Array of exchanges, where each exchange is | ||
| [userMessage, ...agentMessages[]] | ||
| currentUserPrompt: The current user message to evaluate | ||
| """ | ||
|
|
||
| conversation_history: list[ | ||
| list[ | ||
| LegacyConversationalEvalUserMessage | ||
| | LegacyConversationalEvalInputAgentMessage | ||
| ] | ||
| ] = Field(alias="conversationHistory") | ||
| current_user_prompt: LegacyConversationalEvalUserMessage = Field( | ||
| alias="currentUserPrompt" | ||
| ) | ||
|
|
||
|
|
||
| class LegacyConversationalEvalOutput(BaseModel): | ||
| """Complete eval output schema matching TypeScript definition. | ||
|
|
||
| agentResponse: Sequence of agent messages ending with a message without tool calls | ||
| """ | ||
|
|
||
| agent_response: list[LegacyConversationalEvalOutputAgentMessage] = Field( | ||
| alias="agentResponse" | ||
| ) | ||
|
|
||
|
|
||
| # Mapper functions to convert between UiPath standard Message format and legacy conversational formats | ||
|
|
||
|
|
||
| class UiPathLegacyEvalChatMessagesMapper: | ||
| @staticmethod | ||
| def legacy_conversational_eval_input_to_uipath_message_list( | ||
| eval_input: LegacyConversationalEvalInput, | ||
| ) -> List[UiPathConversationMessage]: | ||
| """Convert legacy eval input format to list of UiPathConversationMessage.""" | ||
| messages: List[UiPathConversationMessage] = [] | ||
| timestamp = ( | ||
| datetime.now(timezone.utc) | ||
| .isoformat(timespec="milliseconds") | ||
| .replace("+00:00", "Z") | ||
| ) | ||
|
|
||
| # Process conversation history (list of exchanges) | ||
| for eval_exchange in eval_input.conversation_history: | ||
| for eval_message in eval_exchange: | ||
| if eval_message.role == "user": | ||
| # Convert user message | ||
| content_parts = ( | ||
| [ | ||
| UiPathConversationContentPart( | ||
| content_part_id=str(uuid.uuid4()), | ||
| mime_type="text/plain", | ||
| data=UiPathInlineValue(inline=eval_message.text), | ||
| citations=[], | ||
| created_at=timestamp, | ||
| updated_at=timestamp, | ||
| ) | ||
| ] | ||
| if eval_message.text | ||
| else [] | ||
| ) | ||
|
|
||
| # TODO: Add attachments if present | ||
| # if message.attachments: | ||
| # for attachment in message.attachments: | ||
| # content_parts.append( | ||
| # UiPathConversationContentPart(...) | ||
| # ) | ||
|
|
||
| messages.append( | ||
| UiPathConversationMessage( | ||
| message_id=str(uuid.uuid4()), | ||
| role="user", | ||
| content_parts=content_parts, | ||
| tool_calls=[], | ||
| interrupts=[], | ||
| created_at=timestamp, | ||
| updated_at=timestamp, | ||
| ) | ||
| ) | ||
| elif eval_message.role == "agent": | ||
| # Convert agent message | ||
| content_parts = ( | ||
| [ | ||
| UiPathConversationContentPart( | ||
| content_part_id=str(uuid.uuid4()), | ||
| mime_type="text/markdown", | ||
| data=UiPathInlineValue(inline=eval_message.text), | ||
| citations=[], | ||
| created_at=timestamp, | ||
| updated_at=timestamp, | ||
| ) | ||
| ] | ||
| if eval_message.text | ||
| else [] | ||
| ) | ||
|
|
||
| # Convert tool calls if present | ||
| tool_calls: List[UiPathConversationToolCall] = [] | ||
| if eval_message.tool_calls: | ||
| for tc in eval_message.tool_calls: | ||
| tool_call = UiPathConversationToolCall( | ||
| tool_call_id=str(uuid.uuid4()), | ||
| name=tc.name, | ||
| input=tc.arguments, | ||
| timestamp=timestamp, | ||
| result=UiPathConversationToolCallResult( | ||
| timestamp=timestamp, | ||
| output=tc.result.value, | ||
| is_error=tc.result.is_error, | ||
| ), | ||
| created_at=timestamp, | ||
| updated_at=timestamp, | ||
| ) | ||
| tool_calls.append(tool_call) | ||
|
|
||
| messages.append( | ||
| UiPathConversationMessage( | ||
| message_id=str(uuid.uuid4()), | ||
| role="assistant", | ||
| content_parts=content_parts, | ||
| tool_calls=tool_calls, | ||
| interrupts=[], | ||
| created_at=timestamp, | ||
| updated_at=timestamp, | ||
| ) | ||
| ) | ||
|
|
||
| # Add current user prompt | ||
| content_parts = ( | ||
| [ | ||
| UiPathConversationContentPart( | ||
| content_part_id=str(uuid.uuid4()), | ||
| mime_type="text/plain", | ||
| data=UiPathInlineValue(inline=eval_input.current_user_prompt.text), | ||
| citations=[], | ||
| created_at=timestamp, | ||
| updated_at=timestamp, | ||
| ) | ||
| ] | ||
| if eval_input.current_user_prompt.text | ||
| else [] | ||
| ) | ||
|
|
||
| # TODO Add attachments if present | ||
| # if eval_input.current_user_prompt.attachments: | ||
| # for attachment in eval_input.current_user_prompt.attachments: | ||
| # content_parts.append( | ||
| # UiPathConversationContentPart(...) | ||
| # ) | ||
|
|
||
| messages.append( | ||
| UiPathConversationMessage( | ||
| message_id=str(uuid.uuid4()), | ||
| role="user", | ||
| content_parts=content_parts, | ||
| tool_calls=[], | ||
| interrupts=[], | ||
| created_at=timestamp, | ||
| updated_at=timestamp, | ||
| ) | ||
| ) | ||
|
|
||
| return messages | ||
|
|
||
| @staticmethod | ||
| def legacy_conversational_eval_output_to_uipath_message_data_list( | ||
| eval_output: LegacyConversationalEvalOutput, | ||
| ) -> List[UiPathConversationMessageData]: | ||
| """Convert legacy eval output format to list of UiPathConversationMessageData.""" | ||
| messages: List[UiPathConversationMessageData] = [] | ||
|
|
||
| for eval_agent_message in eval_output.agent_response: | ||
| content_parts = ( | ||
| [ | ||
| UiPathConversationContentPartData( | ||
| mime_type="text/markdown", | ||
| data=UiPathInlineValue(inline=eval_agent_message.text), | ||
| citations=[], | ||
| ) | ||
| ] | ||
| if eval_agent_message.text | ||
| else [] | ||
| ) | ||
|
|
||
| tool_calls: List[UiPathConversationToolCallData] = [] | ||
| if eval_agent_message.tool_calls: | ||
| for tc in eval_agent_message.tool_calls: | ||
| tool_call = UiPathConversationToolCallData( | ||
| name=tc.name, | ||
| input=tc.arguments, | ||
| ) | ||
| tool_calls.append(tool_call) | ||
|
|
||
| messages.append( | ||
| UiPathConversationMessageData( | ||
| role="assistant", | ||
| content_parts=content_parts, | ||
| tool_calls=tool_calls, | ||
| interrupts=[], | ||
| ) | ||
| ) | ||
|
|
||
| return messages | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @norman-le to add after this PR.