Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add prompt editing [WIP]

Tomas Valentab74608e7878f
diff --git a/api-service/codegen/codegen.py b/api-service/codegen/codegen.py
index ff5c71776..467ce63eb 100644
--- a/api-service/codegen/codegen.py
+++ b/api-service/codegen/codegen.py
@@ -71,7 +71,7 @@ class Codegen(BaseModel):
llm=self._llm,
tools=tools,
prefix=self.get_prompt_part("system", "prefix"),
- format_instructions=self.get_prompt_part("system", "formatInstructions"),
+ format_instructions=self.get_prompt_part("system", "instructionsFormat"),
suffix=self.get_prompt_part("system", "suffix"),
input_variables=Codegen.input_variables,
callback_manager=self._callback_manager,
@@ -88,6 +88,7 @@ class Codegen(BaseModel):
return [tool.name for tool in self._tools]
def get_prompt_part(self, role: Literal["user", "system"], type: str):
+ print("get prompt", role, type)
return next(
(
prompt
@@ -105,10 +106,6 @@ class Codegen(BaseModel):
)
)
- # TODO: Extract input instructions from prompt var
-
- self._prompt
-
print("Running executor...")
await self._agent_executor.arun(
agent_scratchpad="",
diff --git a/components/Editor/RouteEditor/PromptEditor/index.tsx b/components/Editor/RouteEditor/PromptEditor/index.tsx
index 16e6686fd..5f207a3e9 100644
--- a/components/Editor/RouteEditor/PromptEditor/index.tsx
+++ b/components/Editor/RouteEditor/PromptEditor/index.tsx
@@ -2,7 +2,6 @@ import { EditorContent } from '@tiptap/react'
import Fuse from 'fuse.js'
import Text from 'components/Text'
-import { Block } from 'state/store'
import useDocEditor from 'hooks/useDocEditor'
import { Reference } from 'editor/referenceType'
@@ -10,19 +9,19 @@ export interface Props {
title?: string
placeholder?: string
onChange: (value: string) => void
- block: Block
- referenceSearch: Fuse<Reference>
+ content: string
+ referenceSearch?: Fuse<Reference>
}
function PromptEditor({
title,
onChange,
- block,
+ content,
placeholder,
referenceSearch,
}: Props) {
const editor = useDocEditor({
- initialContent: block.content,
+ initialContent: content,
onContentChange: onChange,
placeholder,
referenceSearch,
diff --git a/components/Editor/RouteEditor/index.tsx b/components/Editor/RouteEditor/index.tsx
index ab13005bf..eb9beaf1e 100644
--- a/components/Editor/RouteEditor/index.tsx
+++ b/components/Editor/RouteEditor/index.tsx
@@ -50,7 +50,7 @@ function RouteEditor({ route }: Props) {
referenceSearch={referenceSearch}
title="What should this route do?"
placeholder="This is an API endpoint that ..."
- block={descriptionBlock}
+ content={descriptionBlock.content}
onChange={updateDescriptionBlock}
/>
}
@@ -65,7 +65,7 @@ function RouteEditor({ route }: Props) {
referenceSearch={referenceSearch}
title="Step-by-step instructions"
placeholder="1. Check if the incoming `email` is not empty ..."
- block={instructionsBlock}
+ content={instructionsBlock.content}
onChange={updateInstructionsBlock}
/>
}
diff --git a/components/Editor/Sidebar/Prompt.tsx b/components/Editor/Sidebar/Prompt.tsx
index 53f229362..5fdda46b2 100644
--- a/components/Editor/Sidebar/Prompt.tsx
+++ b/components/Editor/Sidebar/Prompt.tsx
@@ -1,9 +1,11 @@
-import { CodeEditor, LanguageSetup } from '@devbookhq/code-editor'
+import { LanguageSetup } from '@devbookhq/code-editor'
import type { Extension } from '@codemirror/state'
import Text from 'components/Text'
import { useStateStore } from 'state/StoreProvider'
import { defaultPromptTemplate } from 'state/prompt'
+import { defaultTemplateID } from 'state/store'
+import PromptEditor from '../RouteEditor/PromptEditor'
export interface Props {
@@ -17,20 +19,20 @@ function Prompt({
}: Props) {
const [selectors] = useStateStore()
const model = selectors.use.model()
- const prompt = selectors.use.prompts().find(p =>
- p.templateID === 'NodeJSServer' &&
+ const setPrompt = selectors.use.setPrompt()
+ const modelSetup = selectors.use.modelSetups().find(p =>
+ p.templateID === defaultTemplateID &&
p.provider === model.provider &&
p.modelName === model.name
)
-
- const promptParts = prompt?.prompt || defaultPromptTemplate
-
- const setPrompt = selectors.use.setPrompt()
+ const prompt = modelSetup?.prompt || defaultPromptTemplate
return (
<div className="
flex
flex-col
+ flex-1
+ overflow-hidden
">
<div className="
flex
@@ -56,9 +58,10 @@ function Prompt({
flex
flex-col
scroller
- overflow-auto
+ flex-1
+ overflow-y-auto
">
- {promptParts.map((p, i) =>
+ {prompt.map((p, i) =>
<div
key={i}
className="
@@ -66,35 +69,32 @@ function Prompt({
flex-col
"
>
- <div className="
- flex
- space-x-2
- ">
- <Text
- text={p.role}
- className="font-bold"
- size={Text.size.S3}
- />
- <Text
- text={p.type}
- className="font-bold"
- size={Text.size.S3}
- />
- </div>
- <CodeEditor
+ <PromptEditor
+ title={p.role + ' ' + p.type}
+ placeholder={`Specify ${p.role} ${p.type} prompt here`}
+ content={p.content}
+ onChange={(content) => {
+ if (modelSetup) {
+ const p = modelSetup.prompt[i]
+ p.content = content
+ setPrompt(defaultTemplateID, model.provider, model.name, modelSetup.prompt)
+ }
+ }}
+ />
+
+ {/* <CodeEditor
content={p.content}
supportedLanguages={supportedLanguages}
filename="prompt"
theme={theme}
onContentChange={(content) => {
- if (prompt) {
- const p = prompt.prompt[i]
+ if (modelSetup) {
+ const p = modelSetup.prompt[i]
p.content = content
-
- setPrompt('NodeJSServer', model.provider, model.name, prompt.prompt)
+ setPrompt(defaultTemplateID, model.provider, model.name, modelSetup.prompt)
}
}}
- />
+ /> */}
</div>
)}
</div>
diff --git a/components/Editor/Sidebar/index.tsx b/components/Editor/Sidebar/index.tsx
index 0ff3494c2..fd64fed08 100644
--- a/components/Editor/Sidebar/index.tsx
+++ b/components/Editor/Sidebar/index.tsx
@@ -7,7 +7,7 @@ import Agent from './Agent'
import Envs from './Envs'
import Model from './Model'
-import { PromptPart, Route } from 'state/store'
+import { defaultTemplateID, PromptPart, Route } from 'state/store'
import { useLatestDeployment } from 'hooks/useLatestDeployment'
import { useStateStore } from 'state/StoreProvider'
import { ModelConfig, getModelConfig } from 'state/model'
@@ -81,8 +81,8 @@ function Sidebar({
const [selectors] = useStateStore()
const envs = selectors.use.envs()
const model = selectors.use.model()
- const prompt = selectors.use.prompts().find(p =>
- p.templateID === 'NodeJSServer' &&
+ const prompt = selectors.use.modelSetups().find(p =>
+ p.templateID === defaultTemplateID &&
p.provider === model.provider &&
p.modelName === model.name
)?.prompt || defaultPromptTemplate
diff --git a/hooks/useDocEditor.ts b/hooks/useDocEditor.ts
index f13101572..fcb2c9c12 100644
--- a/hooks/useDocEditor.ts
+++ b/hooks/useDocEditor.ts
@@ -13,7 +13,7 @@ function useDocEditor({
placeholder,
referenceSearch,
}: {
- referenceSearch: Fuse<Reference>
+ referenceSearch?: Fuse<Reference>
initialContent: string,
onContentChange: (content: string) => void,
placeholder?: string
@@ -32,11 +32,11 @@ function useDocEditor({
extensions: [
...extensions,
CustomKeymap,
- AutocompleteExtension.configure({
+ ...referenceSearch ? [AutocompleteExtension.configure({
suggestion: {
items: query => referenceSearch.search(query),
},
- }),
+ })] : [],
Placeholder.configure({
placeholder: ({ editor }) => {
if (!editor.getText()) {
diff --git a/state/prompt.ts b/state/prompt.ts
index ddcd0ad83..688a834ca 100644
--- a/state/prompt.ts
+++ b/state/prompt.ts
@@ -46,7 +46,7 @@ Final Answer: the final answer
},
{
role: 'user',
- type: 'userPrefix',
+ type: 'prefix',
content: `The handler you are building should do the following:
{{Description}}
diff --git a/state/store.ts b/state/store.ts
index 59cc83faa..b425d7c77 100644
--- a/state/store.ts
+++ b/state/store.ts
@@ -17,6 +17,9 @@ export interface SelectedModel {
name: string
}
+export const defaultTemplateID = 'NodeJSServer'
+export const defaultModelName: 'GPT 3.5 Turbo' = 'GPT 3.5 Turbo'
+
export type BlockType =
// Raw text
'Basic' |
@@ -45,7 +48,7 @@ export interface PromptPart {
content: string
}
-export interface ModelPrompt {
+export interface ModelSetup {
templateID: string
provider: ModelProvider
modelName: string
@@ -69,7 +72,7 @@ export interface SerializedState {
envs: { key: string, value: string }[]
routes: Route[]
model: SelectedModel
- prompts: ModelPrompt[]
+ modelSetups: ModelSetup[]
}
export interface State extends SerializedState {
@@ -107,16 +110,16 @@ function getDefaultRoute(): Route {
function getDefaultModel(): SelectedModel {
return {
provider: ModelProvider.OpenAI,
- name: 'GPT 3.5 Turbo',
+ name: defaultModelName,
args: {},
}
}
-function getDefaultPrompts(): ModelPrompt[] {
+function getDefaultPrompts(): ModelSetup[] {
return [{
provider: ModelProvider.OpenAI,
- modelName: 'GPT 3.5 Turbo',
- templateID: 'NodeJSServer',
+ modelName: defaultModelName,
+ templateID: defaultTemplateID,
prompt: defaultPromptTemplate,
}]
}
@@ -126,7 +129,7 @@ function getDefaultState(): SerializedState {
envs: [{ key: '', value: '' }],
routes: [getDefaultRoute()],
model: getDefaultModel(),
- prompts: getDefaultPrompts(),
+ modelSetups: getDefaultPrompts(),
}
}
@@ -150,8 +153,8 @@ export function createStore(project: projects, client?: SupabaseClient<Database>
initialState.envs.push({ key: '', value: '' })
}
- if (!initialState.prompts) {
- initialState.prompts = []
+ if (!initialState.modelSetups || !Array.isArray(initialState.modelSetups)) {
+ initialState.modelSetups = getDefaultPrompts()
}
// TEMPORARY: We are checking .model === string for backwards compatibility.
@@ -196,16 +199,16 @@ export function createStore(project: projects, client?: SupabaseClient<Database>
state.envs[idx] = pair
}),
setPrompt: (templateID, provider, modelName, prompt) => set(state => {
- const promptIdx = state.prompts.findIndex(p =>
+ const promptIdx = state.modelSetups.findIndex(p =>
p.templateID === templateID &&
p.provider === provider &&
p.modelName === modelName
)
if (promptIdx !== -1) {
- state.prompts[promptIdx].prompt = prompt
+ state.modelSetups[promptIdx].prompt = prompt
} else {
- state.prompts.push({
+ state.modelSetups.push({
templateID,
prompt,
modelName,