Skip to content
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

[editor] Image Output Rendering #744

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { memo } from "react";
import { Image } from "@mantine/core";

type Props = {
mimeType?: string;
content: string;
};

export default memo(function MimeTypeRenderer({ mimeType, content }: Props) {
const mimetype = (mimeType ?? "text/plain").split("/", 1)[0]; // MIME type without subtype
switch (mimetype) {
case "image":
// TODO: Figure out base64 encoding
return <Image alt="Attachment image" src={content} maw={300} />;
default: // "text"
return <span>{content}</span>;
}
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { memo } from "react";
import type { Attachment as InputAttachment, JSONObject } from "aiconfig";
import { PromptInputObjectAttachmentsSchema } from "../../../../utils/promptUtils";
import Attachment from "./Attachment";
import { ActionIcon, Container, Flex, Tooltip } from "@mantine/core";
import { IconEdit, IconTrash } from "@tabler/icons-react";
import AttachmentMetadata from "./AttachmentMetadata";
import MimeTypeRenderer from "../../../MimeTypeRenderer";

type Props = {
schema: PromptInputObjectAttachmentsSchema;
Expand Down Expand Up @@ -39,7 +39,10 @@ export default memo(function AttachmentContainer({
</ActionIcon>
)}
</Flex>
<Attachment attachment={attachment} />
<MimeTypeRenderer
mimeType={attachment.mime_type}
content={attachment.data as string}
/>
{schema.items.properties?.metadata && (
<AttachmentMetadata
schema={schema.items.properties.metadata}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { memo } from "react";
import { TextRenderer } from "../TextRenderer";
import JSONOutput from "./JSONOutput";
import PromptOutputWrapper from "./PromptOutputWrapper";
import MimeTypeRenderer from "../../MimeTypeRenderer";

type Props = {
outputs: Output[];
Expand Down Expand Up @@ -43,6 +44,34 @@ const ExecuteResultOutput = memo(function ExecuteResultOutput({
Object.prototype.hasOwnProperty.call(output.data, "kind")
) {
switch ((output.data as OutputDataWithValue).kind) {
case "file_uri":
return (
<PromptOutputWrapper
copyContent={(output.data as OutputDataWithValue).value as string}
output={output}
withRawJSONToggle
>
<MimeTypeRenderer
mimeType={output.mime_type}
content={(output.data as OutputDataWithValue).value as string}
/>
</PromptOutputWrapper>
);
case "base64":
return (
<PromptOutputWrapper
copyContent={(output.data as OutputDataWithValue).value as string}
output={output}
withRawJSONToggle
>
<MimeTypeRenderer
mimeType={output.mime_type}
content={`data:${output.mime_type};base64, ${
(output.data as OutputDataWithValue).value as string
}`}
/>
</PromptOutputWrapper>
);
// TODO: Tool calls rendering
default:
return (
Expand Down