Skip to content

Commit

Permalink
[editor] Move Over Client Files & Fix Import Paths (#572)
Browse files Browse the repository at this point in the history
# Move Over Client Files & Fix Import Paths

Copy over all of the client files from existing editor directory. Fix
all imports to relative (we can look into making them absolute again,
just wasn't able to make it work within a few minutes) so that the
modules can be found.

Load the page without any JS errors (spinner showing since no config is
loaded yet due to endpoint being 3000 by default):
![Screenshot 2023-12-21 at 3 14 19
PM](https://github.com/lastmile-ai/aiconfig/assets/5060851/28bdec3b-6f76-49a2-aa37-318f975ae862)



---
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with
[ReviewStack](https://reviewstack.dev/lastmile-ai/aiconfig/pull/572).
* __->__ #572
* #571
  • Loading branch information
rholinshead authored Dec 21, 2023
2 parents 6071e49 + 1869194 commit 1460cfd
Show file tree
Hide file tree
Showing 63 changed files with 4,647 additions and 601 deletions.
13 changes: 13 additions & 0 deletions python/src/aiconfig/editor/client/@types/ufetch.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
declare module "ufetch" {
export namespace ufetch {
function setCookie(key: string, value: string, expiry: number): void;
function getCookie(key: string): string;

function post(path: string, data: any, options?: any);
function get(path: string, options?: any);
function put(path: string, data: any, options?: any);
function _delete(path: string, data: any, options?: any);

export { _delete as delete, setCookie, getCookie, post, get, put };
}
}
53 changes: 32 additions & 21 deletions python/src/aiconfig/editor/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,13 @@
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.68",
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"postbuild": "node postbuild.js",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
Expand All @@ -40,5 +20,36 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"dependencies": {
"@emotion/react": "^11.11.1",
"@mantine/carousel": "^6.0.7",
"@mantine/core": "^6.0.7",
"@mantine/dates": "^6.0.16",
"@mantine/dropzone": "^6.0.7",
"@mantine/form": "^6.0.7",
"@mantine/hooks": "^6.0.7",
"@mantine/modals": "^6.0.7",
"@mantine/notifications": "^6.0.7",
"@mantine/prism": "^6.0.7",
"@tabler/icons-react": "^2.44.0",
"aiconfig": "^1.1.0",
"lodash": "^4.17.21",
"node-fetch": "^3.3.2",
"react": "^18",
"react-dom": "^18",
"react-markdown": "^8.0.6",
"remark-gfm": "^4.0.0",
"ufetch": "^1.6.0",
"react-scripts": "5.0.1"
},
"devDependencies": {
"@types/lodash": "^4.14.202",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.0.2",
"typescript": "^5"
}
}
}
Binary file removed python/src/aiconfig/editor/client/public/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion python/src/aiconfig/editor/client/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>AIConfig Editor</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
Binary file removed python/src/aiconfig/editor/client/public/logo192.png
Binary file not shown.
Binary file removed python/src/aiconfig/editor/client/public/logo512.png
Binary file not shown.
23 changes: 3 additions & 20 deletions python/src/aiconfig/editor/client/public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"short_name": "AIConfig Editor",
"name": "Editor for AIConfig JSON files",
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
}
38 changes: 0 additions & 38 deletions python/src/aiconfig/editor/client/src/App.css

This file was deleted.

9 changes: 0 additions & 9 deletions python/src/aiconfig/editor/client/src/App.test.tsx

This file was deleted.

26 changes: 0 additions & 26 deletions python/src/aiconfig/editor/client/src/App.tsx

This file was deleted.

48 changes: 48 additions & 0 deletions python/src/aiconfig/editor/client/src/Editor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import EditorContainer from "./components/EditorContainer";
import { ClientAIConfig } from "./shared/types";
import { Flex, Loader } from "@mantine/core";
import { AIConfig } from "aiconfig";
import { useCallback, useEffect, useState } from "react";
import { ufetch } from "ufetch";

export default function Editor() {
const [aiconfig, setAiConfig] = useState<ClientAIConfig | undefined>();

const loadConfig = useCallback(async () => {
const res = await ufetch.post(`/api/load`, {});

setAiConfig(res.aiconfig);
}, []);

useEffect(() => {
loadConfig();
}, [loadConfig]);

const onBackNavigation = useCallback(() => {
// TODO: Handle file back navigation
}, []);

const onSave = useCallback(async (aiconfig: AIConfig) => {
const res = await ufetch.post(`/api/aiconfig/save`, {
// path: file path,
aiconfig,
});
return res;
}, []);

return (
<div>
{!aiconfig ? (
<Flex justify="center" mt="xl">
<Loader size="xl" />
</Flex>
) : (
<EditorContainer
aiconfig={aiconfig}
onBackNavigation={onBackNavigation}
onSave={onSave}
/>
)}
</div>
);
}
109 changes: 109 additions & 0 deletions python/src/aiconfig/editor/client/src/components/EditorContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import PromptContainer from "./prompt/PromptContainer";
import { Container, Group, Button, createStyles } from "@mantine/core";
import { showNotification } from "@mantine/notifications";
import { AIConfig, PromptInput } from "aiconfig";
import { useCallback, useReducer, useState } from "react";
import aiconfigReducer from "./aiconfigReducer";
import { ClientAIConfig, clientConfigToAIConfig } from "../shared/types";

type Props = {
aiconfig: ClientAIConfig;
onBackNavigation: () => void;
onSave: (aiconfig: AIConfig) => Promise<void>;
};

const useStyles = createStyles((theme) => ({
promptsContainer: {
[theme.fn.smallerThan("sm")]: {
padding: "0 0 200px 0",
},
paddingBottom: 400,
},
}));

export default function EditorContainer({
aiconfig: initialAIConfig,
onBackNavigation,
onSave,
}: Props) {
const [isSaving, setIsSaving] = useState(false);
const [aiconfigState, dispatch] = useReducer(
aiconfigReducer,
initialAIConfig
);

const save = useCallback(async () => {
setIsSaving(true);
try {
await onSave(clientConfigToAIConfig(aiconfigState));
} catch (err: any) {
showNotification({
title: "Error saving",
message: err.message,
color: "red",
});
} finally {
setIsSaving(false);
}
}, [aiconfigState, onSave]);

const onChangePromptInput = useCallback(
async (promptIndex: number, newPromptInput: PromptInput) => {
dispatch({
type: "UPDATE_PROMPT_INPUT",
index: promptIndex,
input: newPromptInput,
});
// TODO: Call server-side endpoint to update prompt input
},
[dispatch]
);

const onUpdatePromptModelSettings = useCallback(
async (promptIndex: number, newModelSettings: any) => {
dispatch({
type: "UPDATE_PROMPT_MODEL_SETTINGS",
index: promptIndex,
modelSettings: newModelSettings,
});
// TODO: Call server-side endpoint to update model settings
},
[dispatch]
);

const { classes } = useStyles();

// TODO: Implement editor context for callbacks, readonly state, etc.

return (
<>
<Container maw="80rem">
<Group grow m="sm">
<Button onClick={onBackNavigation} variant="default" mr="lg">
Back
</Button>
{/* <Text sx={{ textOverflow: "ellipsis", overflow: "hidden" }} size={14}>
{path || "No path specified"}
</Text> */}
<Button loading={isSaving} ml="lg" onClick={save}>
Save
</Button>
</Group>
</Container>
<Container maw="80rem" className={classes.promptsContainer}>
{aiconfigState.prompts.map((prompt: any, i: number) => {
return (
<PromptContainer
index={i}
prompt={prompt}
key={prompt.name}
onChangePromptInput={onChangePromptInput}
onUpdateModelSettings={onUpdatePromptModelSettings}
defaultConfigModelName={aiconfigState.metadata.default_model}
/>
);
})}
</Container>
</>
);
}
Loading

0 comments on commit 1460cfd

Please sign in to comment.