-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement "Move Output" button on Playground Output (#5509)
* feat: Implement "Move Output" button to Playground Output This allows users to copy a desireable result from the playground back into their conversation, to continue iteration * Convert moved tool calls into the correct provider schema
- Loading branch information
1 parent
38f8f56
commit aa8c283
Showing
2 changed files
with
120 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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,93 @@ | ||
import React from "react"; | ||
|
||
import { | ||
Button, | ||
Icon, | ||
Icons, | ||
Tooltip, | ||
TooltipTrigger, | ||
} from "@arizeai/components"; | ||
|
||
import { usePlaygroundContext } from "@phoenix/contexts/PlaygroundContext"; | ||
import { | ||
ChatMessage, | ||
generateMessageId, | ||
PlaygroundInstance, | ||
} from "@phoenix/store"; | ||
import { safelyParseJSON } from "@phoenix/utils/jsonUtils"; | ||
|
||
import { PartialOutputToolCall } from "./PlaygroundToolCall"; | ||
import { | ||
convertMessageToolCallsToProvider, | ||
getChatRole, | ||
} from "./playgroundUtils"; | ||
|
||
export const PlaygroundOutputMoveButton = ({ | ||
instance, | ||
outputContent, | ||
toolCalls, | ||
cleanupOutput, | ||
}: { | ||
instance: PlaygroundInstance; | ||
outputContent?: string | ChatMessage[]; | ||
toolCalls: PartialOutputToolCall[]; | ||
cleanupOutput: () => void; | ||
}) => { | ||
const instanceId = instance.id; | ||
const updateInstance = usePlaygroundContext((state) => state.updateInstance); | ||
return ( | ||
<TooltipTrigger delay={500} offset={10}> | ||
<Button | ||
variant="default" | ||
size="compact" | ||
icon={<Icon svg={<Icons.PlusCircleOutline />} />} | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
if (instance.template.__type !== "chat") { | ||
return; | ||
} | ||
const messages = Array.isArray(outputContent) | ||
? outputContent | ||
: outputContent | ||
? [ | ||
{ | ||
id: generateMessageId(), | ||
role: getChatRole("ai"), | ||
content: outputContent, | ||
}, | ||
] | ||
: []; | ||
if (toolCalls.length > 0) { | ||
messages.push({ | ||
id: generateMessageId(), | ||
role: getChatRole("ai"), | ||
toolCalls: convertMessageToolCallsToProvider({ | ||
provider: instance.model.provider, | ||
toolCalls: toolCalls.map((tc) => ({ | ||
...tc, | ||
function: { | ||
...tc.function, | ||
arguments: | ||
safelyParseJSON(tc.function.arguments)?.json ?? | ||
tc.function.arguments, | ||
}, | ||
})), | ||
}), | ||
}); | ||
} | ||
updateInstance({ | ||
instanceId, | ||
patch: { | ||
template: { | ||
__type: "chat", | ||
messages: [...instance.template.messages, ...messages], | ||
}, | ||
}, | ||
}); | ||
cleanupOutput(); | ||
}} | ||
/> | ||
<Tooltip>Move Output message to the end of Prompt</Tooltip> | ||
</TooltipTrigger> | ||
); | ||
}; |