From 4fdbe07ea2edd2f35148a9be261afe306b553809 Mon Sep 17 00:00:00 2001 From: Jakob Grant Date: Mon, 7 Mar 2022 21:25:53 -0800 Subject: [PATCH 001/531] hard code production thoth in env --- client/.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/.env b/client/.env index d1294695d..47fa9983a 100644 --- a/client/.env +++ b/client/.env @@ -1,7 +1,7 @@ EXTEND_ESLINT = true # This prod site root assumes the netlify build context $URL is available, replace for other hosts -REACT_APP_SITE_ROOT_URL_PROD=$URL +REACT_APP_SITE_ROOT_URL_PROD=http://thoth.latitude.io/ REACT_APP_SITE_ROOT_URL=http://localhost:3001 REACT_APP_LAPI_ROOT_URL=http://localhost:8000 REACT_APP_LAPI_ROOT_URL_PROD=https://api.latitude.io From 8aa8642193a99f4183d22907fff0c9c98012aabd Mon Sep 17 00:00:00 2001 From: Jakob Grant Date: Thu, 17 Mar 2022 17:07:46 -0700 Subject: [PATCH 002/531] prevent trimming of newline in map --- core/src/components/Generator.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/components/Generator.ts b/core/src/components/Generator.ts index ecc68c157..fea0f609a 100644 --- a/core/src/components/Generator.ts +++ b/core/src/components/Generator.ts @@ -118,7 +118,10 @@ export class Generator extends ThothComponent> { const prompt = template(inputs) const stop = node?.data?.stop - ? stopSequence.split(',').map(i => i.trim()) + ? stopSequence.split(',').map(i => { + if (i === '\n') return i + return i.trim() + }) : ['\n'] const tempData = node.data.temp as string From 29a1e1100df98715827711c3b6f6385620de8a00 Mon Sep 17 00:00:00 2001 From: Michael Sharpe Date: Fri, 18 Mar 2022 11:40:03 -0700 Subject: [PATCH 003/531] Fix component import ordering --- core/src/components/components.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/src/components/components.ts b/core/src/components/components.ts index 2ae1b5818..1bc6dc477 100644 --- a/core/src/components/components.ts +++ b/core/src/components/components.ts @@ -2,6 +2,12 @@ import { ActionTypeComponent } from './ActionType' import { Alert } from './AlertMessage' import { BooleanGate } from './BooleanGate' import { Code } from './Code' +import { InputFieldComponent } from './deprecated/InputField' +import { ModuleInput } from './deprecated/ModuleInput' +import { ModuleOutput } from './deprecated/ModuleOutput' +import { PlaytestInput } from './deprecated/PlaytestInput' +import { PlaytestPrint } from './deprecated/PlaytestPrint' +import { RunInputComponent } from './deprecated/RunInput' import { DifficultyDetectorComponent } from './DifficultyDetector' import { EnkiTask } from './EnkiTask' import { EntityDetector } from './EntityDetector' @@ -9,19 +15,11 @@ import { ForEach } from './ForEach' import { Generator } from './Generator' import { HuggingfaceComponent } from './Huggingface' import { InputComponent } from './Input' -import { InputFieldComponent } from './deprecated/InputField' import { ItemTypeComponent } from './ItemDetector' import { JoinListComponent } from './JoinList' import { ModuleComponent } from './Module' -import { ModuleInput } from './deprecated/ModuleInput' -import { ModuleOutput } from './deprecated/ModuleOutput' -import { TriggerIn } from './TriggerIn' -import { TriggerOut } from './TriggerOut' import { Output } from './Output' -import { PlaytestInput } from './deprecated/PlaytestInput' -import { PlaytestPrint } from './deprecated/PlaytestPrint' import { ProseToScript } from './ProseToScript' -import { RunInputComponent } from './deprecated/RunInput' import { SafetyVerifier } from './SafetyVerifier' import { StateRead } from './StateRead' import { StateWrite } from './StateWrite' @@ -29,6 +27,8 @@ import { StringProcessor } from './StringProcessor' import { SwitchGate } from './SwitchGate' import { TenseTransformer } from './TenseTransformer' import { TimeDetectorComponent } from './TimeDetector' +import { TriggerIn } from './TriggerIn' +import { TriggerOut } from './TriggerOut' import { VisualGeneration } from './VisualGeneration' // Here we load up all components of the builder into our editor for usage. From 72b98a710a8db7e2de4f2e82071e6b2018dd3b46 Mon Sep 17 00:00:00 2001 From: Nick Walton Date: Fri, 18 Mar 2022 13:10:08 -0700 Subject: [PATCH 004/531] generator can select (requires a lapi change) --- .../DataControls/DataControls.jsx | 2 + .../DataControls/DropdownSelect.tsx | 38 +++++++++++++++++++ client/src/features/common/Select/Select.jsx | 24 ++++++++++-- client/src/services/game-api/text.ts | 7 ++-- core/src/components/Generator.ts | 17 ++++++++- core/src/dataControls/DropdownControl.ts | 34 +++++++++++++++++ 6 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 client/src/features/Thoth/windows/InspectorWindow/DataControls/DropdownSelect.tsx create mode 100644 core/src/dataControls/DropdownControl.ts diff --git a/client/src/features/Thoth/windows/InspectorWindow/DataControls/DataControls.jsx b/client/src/features/Thoth/windows/InspectorWindow/DataControls/DataControls.jsx index cac6b7c7e..c8415ba18 100644 --- a/client/src/features/Thoth/windows/InspectorWindow/DataControls/DataControls.jsx +++ b/client/src/features/Thoth/windows/InspectorWindow/DataControls/DataControls.jsx @@ -8,6 +8,7 @@ import InputGenerator from './InputGenerator' import LongText from './LongTextControl' import ModuleSelect from './ModuleSelect' import OutputGenerator from './OutputGenerator' +import DropdownSelect from './DropdownSelect' import SocketGenerator from './SocketGenerator' import PlaytestControl from './PlaytestControl' import SwitchControl from './SwitchControl' @@ -28,6 +29,7 @@ const controlMap = { socketGenerator: SocketGenerator, playtest: PlaytestControl, switch: SwitchControl, + dropdownSelect: DropdownSelect, } const DataControls = ({ diff --git a/client/src/features/Thoth/windows/InspectorWindow/DataControls/DropdownSelect.tsx b/client/src/features/Thoth/windows/InspectorWindow/DataControls/DropdownSelect.tsx new file mode 100644 index 000000000..d798a2d82 --- /dev/null +++ b/client/src/features/Thoth/windows/InspectorWindow/DataControls/DropdownSelect.tsx @@ -0,0 +1,38 @@ +import Select from '../../../../common/Select/Select' + +const DropdownSelect = ({ control, updateData, initialValue }) => { + const { dataKey, data } = control + + const {values, defaultValue} = data + + const options = values.map((value, index) => ({ + value: value, + label: value, + })) + + const value = initialValue?.length > 0 ? initialValue : defaultValue + + const defaultVal = {value, label: value} + + const onChange = async ({ value }) => { + update(value) + } + + const update = update => { + updateData({ [dataKey]: update }) + } + + return ( +
+ + )} + + ) : ( )} diff --git a/client/src/services/game-api/text.ts b/client/src/services/game-api/text.ts index 8e1ee3ab0..19f942169 100644 --- a/client/src/services/game-api/text.ts +++ b/client/src/services/game-api/text.ts @@ -3,17 +3,16 @@ import { getAuthHeader } from '../../contexts/AuthProvider' export const completion = async body => { try { - const response = await fetch(latitudeApiRootUrl + '/text/completions', { + const response = await fetch(latitudeApiRootUrl + '/text/completions/v2', { method: 'POST', - mode: 'cors', headers: { 'Content-Type': 'application/json', ...(await getAuthHeader()), }, body: JSON.stringify({ ...body, prompt: body.prompt.trimEnd() }), }) - const { result } = await response.json() - return result + const result = await response.json() + return result.completions[0].text } catch (err) { // eslint-disable-next-line no-console console.warn('fetch error', err) diff --git a/core/src/components/Generator.ts b/core/src/components/Generator.ts index fea0f609a..585476178 100644 --- a/core/src/components/Generator.ts +++ b/core/src/components/Generator.ts @@ -9,6 +9,7 @@ import { } from '../../types' import { FewshotControl } from '../dataControls/FewshotControl' import { InputControl } from '../dataControls/InputControl' +import { DropdownControl } from '../dataControls/DropdownControl' import { SocketGeneratorControl } from '../dataControls/SocketGenerator' import { EngineContext } from '../engine' import { triggerSocket, stringSocket } from '../sockets' @@ -55,6 +56,13 @@ export class Generator extends ThothComponent> { name: 'Component Name', }) + const modelControl = new DropdownControl({ + dataKey: 'model', + name: 'Model', + defaultValue: (node.data?.model as string) || 'davinci', + values: ['vanilla-davinci', 'aid-jumbo', 'vanilla-jumbo'] + }) + const inputGenerator = new SocketGeneratorControl({ connectionType: 'input', name: 'Input Sockets', @@ -90,6 +98,7 @@ export class Generator extends ThothComponent> { node.inspector .add(nameControl) + .add(modelControl) .add(inputGenerator) .add(fewshotControl) .add(stopControl) @@ -112,6 +121,9 @@ export class Generator extends ThothComponent> { return acc }, {} as Record) + const model = (node.data.model as string) ?? 'vanilla-davinci' + // const model = node.data.model || 'davinci' + const fewshot = (node.data.fewshot as string) || '' const stopSequence = node.data.stop as string const template = Handlebars.compile(fewshot) @@ -119,10 +131,10 @@ export class Generator extends ThothComponent> { const stop = node?.data?.stop ? stopSequence.split(',').map(i => { - if (i === '\n') return i + if (i.includes('\n')) return i return i.trim() }) - : ['\n'] + : "" const tempData = node.data.temp as string const temperature = tempData ? parseFloat(tempData) : 0.7 @@ -134,6 +146,7 @@ export class Generator extends ThothComponent> { : 0 const body = { + model, prompt, stop, maxTokens, diff --git a/core/src/dataControls/DropdownControl.ts b/core/src/dataControls/DropdownControl.ts new file mode 100644 index 000000000..e207960ca --- /dev/null +++ b/core/src/dataControls/DropdownControl.ts @@ -0,0 +1,34 @@ +import { DataControl } from '../plugins/inspectorPlugin' + +export class DropdownControl extends DataControl { + constructor({ + name, + dataKey, + values, + defaultValue, + icon = 'properties', + write = true, + + }: { + name: string + dataKey: string + defaultValue: string + values: string[], + icon?: string + write?: boolean + }) { + const options = { + dataKey, + name: name, + component: 'dropdownSelect', + write, + icon, + data: { + defaultValue, + values, + }, + } + + super(options) + } +} From c640de124f2afc6fdd2c988f0fe1352d18c5dd46 Mon Sep 17 00:00:00 2001 From: Michael Sharpe Date: Mon, 21 Mar 2022 16:51:12 -0700 Subject: [PATCH 005/531] Add type for inspector data and export it --- core/src/plugins/inspectorPlugin/Inspector.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/src/plugins/inspectorPlugin/Inspector.ts b/core/src/plugins/inspectorPlugin/Inspector.ts index 5cbe22c99..96ecd7596 100644 --- a/core/src/plugins/inspectorPlugin/Inspector.ts +++ b/core/src/plugins/inspectorPlugin/Inspector.ts @@ -16,6 +16,17 @@ type InspectorConstructor = { // todo improve this typing type DataControlData = Record +export type InspectorData = { + name: string + nodeId: number + dataControls: Record + data: Record + category?: string + info: string + deprecated: boolean + deprecationMessage: string +} + export class Inspector { // Stub of function. Can be a nodes catch all onData cache: Record = {} @@ -238,7 +249,7 @@ export class Inspector { get() {} // returns all data prepared for the pubsub to send it. - data() { + data(): InspectorData { const dataControls = Array.from(this.dataControls.entries()).reduce( (acc, [key, val]) => { const cache = this.node?.data?.dataControls as DataControlData From 6ba2252edaac8fae1c87ff476fec710a429e8109 Mon Sep 17 00:00:00 2001 From: Michael Sharpe Date: Mon, 21 Mar 2022 16:51:33 -0700 Subject: [PATCH 006/531] Convert open project to typescript. --- .../screens/{OpenProject.jsx => OpenProject.tsx} | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) rename client/src/features/HomeScreen/screens/{OpenProject.jsx => OpenProject.tsx} (91%) diff --git a/client/src/features/HomeScreen/screens/OpenProject.jsx b/client/src/features/HomeScreen/screens/OpenProject.tsx similarity index 91% rename from client/src/features/HomeScreen/screens/OpenProject.jsx rename to client/src/features/HomeScreen/screens/OpenProject.tsx index de06455e8..d09f7e994 100644 --- a/client/src/features/HomeScreen/screens/OpenProject.jsx +++ b/client/src/features/HomeScreen/screens/OpenProject.tsx @@ -1,12 +1,14 @@ import { useNavigate } from 'react-router-dom' -import { useTabManager } from '../../../contexts/TabManagerProvider' import Icon from '../../common/Icon/Icon' import Panel from '../../common/Panel/Panel' import css from '../homeScreen.module.css' import thothBanner from '../version-banner-0.0.0beta.jpg' import FileInput from '../components/FileInput' import ProjectRow from '../components/ProjectRow' +import { useSelector } from 'react-redux' +import { selectAllTabs } from '@/state/tabs' +import { RootState } from '@/state/store' const getThothVersion = () => '0.0.1' @@ -17,7 +19,7 @@ const OpenProject = ({ loadFile, openSpell, }) => { - const { tabs } = useTabManager() + const tabs = useSelector((state: RootState) => selectAllTabs(state.tabs)) const navigate = useNavigate() return ( @@ -46,6 +48,7 @@ const OpenProject = ({ key={i} selectedSpell={selectedSpell} label={spell.name} + spell={spell} onClick={() => { setSelectedSpell(spell) }} From 4efb667794be63594a00c8d8de5a975dce59ff9b Mon Sep 17 00:00:00 2001 From: Michael Sharpe Date: Mon, 21 Mar 2022 16:51:58 -0700 Subject: [PATCH 007/531] Convert create new to typescript and strip out tab provider --- .../screens/{CreateNew.jsx => CreateNew.tsx} | 69 ++++++++++++------- 1 file changed, 43 insertions(+), 26 deletions(-) rename client/src/features/HomeScreen/screens/{CreateNew.jsx => CreateNew.tsx} (67%) diff --git a/client/src/features/HomeScreen/screens/CreateNew.jsx b/client/src/features/HomeScreen/screens/CreateNew.tsx similarity index 67% rename from client/src/features/HomeScreen/screens/CreateNew.jsx rename to client/src/features/HomeScreen/screens/CreateNew.tsx index 6f7791f9f..a3f1a8ba1 100644 --- a/client/src/features/HomeScreen/screens/CreateNew.jsx +++ b/client/src/features/HomeScreen/screens/CreateNew.tsx @@ -1,5 +1,5 @@ import { useSnackbar } from 'notistack' -import { useState, useEffect } from 'react' +import { useState } from 'react' import { useForm } from 'react-hook-form' import { uniqueNamesGenerator, @@ -9,15 +9,14 @@ import { import { useNavigate } from 'react-router-dom' import { useNewSpellMutation } from '@/state/api/spells' -import { useTabManager } from '@/contexts/TabManagerProvider' import Panel from '@common/Panel/Panel' -import Input from '@common/Input/Input' import emptyImg from '../empty.png' import enkiImg from '../enki.png' import langImg from '../lang.png' import css from '../homeScreen.module.css' import TemplatePanel from '../components/TemplatePanel' import defaultChain from './chains/default' +import { Spell } from '@latitudegames/thoth-core/types' const customConfig = { dictionaries: [adjectives, colors], @@ -25,6 +24,12 @@ const customConfig = { length: 2, } +type Template = { + label: string + bg: string + chain: Spell +} + const templates = [ { label: 'Starter', bg: emptyImg, chain: defaultChain }, { label: 'Language example', bg: langImg, chain: defaultChain }, @@ -32,12 +37,13 @@ const templates = [ ] const CreateNew = () => { - const [selectedTemplate, setSelectedTemplate] = useState(null) - const [error, setError] = useState(null) + const [selectedTemplate, setSelectedTemplate] = useState