-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prompts): Implement prompts as code examples beneath prompt (#5843)
* feat(prompts): Implement prompts as code examples beneath prompt - python prompts as code - typescript prompts as code * Implement typescript language formatter for prompts * Align emitted code with openai documentation sample code * Minor UX tweaks wrt code blocks and version details page * Reduce tab size, update prompt mock data * Make code card collapsible * Make prompt code snippets conform to new schemas * Tweak comment * Refactor templates into lodash templates
- Loading branch information
1 parent
7a07c18
commit 879bb0a
Showing
12 changed files
with
727 additions
and
77 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,89 @@ | ||
import React, { useMemo, useState } from "react"; | ||
import { useFragment } from "react-relay"; | ||
import { graphql } from "relay-runtime"; | ||
|
||
import { Accordion, AccordionItem, Card } from "@arizeai/components"; | ||
|
||
import { CopyToClipboardButton, Flex, View } from "@phoenix/components"; | ||
import { | ||
CodeLanguage, | ||
CodeLanguageRadioGroup, | ||
PythonBlock, | ||
TypeScriptBlock, | ||
} from "@phoenix/components/code"; | ||
|
||
import { PromptCodeExportCard__main$key } from "./__generated__/PromptCodeExportCard__main.graphql"; | ||
import { mapPromptToSnippet } from "./promptCodeSnippets"; | ||
|
||
export function PromptCodeExportCard({ | ||
promptVersion, | ||
}: { | ||
promptVersion: PromptCodeExportCard__main$key; | ||
}) { | ||
const [language, setLanguage] = useState<CodeLanguage>("Python"); | ||
const data = useFragment<PromptCodeExportCard__main$key>( | ||
graphql` | ||
fragment PromptCodeExportCard__main on PromptVersion { | ||
invocationParameters | ||
modelName | ||
modelProvider | ||
outputSchema { | ||
schema | ||
} | ||
tools { | ||
definition | ||
} | ||
template { | ||
__typename | ||
... on PromptChatTemplate { | ||
messages { | ||
... on JSONPromptMessage { | ||
role | ||
jsonContent: content | ||
} | ||
... on TextPromptMessage { | ||
role | ||
content | ||
} | ||
} | ||
} | ||
... on PromptStringTemplate { | ||
template | ||
} | ||
} | ||
templateFormat | ||
templateType | ||
} | ||
`, | ||
promptVersion | ||
); | ||
const snippet = useMemo( | ||
() => mapPromptToSnippet({ promptVersion: data, language }), | ||
[data, language] | ||
); | ||
return ( | ||
<Card | ||
title="Code" | ||
variant="compact" | ||
bodyStyle={{ padding: 0 }} | ||
extra={ | ||
<Flex gap="size-100"> | ||
<CodeLanguageRadioGroup language={language} onChange={setLanguage} /> | ||
<CopyToClipboardButton text={snippet} /> | ||
</Flex> | ||
} | ||
> | ||
<Accordion> | ||
<AccordionItem title="Snippet" id="snippet"> | ||
<View padding="size-100"> | ||
{language === "Python" ? ( | ||
<PythonBlock value={snippet} /> | ||
) : language === "TypeScript" ? ( | ||
<TypeScriptBlock value={snippet} /> | ||
) : null} | ||
</View> | ||
</AccordionItem> | ||
</Accordion> | ||
</Card> | ||
); | ||
} |
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
Oops, something went wrong.