mirror of
https://github.com/ianarawjo/ChainForge.git
synced 2025-03-14 16:26:45 +00:00
Immediate bug fix when extending ChainForge examples that were created before the new OpenAI 'functions' feature (#77)
* Fix bug in call_chatgpt * Bug fix and add New Flow button
This commit is contained in:
parent
ea3d730bba
commit
4bd5c15e82
@ -60,11 +60,11 @@ async def call_chatgpt(prompt: str, model: LLM, n: int = 1, temperature: float=
|
||||
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
||||
|
||||
model = model.value
|
||||
if 'stop' in params and not isinstance(params['stop'], list) or len(params['stop']) == 0:
|
||||
if 'stop' in params and (not isinstance(params['stop'], list) or len(params['stop']) == 0):
|
||||
del params['stop']
|
||||
if 'functions' in params and not isinstance(params['functions'], list) or len(params['functions']) == 0:
|
||||
if 'functions' in params and (not isinstance(params['functions'], list) or len(params['functions']) == 0):
|
||||
del params['functions']
|
||||
if 'function_call' in params and not isinstance(params['function_call'], str) or len(params['function_call'].strip()) == 0:
|
||||
if 'function_call' in params and (not isinstance(params['function_call'], str) or len(params['function_call'].strip()) == 0):
|
||||
del params['function_call']
|
||||
|
||||
print(f"Querying OpenAI model '{model}' with prompt '{prompt}'...")
|
||||
|
@ -1,15 +1,15 @@
|
||||
{
|
||||
"files": {
|
||||
"main.css": "/static/css/main.e7a9f023.css",
|
||||
"main.js": "/static/js/main.082194ef.js",
|
||||
"main.js": "/static/js/main.c2936487.js",
|
||||
"static/js/787.4c72bb55.chunk.js": "/static/js/787.4c72bb55.chunk.js",
|
||||
"index.html": "/index.html",
|
||||
"main.e7a9f023.css.map": "/static/css/main.e7a9f023.css.map",
|
||||
"main.082194ef.js.map": "/static/js/main.082194ef.js.map",
|
||||
"main.c2936487.js.map": "/static/js/main.c2936487.js.map",
|
||||
"787.4c72bb55.chunk.js.map": "/static/js/787.4c72bb55.chunk.js.map"
|
||||
},
|
||||
"entrypoints": [
|
||||
"static/css/main.e7a9f023.css",
|
||||
"static/js/main.082194ef.js"
|
||||
"static/js/main.c2936487.js"
|
||||
]
|
||||
}
|
@ -1 +1 @@
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Chainforge</title><script defer="defer" src="/static/js/main.082194ef.js"></script><link href="/static/css/main.e7a9f023.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Chainforge</title><script defer="defer" src="/static/js/main.c2936487.js"></script><link href="/static/css/main.e7a9f023.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
36
chainforge/react-server/src/App.js
vendored
36
chainforge/react-server/src/App.js
vendored
@ -21,6 +21,7 @@ import CsvNode from './CsvNode';
|
||||
import TabularDataNode from './TabularDataNode';
|
||||
import GlobalSettingsModal from './GlobalSettingsModal';
|
||||
import ExampleFlowsModal from './ExampleFlowsModal';
|
||||
import AreYouSureModal from './AreYouSureModal';
|
||||
import './text-fields-node.css';
|
||||
|
||||
// State management (from https://reactflow.dev/docs/guides/state-management/)
|
||||
@ -69,6 +70,12 @@ const App = () => {
|
||||
// For modal popup of example flows
|
||||
const examplesModal = useRef(null);
|
||||
|
||||
// For confirmation popup
|
||||
const confirmationModal = useRef(null);
|
||||
const [confirmationDialogProps, setConfirmationDialogProps] = useState({
|
||||
title: 'Confirm action', message: 'Are you sure?', onConfirm: () => {}
|
||||
});
|
||||
|
||||
// For displaying error messages to user
|
||||
const alertModal = useRef(null);
|
||||
|
||||
@ -162,6 +169,18 @@ const App = () => {
|
||||
URL.revokeObjectURL(downloadLink.href);
|
||||
};
|
||||
|
||||
const resetFlow = useCallback(() => {
|
||||
resetLLMColors();
|
||||
|
||||
const uid = (id) => `${id}-${Date.now()}`;
|
||||
const starting_nodes = [
|
||||
{ id: uid('prompt'), type: 'prompt', data: { prompt: 'Why is the sky blue?', n: 1 }, position: { x: 450, y: 200 } },
|
||||
{ id: uid('textfields'), type: 'textfields', data: {}, position: { x: 80, y: 270 } },
|
||||
];
|
||||
|
||||
setNodes(starting_nodes);
|
||||
setEdges([]);
|
||||
}, [setNodes, setEdges, resetLLMColors]);
|
||||
const saveFlow = useCallback(() => {
|
||||
if (!rfInstance) return;
|
||||
const flow = rfInstance.toObject();
|
||||
@ -352,12 +371,26 @@ const App = () => {
|
||||
}, handleError).catch(handleError);
|
||||
};
|
||||
|
||||
// When the user clicks the 'New Flow' button
|
||||
const onClickNewFlow = useCallback(() => {
|
||||
setConfirmationDialogProps({
|
||||
title: 'Create a new flow',
|
||||
message: 'Are you sure? Any unexported changes to your existing flow will be lost.',
|
||||
onConfirm: () => resetFlow(), // Set the callback if user confirms action
|
||||
});
|
||||
|
||||
// Trigger the 'are you sure' modal:
|
||||
if (confirmationModal && confirmationModal.current)
|
||||
confirmationModal.current.trigger();
|
||||
}, [confirmationModal, resetFlow, setConfirmationDialogProps]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<GlobalSettingsModal ref={settingsModal} />
|
||||
<AlertModal ref={alertModal} />
|
||||
<LoadingOverlay visible={isLoading} overlayBlur={1} />
|
||||
<ExampleFlowsModal ref={examplesModal} onSelect={onSelectExampleFlow} />
|
||||
<AreYouSureModal ref={confirmationModal} title={confirmationDialogProps.title} message={confirmationDialogProps.message} onConfirm={confirmationDialogProps.onConfirm} />
|
||||
<div style={{ height: '100vh', width: '100%', backgroundColor: '#eee' }}>
|
||||
<ReactFlow
|
||||
onNodesChange={onNodesChange}
|
||||
@ -403,8 +436,9 @@ const App = () => {
|
||||
<Button onClick={importFlowFromFile} size="sm" variant="outline" compact>Import</Button>
|
||||
</div>
|
||||
<div style={{position: 'fixed', right: '10px', top: '10px', zIndex: 8}}>
|
||||
<Button onClick={onClickNewFlow} size="sm" variant="outline" compact mr='xs' style={{float: 'left'}}> New Flow </Button>
|
||||
<Button onClick={onClickExamples} size="sm" variant="outline" compact mr='xs' style={{float: 'left'}}> Example Flows </Button>
|
||||
<Button onClick={onClickSettings} size="sm" variant="outline" compact><IconSettings size={"100%"} /></Button>
|
||||
<Button onClick={onClickSettings} size="sm" variant="filled" compact><IconSettings size={"90%"} /></Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
42
chainforge/react-server/src/AreYouSureModal.js
vendored
Normal file
42
chainforge/react-server/src/AreYouSureModal.js
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
import React, { forwardRef, useImperativeHandle } from 'react';
|
||||
import { Modal, Button, Box, Text, Flex } from '@mantine/core';
|
||||
import { useDisclosure } from '@mantine/hooks';
|
||||
|
||||
/** Modal that lets user rename a single value, using a TextInput field. */
|
||||
const AreYouSureModal = forwardRef(({title, message, onConfirm}, ref) => {
|
||||
const [opened, { open, close }] = useDisclosure(false);
|
||||
const description = message ? message : 'Are you sure?';
|
||||
|
||||
// This gives the parent access to triggering the modal alert
|
||||
const trigger = () => {
|
||||
open();
|
||||
};
|
||||
useImperativeHandle(ref, () => ({
|
||||
trigger,
|
||||
}));
|
||||
|
||||
const confirmAndClose = () => {
|
||||
close();
|
||||
if (onConfirm) onConfirm();
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal opened={opened} onClose={close} title={title} styles={{header: {backgroundColor: 'orange', color: 'white'}, root: {position: 'relative', left: '-80px'}}}>
|
||||
<Box maw={400} mx="auto" mt='md' mb='md'>
|
||||
<Text>{description}</Text>
|
||||
</Box>
|
||||
<Flex mih={50}
|
||||
gap="md"
|
||||
justify="space-evenly"
|
||||
align="center"
|
||||
direction="row"
|
||||
wrap="wrap"
|
||||
>
|
||||
<Button variant='light' color='red' type="submit" w='40%' onClick={close}>Cancel</Button>
|
||||
<Button variant='filled' color='green' type="submit" w='40%' onClick={confirmAndClose}>Confirm</Button>
|
||||
</Flex>
|
||||
</Modal>
|
||||
);
|
||||
});
|
||||
|
||||
export default AreYouSureModal;
|
10
chainforge/react-server/src/EvaluatorNode.js
vendored
10
chainforge/react-server/src/EvaluatorNode.js
vendored
@ -1,6 +1,6 @@
|
||||
import React, { useState, useRef, useCallback, useEffect } from 'react';
|
||||
import { Handle } from 'react-flow-renderer';
|
||||
import { Button } from '@mantine/core';
|
||||
import { Button, Code } from '@mantine/core';
|
||||
import useStore from './store';
|
||||
import NodeLabel from './NodeLabelComponent'
|
||||
import { IconTerminal, IconSearch } from '@tabler/icons-react'
|
||||
@ -185,12 +185,12 @@ const EvaluatorNode = ({ data, id }) => {
|
||||
style={{ top: '50%', background: '#555' }}
|
||||
/>
|
||||
<div className="core-mirror-field">
|
||||
<div className="code-mirror-field-header">Function to map over each
|
||||
<select name="mapscope" id="mapscope" onChange={handleOnMapScopeSelect}>
|
||||
<div className="code-mirror-field-header">Define an <Code>evaluate</Code> func to map over each response:
|
||||
{/* <select name="mapscope" id="mapscope" onChange={handleOnMapScopeSelect}>
|
||||
<option value="response">response</option>
|
||||
<option value="batch">batch of responses</option>
|
||||
</select>
|
||||
:</div>
|
||||
</select> */}
|
||||
</div>
|
||||
|
||||
{/* <span className="code-style">response</span>: */}
|
||||
<div className="ace-editor-container nodrag">
|
||||
|
2
setup.py
2
setup.py
@ -6,7 +6,7 @@ def readme():
|
||||
|
||||
setup(
|
||||
name='chainforge',
|
||||
version='0.1.7',
|
||||
version='0.1.7.1',
|
||||
packages=find_packages(),
|
||||
author="Ian Arawjo",
|
||||
description="A Visual Programming Environment for Prompt Engineering",
|
||||
|
Loading…
x
Reference in New Issue
Block a user