Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Add UI for passing user's OpenAI API key during setup

Vasek Mlejnskyacadce71eb7b
diff --git a/components/ChooseOpenAIKey.tsx b/components/ChooseOpenAIKey.tsx
new file mode 100644
index 000000000..225a6ec9c
--- /dev/null
+++ b/components/ChooseOpenAIKey.tsx
@@ -0,0 +1,120 @@
+import {
+ ArrowLeft,
+ ArrowRight,
+} from 'lucide-react'
+import { usePostHog } from 'posthog-js/react'
+import clsx from 'clsx'
+
+export interface Props {
+ selectedOpenAIKeyType: string
+ onSelectedOpenAIKeyTypeChange: (type: string) => void
+ userOpenAIKey?: string
+ onUserOpenAIKeyChange: (e: any) => void
+ onNext: () => void
+ onBack: () => void
+}
+
+const baseClasses = 'text-xs font-semibold py-1 px-2 rounded-md transition-all cursor-pointer'
+const unselectedClasses = 'text-gray-500 hover:bg-indigo-400/10 hover:text-indigo-400 border border-transparent hover:border-indigo-400/20'
+const selectedClasses = 'bg-indigo-400/10 text-indigo-400 border border-indigo-400/20'
+
+function ChooseOpenAIKey({
+ selectedOpenAIKeyType,
+ onSelectedOpenAIKeyTypeChange,
+ userOpenAIKey,
+ onUserOpenAIKeyChange,
+ onNext,
+ onBack,
+}: Props) {
+ const posthog = usePostHog()
+
+ function handleContinue() {
+ if (selectedOpenAIKeyType === 'user' && !userOpenAIKey) {
+ return
+ }
+ posthog?.capture('selected OpenAI key', {
+ selectedOpenAIKeyType,
+ })
+ onNext()
+ }
+
+ return (
+ <div className="flex-1 flex flex-col items-start justify-start space-y-2">
+ <h2 className="text-3xl font-bold tracking-tight sm:text-4xl">
+ Select OpenAI API Key
+ </h2>
+ <p className="mt-2 mb-6 text-lg leading-8 text-gray-400">
+ Pass your own OpenAI key or use the e2b key.
+ </p>
+
+ <div className="flex-1 w-full flex flex-col space-y-4 items-center justify-start">
+ <div className="mb-2 flex items-center justify-center space-x-2">
+ <div
+ className={clsx(
+ baseClasses,
+ selectedOpenAIKeyType === 'e2b' ? selectedClasses : unselectedClasses,
+ )}
+ onClick={() => onSelectedOpenAIKeyTypeChange('e2b')}
+ >
+ Use e2b&apos;s OpenAI API Key
+ </div>
+ <div
+ className={clsx(
+ baseClasses,
+ selectedOpenAIKeyType === 'user' ? selectedClasses : unselectedClasses,
+ )}
+ onClick={() => onSelectedOpenAIKeyTypeChange('user')}
+ >
+ Use my own OpenAI API key
+ </div>
+ </div>
+
+ {selectedOpenAIKeyType === 'e2b' && (
+ <ul className="list-disc p-4 border border-indigo-400/40 rounded-md text-sm">
+ <li className="ml-4">Use the e2b key to get started quickly and not get charged for OpenAI API usage.</li>
+ <li className="ml-4">We can&apos;t guarantee that e2b will not get blocked by OpenAI API rate limits.</li>
+ <li className="ml-4"><b>All costs running the smol developer will be billed to e2b.</b></li>
+ </ul>
+ )}
+ {selectedOpenAIKeyType === 'user' && (
+ <div className="flex flex-col space-y-2">
+ <ul className="list-disc p-4 border border-indigo-400/40 rounded-md text-sm">
+ <li className="ml-4">Use your own OpenAI API key</li>
+ <li className="ml-4">Using your own key might help when e2b is hitting the OpenAI&apos;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"
+ placeholder="OpenAI API Key"
+ value={userOpenAIKey}
+ onChange={onUserOpenAIKeyChange}
+ type='password'
+ autoFocus
+ />
+ </div>
+ )}
+ </div>
+
+
+ <div className="w-full flex items-center justify-between">
+ <button
+ className="flex items-center justify-start space-x-1 text-gray-400 hover:text-gray-100 transition-all"
+ onClick={onBack}
+ >
+ <ArrowLeft size={14} />
+ <span className="text-sm">Back</span>
+ </button>
+
+ <button
+ className="px-2 py-1 flex group items-center space-x-1 font-medium rounded-md border border-indigo-400/30 bg-indigo-400/10 text-indigo-400 hover:bg-transparent hover:border-indigo-400 transition-all"
+ onClick={handleContinue}
+ >
+ <span className="text-sm">Continue</span>
+ <ArrowRight className="group-hover:translate-x-0.5 transition-all" size={14} />
+ </button>
+ </div>
+ </div>
+ )
+}
+
+export default ChooseOpenAIKey
\ No newline at end of file
diff --git a/components/DeployAgent.tsx b/components/DeployAgent.tsx
index 1d382de24..943ae010c 100644
--- a/components/DeployAgent.tsx
+++ b/components/DeployAgent.tsx
@@ -18,6 +18,7 @@ export interface Props {
onDeploy: (e: any) => void
isDeploying?: boolean
error?: string
+ selectedOpenAIKeyType: string // 'e2b' or 'user'
}
function DeployAgent({
@@ -29,6 +30,7 @@ function DeployAgent({
onBack,
onDeploy,
isDeploying,
+ selectedOpenAIKeyType,
error,
}: Props) {
return (
@@ -44,6 +46,19 @@ function DeployAgent({
{!isDeploying && (
<>
+ {/* OpenAI Key */}
+ <div className="w-full flex flex-col space-y-2 items-start justify-start">
+ <span className="text-sm text-gray-300 font-medium">
+ OpenAI API Key
+ </span>
+ <span className="text-sm font-medium text-gray-100">
+ {selectedOpenAIKeyType === 'user' && 'Use your own OpenAI API key'}
+ {selectedOpenAIKeyType === 'e2b' && 'Use e2b\'s OpenAI API key'}
+ </span>
+ </div>
+
+ <hr className="w-full border-gray-700 rounded" />
+
{/* Selected repo */}
<div className="w-full flex flex-col space-y-2 items-start justify-start">
<div className="w-full flex items-center justify-between">
diff --git a/components/SelectRepository/index.tsx b/components/SelectRepository/index.tsx
index 5d894fecb..a55efa018 100644
--- a/components/SelectRepository/index.tsx
+++ b/components/SelectRepository/index.tsx
@@ -99,6 +99,7 @@ function SelectRepository({
onRepoSelection={selectRepo}
/>
)}
+
<button
type="button"
className="flex justify-start items-center text-xs font-medium space-x-1 text-gray-400 hover:text-white transition-all mt-4 rounded-md"
diff --git a/pages/agent/smol-developer/setup.tsx b/pages/agent/smol-developer/setup.tsx
index 87b4df0e7..c5528a9ad 100644
--- a/pages/agent/smol-developer/setup.tsx
+++ b/pages/agent/smol-developer/setup.tsx
@@ -27,6 +27,7 @@ import { GitHubAccount } from 'utils/github'
import { RepoSetup } from 'utils/repoSetup'
import StarUs from 'components/StarUs'
import { smolDeveloperTemplateID } from 'utils/smolTemplates'
+import ChooseOpenAIKey from 'components/ChooseOpenAIKey'
export interface PostAgentBody {
// ID of the installation of the GitHub App
@@ -53,6 +54,7 @@ export interface PostAgentBody {
const steps = [
{ name: 'Select Repository' },
{ name: 'Your Instructions' },
+ { name: 'OpenAI API Key' },
{ name: 'Overview & Deploy' },
]
@@ -107,6 +109,8 @@ function Setup() {
const posthog = usePostHog()
const router = useRouter()
const [isDeploying, setIsDeploying] = useState(false)
+ const [selectedOpenAIKeyType, setSelectedOpenAIKeyType] = useState('e2b')
+ const [userOpenAIKey, setUserOpenAIKey] = useState('')
const handleMessageEvent = useCallback((event: MessageEvent) => {
if (event.data.accessToken) {
@@ -247,6 +251,16 @@ function Setup() {
/>
)}
{currentStepIdx === 2 && (
+ <ChooseOpenAIKey
+ selectedOpenAIKeyType={selectedOpenAIKeyType}
+ onSelectedOpenAIKeyTypeChange={setSelectedOpenAIKeyType}
+ userOpenAIKey={userOpenAIKey}
+ onUserOpenAIKeyChange={e => setUserOpenAIKey(e.target.value)}
+ onNext={nextStep}
+ onBack={previousStep}
+ />
+ )}
+ {currentStepIdx === 3 && (
<DeployAgent
selectedRepo={selectedRepository!}
instructions={instructions}
@@ -262,6 +276,7 @@ function Setup() {
onBack={previousStep}
onDeploy={deployAgent}
isDeploying={isDeploying}
+ selectedOpenAIKeyType={selectedOpenAIKeyType}
/>
)}
</div>