Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
add UI for selecting OpenAI models
Vasek Mlejnsky0839ae6740be
diff --git a/components/ChooseOpenAIKey.tsx b/components/ChooseOpenAIKey.tsxindex 172fe3f10..d8590c8d6 100644--- a/components/ChooseOpenAIKey.tsx+++ b/components/ChooseOpenAIKey.tsx@@ -5,11 +5,19 @@ import {import { usePostHog } from 'posthog-js/react'import clsx from 'clsx'+import OpenAIKeyInput from 'components/OpenAIKeyInput'+export interface Props {selectedOpenAIKeyType: string+onSelectedOpenAIKeyTypeChange: (type: string) => voiduserOpenAIKey?: stringonUserOpenAIKeyChange: (e: any) => void++ openAIModels: { displayName: string, value: string }[]+ selectedOpenAIModel: { displayName: string, value: string }+ onOpenAIModelChange: (value: string) => void+onNext: () => voidonBack: () => void}@@ -20,9 +28,15 @@ const selectedClasses = 'bg-indigo-400/10 text-indigo-400 border border-indigo-function ChooseOpenAIKey({selectedOpenAIKeyType,+onSelectedOpenAIKeyTypeChange,userOpenAIKey,onUserOpenAIKeyChange,++ openAIModels,+ selectedOpenAIModel,+ onOpenAIModelChange,+onNext,onBack,}: Props) {@@ -34,6 +48,7 @@ function ChooseOpenAIKey({}posthog?.capture('selected OpenAI key', {selectedOpenAIKeyType,+ selectedOpenAIModel,})onNext()}@@ -83,12 +98,12 @@ function ChooseOpenAIKey({<li className="ml-4">Using your own key might help when e2b is hitting the OpenAI's API rate limits</li><li className="ml-4"><b>All costs running the smol developer will be billed to your OpenAI account</b></li></ul>- <input- className="bg-gray-800 block w-full rounded-md border-0 px-3 py-1.5 text-gray-100 shadow-sm ring-1 ring-inset ring-gray-400 placeholder:text-gray-400 focus:ring-gray-300 outline-none sm:text-sm sm:leading-6 transition-all security"- placeholder="OpenAI API Key"- value={userOpenAIKey}- onChange={onUserOpenAIKeyChange}- autoFocus+ <OpenAIKeyInput+ openAIKey={userOpenAIKey}+ onOpenAIKeyChange={onUserOpenAIKeyChange}+ models={openAIModels}+ selectedModel={selectedOpenAIModel}+ onModelChange={onOpenAIModelChange}/></div>)}diff --git a/components/OpenAIKeyInput.tsx b/components/OpenAIKeyInput.tsxnew file mode 100644index 000000000..8283323ae--- /dev/null+++ b/components/OpenAIKeyInput.tsx@@ -0,0 +1,54 @@+export interface Props {+ openAIKey?: string+ onOpenAIKeyChange: (e: any) => void+ models: { displayName: string, value: string }[]+ selectedModel: { displayName: string, value: string }+ onModelChange: (value: string) => void+}++function OpenAIKeyInput({+ openAIKey,+ onOpenAIKeyChange,+ models,+ selectedModel,+ onModelChange,+}: Props) {+ return (+ <div className="flex-1 flex flex-col space-y-2">+ <div className="flex-1 flex flex-col space-y-1">+ <label htmlFor="openai-model" className="block text-sm font-medium text-gray-400">+ Model+ </label>+ <select+ id="openai-model"+ name="location"+ className="cursor-pointer bg-gray-800 block w-full rounded-md px-3 py-1.5 text-gray-100 border border-gray-400 placeholder:text-gray-400 focus:border-gray-300 active:border-gray-300 outline-none sm:text-sm sm:leading-6 transition-all"+ value={selectedModel?.value}+ onChange={e => onModelChange(e.target.value)}+ >+ {models.map(model => (+ <option key={model.value} value={model.value}>+ {model.displayName}+ </option>+ ))}+ </select>+ </div>++ <div className="flex-1 flex flex-col space-y-1">+ <label htmlFor="openai-key" className="block text-sm font-medium text-gray-400">+ OpenAI Key+ </label>+ <input+ id="openai-key"+ className="bg-gray-800 block w-full rounded-md px-3 py-1.5 text-gray-100 border border-gray-400 placeholder:text-gray-400 focus:border-gray-300 outline-none sm:text-sm sm:leading-6 transition-all security"+ placeholder="OpenAI API Key"+ value={openAIKey}+ onChange={onOpenAIKeyChange}+ autoFocus+ />+ </div>+ </div>+ )+}++export default OpenAIKeyInput\ No newline at end of filediff --git a/pages/agent/smol-developer/setup.tsx b/pages/agent/smol-developer/setup.tsxindex 1ccf77df2..f5b8493de 100644--- a/pages/agent/smol-developer/setup.tsx+++ b/pages/agent/smol-developer/setup.tsx@@ -59,6 +59,13 @@ const steps = [{ name: 'Overview & Deploy' },]+const openAIModels = [+ { displayName: 'GPT-4', value: 'gpt-4' },+ { displayName: 'GPT-4 32k', value: 'gpt-4-32k' },+ { displayName: 'GPT-3.5 Turbo', value: 'gpt-3.5-turbo' },+ { displayName: 'GPT-3.5 Turbo 16k', value: 'gpt-3.5-turbo-16k' },+]+export const getServerSideProps: GetServerSideProps = async (ctx) => {const supabase = createServerSupabaseClient(ctx, serverCreds)const {@@ -113,6 +120,7 @@ function Setup() {const [selectedOpenAIKeyType, setSelectedOpenAIKeyType] = useState('e2b')const [userOpenAIKey, setUserOpenAIKey] = useState('')const [errorMessage, setErrorMessage] = useState('')+ const [selectedOpenAIModel, setSelectedOpenAIModel] = useState(openAIModels[0])const handleMessageEvent = useCallback((event: MessageEvent) => {if (event.data.accessToken) {@@ -123,6 +131,16 @@ function Setup() {}, [refetch, setAccessToken])useListenOnMessage(handleMessageEvent)+ const handleSelectOpenAIModel = useCallback((value: string) => {+ const model = openAIModels.find((model) => model.value === value)+ if (!model) throw new Error(`Invalid OpenAI model: ${value}`)+ setSelectedOpenAIModel(model)+ }, [])++ const handleOpenAIKeyChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {+ setUserOpenAIKey(event.target.value)+ }, [])+const {trigger: createAgent,} = useSWRMutation('/api/agent', handlePostAgent)@@ -260,9 +278,15 @@ function Setup() {{currentStepIdx === 2 && (<ChooseOpenAIKeyselectedOpenAIKeyType={selectedOpenAIKeyType}+onSelectedOpenAIKeyTypeChange={setSelectedOpenAIKeyType}userOpenAIKey={userOpenAIKey}- onUserOpenAIKeyChange={e => setUserOpenAIKey(e.target.value)}+ onUserOpenAIKeyChange={handleOpenAIKeyChange}++ openAIModels={openAIModels}+ selectedOpenAIModel={selectedOpenAIModel}+ onOpenAIModelChange={handleSelectOpenAIModel}+onNext={nextStep}onBack={previousStep}/>