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

[AiConfig Branded Editor] #777

Merged
merged 1 commit into from
Jan 5, 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
Binary file modified .DS_Store
Binary file not shown.
16 changes: 9 additions & 7 deletions cookbooks/Getting-Started/travel.aiconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "NYC Trip Planner",
"description": "Intrepid explorer with ChatGPT and AIConfig",
"schema_version": "latest",
"metadata": {
"parameters": {},
"models": {
"gpt-3.5-turbo": {
"model": "gpt-3.5-turbo",
Expand All @@ -17,10 +17,12 @@
},
"default_model": "gpt-3.5-turbo"
},
"description": "Intrepid explorer with ChatGPT and AIConfig",
"prompts": [
{
"name": "get_activities",
"input": "Tell me 10 fun attractions to do in NYC."
"input": "Tell me 10 fun attractions to do in NYC.",
"outputs": []
},
{
"name": "gen_itinerary",
Expand All @@ -30,9 +32,9 @@
"parameters": {
"order_by": "geographic location"
}
}
},
"outputs": []
}
]
}


],
"$schema": "https://json.schemastore.org/aiconfig-1.0"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 113 additions & 3 deletions python/src/aiconfig/editor/client/src/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import EditorContainer, {
AIConfigCallbacks,
} from "./components/EditorContainer";
import { Flex, Loader, MantineProvider } from "@mantine/core";
import { Flex, Loader, MantineProvider, Image } from "@mantine/core";
import { AIConfig, InferenceSettings, JSONObject, Prompt } from "aiconfig";
import { useCallback, useEffect, useMemo, useState } from "react";
import { ufetch } from "ufetch";
Expand Down Expand Up @@ -141,8 +141,118 @@ export default function Editor() {
);

