-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Object Node & GPT Function Node AI Assist, openai structured outputs …
…for chat node
- Loading branch information
Showing
16 changed files
with
832 additions
and
26 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,73 @@ | ||
import { useState, type FC } from 'react'; | ||
import { loadedProjectState } from '../state/savedGraphs'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { revisionStyles } from './GraphRevisionList'; | ||
import Button from '@atlaskit/button'; | ||
import { useProjectRevisions } from '../hooks/useGraphRevisions'; | ||
import { type CalculatedRevision } from '../utils/ProjectRevisionCalculator'; | ||
|
||
export const ProjectRevisions: FC = () => { | ||
const projectState = useRecoilValue(loadedProjectState); | ||
|
||
const [enabled, setEnabled] = useState(false); | ||
|
||
if (!projectState.loaded || !projectState.path) { | ||
return <div>No git history</div>; | ||
} | ||
|
||
if (!enabled) { | ||
return ( | ||
<div css={revisionStyles}> | ||
<Button onClick={() => setEnabled(true)}>Show Revisions</Button> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div css={revisionStyles}> | ||
<ProjectRevisionList /> | ||
</div> | ||
); | ||
}; | ||
|
||
const ProjectRevisionList: FC = () => { | ||
const { revisions, isLoading, stop, resume, numTotalRevisions, numProcessedRevisions } = useProjectRevisions(); | ||
|
||
return ( | ||
<div css={revisionStyles}> | ||
<div className="revisions"> | ||
{revisions.map((revision) => ( | ||
<ProjectRevisionListEntry key={revision.hash} revision={revision} /> | ||
))} | ||
{isLoading ? ( | ||
<div className="loading-area"> | ||
<div> | ||
Loading... ({numProcessedRevisions} / {numTotalRevisions}) | ||
</div> | ||
<Button onClick={() => stop()}>Stop Loading</Button> | ||
</div> | ||
) : ( | ||
<div className="loaded-area"> | ||
<span>Searched {numProcessedRevisions} revisions for changes to graph.</span> | ||
{(numProcessedRevisions < numTotalRevisions || numTotalRevisions === 0) && ( | ||
<Button onClick={() => resume()}>Load More</Button> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export const ProjectRevisionListEntry: FC<{ | ||
revision: CalculatedRevision; | ||
}> = ({ revision }) => { | ||
return ( | ||
<div className="revision"> | ||
<div className="hash"> | ||
<span>{revision.hash.slice(0, 6)}</span> | ||
</div> | ||
<div className="message">{revision.message}</div> | ||
</div> | ||
); | ||
}; |
Empty file.
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
128 changes: 128 additions & 0 deletions
128
packages/app/src/components/editors/custom/GptFunctionJsonSchemaAiAssistEditor.tsx
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,128 @@ | ||
import { useState, type FC } from 'react'; | ||
import { type SharedEditorProps } from '../SharedEditorProps'; | ||
import { | ||
getError, | ||
type ChartNode, | ||
type CustomEditorDefinition, | ||
coreCreateProcessor, | ||
deserializeProject, | ||
coerceTypeOptional, | ||
type GptFunctionNodeData, | ||
} from '@ironclad/rivet-core'; | ||
import { Field } from '@atlaskit/form'; | ||
import TextField from '@atlaskit/textfield'; | ||
import Button from '@atlaskit/button'; | ||
import { css } from '@emotion/react'; | ||
import Select from '@atlaskit/select'; | ||
import { toast } from 'react-toastify'; | ||
import codeGeneratorProject from '../../../../graphs/code-node-generator.rivet-project?raw'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { settingsState } from '../../../state/settings'; | ||
import { fillMissingSettingsFromEnvironmentVariables } from '../../../utils/tauri'; | ||
import { useDependsOnPlugins } from '../../../hooks/useDependsOnPlugins'; | ||
import { marked } from 'marked'; | ||
|
||
const styles = css` | ||
display: flex; | ||
align-items: center; | ||
gap: 8px; | ||
.model-selector { | ||
width: 250px; | ||
} | ||
`; | ||
|
||
const modelOptions = [ | ||
{ label: 'GPT-4o', value: 'gpt-4o' }, | ||
{ label: 'GPT-4o mini', value: 'gpt-4o-mini' }, | ||
]; | ||
|
||
export const GptFunctionNodeJsonSchemaAiAssistEditor: FC< | ||
SharedEditorProps & { | ||
editor: CustomEditorDefinition<ChartNode>; | ||
} | ||
> = ({ node, isReadonly, isDisabled, onChange, editor }) => { | ||
const [prompt, setPrompt] = useState(''); | ||
const [working, setWorking] = useState(false); | ||
const [model, setModel] = useState('gpt-4o-mini'); | ||
|
||
const settings = useRecoilValue(settingsState); | ||
const plugins = useDependsOnPlugins(); | ||
|
||
const data = node.data as GptFunctionNodeData; | ||
|
||
const generateSchema = async () => { | ||
try { | ||
const [project] = deserializeProject(codeGeneratorProject); | ||
const processor = coreCreateProcessor(project, { | ||
graph: 'Structured Outputs JSON Schema Generator', | ||
inputs: { | ||
prompt, | ||
model, | ||
}, | ||
...(await fillMissingSettingsFromEnvironmentVariables(settings, plugins)), | ||
}); | ||
|
||
setWorking(true); | ||
|
||
const outputs = await processor.run(); | ||
|
||
const schema = coerceTypeOptional(outputs.schema, 'string'); | ||
const errorResponse = coerceTypeOptional(outputs.error, 'string'); | ||
|
||
if (errorResponse == null) { | ||
onChange({ | ||
...node, | ||
data: { | ||
...data, | ||
schema: schema ?? '', | ||
} satisfies GptFunctionNodeData, | ||
}); | ||
} else { | ||
const markdownResponse = marked(errorResponse); | ||
toast.info(<div dangerouslySetInnerHTML={{ __html: markdownResponse }}></div>, { | ||
autoClose: false, | ||
containerId: 'wide', | ||
toastId: 'ai-assist-response', | ||
}); | ||
} | ||
} catch (err) { | ||
toast.error(`Failed to generate schema: ${getError(err).message}`); | ||
} finally { | ||
setWorking(false); | ||
} | ||
}; | ||
|
||
const selectedModel = modelOptions.find((option) => option.value === model); | ||
|
||
return ( | ||
<Field name="aiAssist" label="Generate Using AI"> | ||
{() => ( | ||
<div css={styles}> | ||
<TextField | ||
isDisabled={isDisabled || working} | ||
isReadOnly={isReadonly} | ||
value={prompt} | ||
onChange={(e) => setPrompt((e.target as HTMLInputElement).value)} | ||
placeholder="What would you like your schema to be?" | ||
onKeyDown={(e) => { | ||
if (e.key === 'Enter') { | ||
generateSchema(); | ||
} | ||
}} | ||
/> | ||
<Select | ||
options={modelOptions} | ||
value={selectedModel} | ||
onChange={(option) => setModel(option!.value)} | ||
isDisabled={isDisabled || working} | ||
className="model-selector" | ||
/> | ||
<Button appearance="primary" onClick={generateSchema} isDisabled={isDisabled || working}> | ||
Generate | ||
</Button> | ||
</div> | ||
)} | ||
</Field> | ||
); | ||
}; |
Oops, something went wrong.