Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Fix model config UI

Tomas Valenta5861d7b9a71a
diff --git a/api-service/models/base.py b/api-service/models/base.py
index 82efd1642..be006a45b 100644
--- a/api-service/models/base.py
+++ b/api-service/models/base.py
@@ -24,7 +24,6 @@ def get_model(
) -> BaseLanguageModel:
match config["provider"]:
case ModelProvider.OpenAI.value:
- print("pack")
return ChatOpenAI(
**config["args"],
request_timeout=3600,
diff --git a/api-service/playground/src/sessions/session.ts b/api-service/playground/src/sessions/session.ts
index 673724d9f..1298a16c7 100644
--- a/api-service/playground/src/sessions/session.ts
+++ b/api-service/playground/src/sessions/session.ts
@@ -59,7 +59,7 @@ export class CachedSession {
const url = this.session.getHostname()
if (!url) throw new Error('Cannot start session')
- const [id,] = url.split('.')
+ const [id] = url.split('.')
this.id = id
sessionCache.set(id, this)
diff --git a/components/Editor/Sidebar/Agent/index.tsx b/components/Editor/Sidebar/Agent/index.tsx
index c365ced51..4f4a43557 100644
--- a/components/Editor/Sidebar/Agent/index.tsx
+++ b/components/Editor/Sidebar/Agent/index.tsx
@@ -3,6 +3,7 @@ import { deployment_state, deployments } from '@prisma/client'
import produce from 'immer'
import { useSupabaseClient } from '@supabase/auth-helpers-react'
import { useRouter } from 'next/router'
+import { Key } from 'lucide-react'
import Text from 'components/Text'
import { useTabs } from 'components/Tabs/useTabs'
@@ -51,7 +52,7 @@ function Agent({
const [selector] = useStateStore()
const router = useRouter()
- const [creds,] = useModelProviderCreds()
+ const [creds] = useModelProviderCreds()
const model = selector.use.model()
const missingCreds = getMissingCreds(model.provider, creds)
@@ -124,7 +125,11 @@ function Agent({
className="text-red-600"
/>
<Button
+ className="whitespace-pre-wrap"
text="Set keys"
+ icon={
+ <Key size="16px" />
+ }
onClick={() => router.push('/settings')}
/>
</>
diff --git a/components/Editor/Sidebar/Model/ModelCard.tsx b/components/Editor/Sidebar/Model/ModelCard.tsx
new file mode 100644
index 000000000..bb9dad41f
--- /dev/null
+++ b/components/Editor/Sidebar/Model/ModelCard.tsx
@@ -0,0 +1,114 @@
+import clsx from 'clsx'
+import Input from 'components/Input'
+import Text from 'components/Text'
+import { Check, Wrench } from 'lucide-react'
+import React from 'react'
+
+import { ModelConfig } from 'state/model'
+import { ModelInfo } from 'state/store'
+
+interface Props {
+ isSelected?: boolean
+ select: (config: Omit<ModelInfo, 'name' | 'provider'>) => void
+ model: Omit<ModelConfig, 'provider'>
+ modelInfo?: ModelInfo
+}
+
+function ModelCard({
+ isSelected,
+ select,
+ model,
+ modelInfo,
+}: Props) {
+ return (
+ <div
+ className={clsx(
+ {
+ 'border-green-800 text-slate-600 shadow-sm': isSelected,
+ 'bg-white border-slate-300 text-slate-400': !isSelected,
+ },
+ `
+ relative
+ flex
+ min-h-[50px]
+ cursor-pointer
+ rounded
+ p-2
+ border
+ hover:text-slate-600
+ hover:border-green-800
+ `)}
+ onClick={() => select({
+ userArgs: {
+ ...modelInfo?.userArgs,
+ }
+ })}
+ >
+ <div className="
+ flex
+ w-full
+ items-center
+ justify-between
+ ">
+ <div className="
+ flex
+ items-start
+ flex-col
+ space-y-2
+ ">
+ <div className="
+ text-sm
+ items-center
+ font-medium
+ ">
+ {model.name}
+ </div>
+ {Object
+ .entries(model.args || {})
+ .filter(([, value]) => value.editable).length > 0 &&
+ <>
+ <Text
+ text="Configuration"
+ className="font-medium pt-3"
+ icon={<Wrench size="16px" />}
+ size={Text.size.S3}
+ />
+ <div className="
+ flex
+ flex-col
+ space-y-2
+ "
+ >
+ {Object.entries(model.args || {})
+ .filter(([, value]) => value.editable)
+ .map(([key, value]) =>
+ <div
+ key={key}
+ >
+ <Input
+ value={modelInfo?.userArgs[key]?.toString() || ''}
+ onChange={(v) => select({
+ userArgs: {
+ ...modelInfo?.userArgs,
+ [key]: v,
+ }
+ })}
+ label={value.label || key}
+ />
+ </div>
+ )}
+ </div>
+ </>
+ }
+ </div>
+ {isSelected && (
+ <div className="shrink-0 text-green-800">
+ <Check size="20px" />
+ </div>
+ )}
+ </div>
+ </div >
+ )
+}
+
+export default ModelCard
diff --git a/components/Editor/Sidebar/Model.tsx b/components/Editor/Sidebar/Model/index.tsx
similarity index 70%
rename from components/Editor/Sidebar/Model.tsx
rename to components/Editor/Sidebar/Model/index.tsx
index 46c54fa02..645ac9d95 100644
--- a/components/Editor/Sidebar/Model.tsx
+++ b/components/Editor/Sidebar/Model/index.tsx
@@ -1,22 +1,24 @@
import { useRouter } from 'next/router'
+import { Key } from 'lucide-react'
-import Radio from 'components/ModelRadio'
import Text from 'components/Text'
import { useStateStore } from 'state/StoreProvider'
import { getMissingCreds, ModelProvider, models } from 'state/model'
import useModelProviderCreds from 'hooks/useModelProviderCreds'
import Button from 'components/Button'
+import ModelCard from './ModelCard'
+
export interface Props { }
-function Context({ }: Props) {
+function Model({ }: Props) {
const [selector] = useStateStore()
const router = useRouter()
const model = selector.use.model()
const setModel = selector.use.setModel()
- const [creds,] = useModelProviderCreds()
+ const [creds] = useModelProviderCreds()
return (
<div className="
@@ -57,9 +59,15 @@ function Context({ }: Props) {
{Object.entries(models).map(([provider, value]) =>
<div
key={provider}
+ className="
+ flex
+ space-y-1
+ flex-col
+ "
>
<div className="
flex
+ space-y-1
justify-between
"
>
@@ -85,26 +93,37 @@ function Context({ }: Props) {
size={Text.size.S3}
/>
<Button
+ icon={
+ <Key size="16px" />
+ }
text="Set keys"
+ className="whitespace-pre-wrap"
onClick={() => router.push('/settings')}
/>
</div>
</div>
<div className="
flex
- items-start
+ items-stretch
+ flex-col
flex-1
py-1
+ space-y-2
"
>
- <Radio
- items={value.models}
- select={(i) => setModel({
-
- ...i,
- })}
- selected={model}
- />
+ {value.models.map(m =>
+ <ModelCard
+ key={m.name}
+ model={m}
+ modelInfo={m.name === model.name ? model : undefined}
+ isSelected={m.name === model.name}
+ select={i => setModel({
+ name: m.name,
+ provider: provider as ModelProvider,
+ ...i,
+ })}
+ />
+ )}
</div>
</div>
)}
@@ -113,4 +132,4 @@ function Context({ }: Props) {
)
}
-export default Context
+export default Model
diff --git a/components/ModelRadio.tsx b/components/ModelRadio.tsx
deleted file mode 100644
index cd1bf366e..000000000
--- a/components/ModelRadio.tsx
+++ /dev/null
@@ -1,69 +0,0 @@
-import { RadioGroup } from '@headlessui/react'
-import { Check } from 'lucide-react'
-
-import { ModelConfig } from 'state/model'
-
-export type Item = Omit<ModelConfig, 'provider'>
-
-export interface Props {
- selected: Item
- select: (item: Item) => void
- items: Item[]
-}
-
-function Radio<T>({ selected, items, select }: Props) {
- return (
- <div className="mx-auto w-full">
- <RadioGroup value={selected} onChange={select}>
- <div className="space-y-2">
- {items.map((item) => (
- <RadioGroup.Option
- key={item.name}
- value={item.name}
- className={({ active, checked }) =>
- `
- ${checked ? 'border-green-800' : 'bg-white border-slate-300'
- }
- relative flex cursor-pointer rounded px-2 py-1 border hover:border-green-800 transition-all`
- }
- >
- {({ active, checked }) => (
- <>
- <div className="flex w-full items-center justify-between">
- <div className="flex items-center">
- <div className="text-sm items-center transition-all">
- <RadioGroup.Label
- as="p"
- className={`font-medium ${checked ? 'text-slate-600' : 'text-slate-500'
- }`}
- >
- {item.name}
- </RadioGroup.Label>
- <RadioGroup.Description
- as="span"
- className={`inline text-xs ${checked ? 'text-slate-500' : 'text-slate-400'
- }`}
- >
- <span className="font-mono">
- {item.name}
- </span>
- </RadioGroup.Description>
- </div>
- </div>
- {checked && (
- <div className="shrink-0 text-green-800">
- <Check size="20px" />
- </div>
- )}
- </div>
- </>
- )}
- </RadioGroup.Option>
- ))}
- </div>
- </RadioGroup>
- </div>
- )
-}
-
-export default Radio
diff --git a/package-lock.json b/package-lock.json
index 604750e6a..71a348684 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -10,7 +10,6 @@
"hasInstallScript": true,
"dependencies": {
"@devbookhq/splitter": "^1.4.0",
- "@headlessui/react": "^1.7.13",
"@prisma/client": "^4.11.0",
"@supabase/auth-helpers-nextjs": "^0.5.5",
"@supabase/auth-helpers-react": "^0.3.1",
@@ -118,21 +117,6 @@
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
}
},
- "node_modules/@headlessui/react": {
- "version": "1.7.13",
- "resolved": "https://registry.npmjs.org/@headlessui/react/-/react-1.7.13.tgz",
- "integrity": "sha512-9n+EQKRtD9266xIHXdY5MfiXPDfYwl7zBM7KOx2Ae3Gdgxy8QML1FkCMjq6AsOf0l6N9uvI4HcFtuFlenaldKg==",
- "dependencies": {
- "client-only": "^0.0.1"
- },
- "engines": {
- "node": ">=10"
- },
- "peerDependencies": {
- "react": "^16 || ^17 || ^18",
- "react-dom": "^16 || ^17 || ^18"
- }
- },
"node_modules/@humanwhocodes/config-array": {
"version": "0.11.8",
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz",
diff --git a/package.json b/package.json
index 33353a5ba..a0b32211d 100644
--- a/package.json
+++ b/package.json
@@ -26,7 +26,6 @@
},
"dependencies": {
"@devbookhq/splitter": "^1.4.0",
- "@headlessui/react": "^1.7.13",
"@prisma/client": "^4.11.0",
"@supabase/auth-helpers-nextjs": "^0.5.5",
"@supabase/auth-helpers-react": "^0.3.1",
diff --git a/pages/settings.tsx b/pages/settings.tsx
index fc22441ee..3f576704e 100644
--- a/pages/settings.tsx
+++ b/pages/settings.tsx
@@ -1,4 +1,4 @@
-import { Settings as SettingsIcon } from 'lucide-react'
+import { Key, Mail, Settings as SettingsIcon } from 'lucide-react'
import { useRouter } from 'next/router'
import { GetServerSideProps } from 'next'
import { createServerSupabaseClient } from '@supabase/auth-helpers-nextjs'
@@ -87,11 +87,18 @@ function Settings({ }: Props) {
space-y-1
"
>
- <Text
- className="text-slate-400"
- size={Text.size.S2}
- text="Email"
- />
+ <div className="
+ flex
+ space-x-2
+ text-slate-400
+ items-center
+ ">
+ <Mail size="16px" />
+ <Text
+ size={Text.size.S2}
+ text="Email"
+ />
+ </div>
<Text
size={Text.size.S2}
text={user?.email!}
@@ -104,11 +111,18 @@ function Settings({ }: Props) {
space-y-1
"
>
- <Text
- className="text-slate-400"
- size={Text.size.S2}
- text="Keys"
- />
+ <div className="
+ flex
+ space-x-2
+ text-slate-400
+ items-center
+ ">
+ <Key size="16px" />
+ <Text
+ size={Text.size.S2}
+ text="Keys"
+ />
+ </div>
<div
className="
flex
diff --git a/state/model.ts b/state/model.ts
index ae16b47c9..ea277839f 100644
--- a/state/model.ts
+++ b/state/model.ts
@@ -45,11 +45,12 @@ export const models: {
},
models: [
{
- name: 'Custom model',
+ name: 'Deployed model',
args: {
model_name: {
editable: true,
type: 'string',
+ label: 'Model name'
},
max_tokens: {
type: 'number',