return (
<div>
<MantineProvider withGlobalStyles withNormalizeCSS>
<div className="editorBackground">
<MantineProvider
withGlobalStyles
withNormalizeCSS
theme={{
colorScheme: "dark",

headings: {
fontFamily:
"system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, Arial, sans-serif",
sizes: {
h1: { fontSize: "2rem" },
},
},

defaultGradient: {
from: "pink",
to: "pink",
deg: 45,
},

globalStyles: (theme) => ({
".editorBackground": {
background:
"radial-gradient(ellipse at top,#08122d,#030712),radial-gradient(ellipse at bottom,#030712,#030712)",
margin: "0 auto",
minHeight: "100vh",
},
".monoFont": {
fontFamily:
"sf mono, ui-monospace, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace",
},
".ghost": {
border: "none",
borderRadius: "4px",
padding: "4px",
margin: "0px",
backgroundColor: "transparent",
":hover": {
backgroundColor: "rgba(226,232,255,.1)",
},
input: {
maxHeight: "16px",
fontFamily:
"sf mono, ui-monospace, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace",
},
},
".cellStyle": {
border: "1px solid rgba(226,232,255,.1) !important",
background: "rgb(12 21 57 / 10%)",
flex: 1,
borderTopRightRadius: "0px",
borderBottomRightRadius: "0px",
":hover": {
background: "rgba(255, 255, 255, 0.03) !important",
},
textarea: {
border: "1px solid rgba(226,232,255,.1)",
backgroundColor: "#060c21",
":focus": {
outline: "solid 1px #ff1cf7 !important",
outlineOffset: "-1px",
},
},
},
".sidePanel": {
border: "1px solid rgba(226,232,255,.1)",
borderLeft: "none",
borderTopRightRadius: "4px",
borderBottomRightRadius: "4px",
input: {
border: "1px solid rgba(226,232,255,.1)",
backgroundColor: "#060c21",
":focus": {
outline: "solid 1px #ff1cf7 !important",
outlineOffset: "-1px",
},
},
},
".divider": {
borderTopWidth: "1px",
borderTopColor: "rgba(226,232,255,.1)",
marginBottom: "0.5em",
},
".runPromptButton": {
background: "#ff1cf7",
color: "white",
borderRadius: "0",
height: "auto",
},
".actionTabsPanel": {
width: "400px",
},
".logo": {
maxWidth: "80rem",
margin: "0 auto",
padding: "32px 0 0 32px",
display: "flex",
justifyContent: "space-between",
alignItems: "center",
},
}),
}}
>
<div className="logo">
<Image
withPlaceholder
maw={140}
src="images/aiconfigLogo.png"
alt="AiConfig Logo"
/>
</div>
{!aiconfig ? (
<Flex justify="center" mt="xl">
<Loader size="xl" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,16 +676,16 @@ export default function EditorContainer({
<Tooltip
label={isDirty ? "Save changes to config" : "No unsaved changes"}
>
<div>
<Button
leftIcon={<IconDeviceFloppy />}
loading={isSaving}
onClick={onSave}
disabled={!isDirty}
>
Save
</Button>
</div>
<Button
leftIcon={<IconDeviceFloppy />}
loading={isSaving}
onClick={onSave}
disabled={!isDirty}
size="xs"
variant="gradient"
>
Save
</Button>
</Tooltip>
</Flex>
<ConfigNameDescription
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ export default memo(function ModelSelector({
<Autocomplete
placeholder="Select model"
limit={100}
className="ghost"
variant="unstyled"
maxDropdownHeight={200}
rightSection={
selectedModel ? (
<Button
size="xs"
variant="subtle"
className="ghost"
mr={10}
onClick={() => {
onSelectModel(undefined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default memo(function PromptActionBar({
)}
</Tabs.List>

<Tabs.Panel value="settings">
<Tabs.Panel value="settings" className="actionTabsPanel">
<ModelSettingsRenderer
settings={getModelSettings(prompt)}
schema={modelSettingsSchema}
Expand All @@ -79,7 +79,7 @@ export default memo(function PromptActionBar({
</Tabs.Panel>

{checkParametersSupported(prompt) && (
<Tabs.Panel value="parameters">
<Tabs.Panel value="parameters" className="actionTabsPanel">
<ParametersRenderer
initialValue={getPromptParameters(prompt)}
onUpdateParameters={onUpdateParameters}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PromptInputRenderer from "./prompt_input/PromptInputRenderer";
import PromptOutputsRenderer from "./prompt_outputs/PromptOutputsRenderer";
import { ClientPrompt } from "../../shared/types";
import { getPromptSchema } from "../../utils/promptUtils";
import { Flex, Card, createStyles } from "@mantine/core";
import { Flex, Card } from "@mantine/core";
import { PromptInput as AIConfigPromptInput, JSONObject } from "aiconfig";
import { memo, useCallback } from "react";
import PromptOutputBar from "./PromptOutputBar";
Expand Down Expand Up @@ -31,21 +31,6 @@ type Props = {
defaultConfigModelName?: string;
};

const useStyles = createStyles((theme) => ({
promptInputCard: {
flex: 1,
borderRight: "0 !important",
borderBottomRightRadius: 0,
borderTopRightRadius: 0,
},
actionBar: {
border: `1px solid ${theme.colors.gray[3]}`,
borderRadius: "0.25em",
borderBottomLeftRadius: 0,
borderTopLeftRadius: 0,
},
}));

export default memo(function PromptContainer({
prompt,
getModels,
Expand Down Expand Up @@ -96,11 +81,9 @@ export default memo(function PromptContainer({
const promptSchema = getPromptSchema(prompt, defaultConfigModelName);
const inputSchema = promptSchema?.input;

const { classes } = useStyles();

return (
<Flex justify="space-between" w="100%">
<Card withBorder className={classes.promptInputCard}>
<Card withBorder className="cellStyle">
<Flex direction="column">
<Flex justify="space-between" mb="0.5em">
<PromptName
Expand All @@ -124,7 +107,7 @@ export default memo(function PromptContainer({
{prompt.outputs && <PromptOutputsRenderer outputs={prompt.outputs} />}
</Flex>
</Card>
<div className={classes.actionBar}>
<div className="sidePanel">
<PromptActionBar
prompt={prompt}
promptSchema={promptSchema}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export default memo(function PromptName({ promptId, name, onUpdate }: Props) {
return (
<TextInput
value={nameInput}
className="ghost"
variant="unstyled"
placeholder="Name this prompt"
onChange={onChange}
error={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { memo } from "react";
export default memo(function PromptOutputBar() {
return (
<Flex direction="column" mt="0.5em">
<Divider size="sm" mt="0.5em" mb="0.5em" />
<Text color="dimmed">Output</Text>
<Divider size="sm" className="divider" />
<Text color="dimmed" size={"xs"} className="monoFont">
Output
</Text>
{/* TODO: Add output metrics */}
</Flex>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, createStyles, Loader, Text } from "@mantine/core";
import { Button, Loader, Text } from "@mantine/core";
import { IconPlayerPlayFilled, IconPlayerStop } from "@tabler/icons-react";
import { memo } from "react";

Expand All @@ -8,28 +8,19 @@ type Props = {
size: "compact" | "full";
};

const useStyles = createStyles(() => ({
executeButton: {
borderBottomLeftRadius: 0,
borderTopLeftRadius: 0,
borderTopRightRadius: 0,
},
}));

export default memo(function RunPromptButton({
runPrompt,
size,
isRunning = false,
}: Props) {
const { classes } = useStyles();
return (
<Button
onClick={runPrompt}
disabled={isRunning}
p="xs"
size="xs"
fullWidth={size === "full"}
className={classes.executeButton}
className="runPromptButton"
>
{isRunning ? (
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ export default memo(function PromptInputRenderer({
const [isRawJSON, setIsRawJSON] = useState(false);
return (
<>
<Flex justify="flex-end">
<Tooltip label="Toggle JSON editor" withArrow>
<ActionIcon onClick={() => setIsRawJSON((curr) => !curr)}>
{isRawJSON ? (
<IconBracesOff size="1rem" />
) : (
<IconBraces size="1rem" />
)}
</ActionIcon>
</Tooltip>
</Flex>
{isRawJSON ? (
<PromptInputJSONRenderer input={input} onChangeInput={onChangeInput} />
) : schema ? (
Expand All @@ -46,6 +35,17 @@ export default memo(function PromptInputRenderer({
onChangeInput={onChangeInput}
/>
)}
<Flex justify="flex-end">
<Tooltip label="Toggle JSON editor" withArrow>
<ActionIcon onClick={() => setIsRawJSON((curr) => !curr)}>
{isRawJSON ? (
<IconBracesOff size="1rem" />
) : (
<IconBraces size="1rem" />
)}
</ActionIcon>
</Tooltip>
</Flex>
</>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default memo(function PromptInputSchemaRenderer(props: Props) {
value={props.input}
onChange={(e) => props.onChangeInput(e.target.value)}
placeholder="Type a prompt"
autosize
/>
);
} else {
Expand Down