|
| 1 | +import { getAPIKey, setAPIKey } from 'AutoGPT/utils/apiKey'; |
| 2 | +import { useAIStateDispatcher } from './AIStateProvider'; |
| 3 | +import { useCallback, useRef } from 'react'; |
| 4 | + |
| 5 | +export function HowToUseWithTokenRequest() { |
| 6 | + const { setupDispatcher } = useAIStateDispatcher(); |
| 7 | + const tokenRef = useRef<HTMLInputElement>(null); |
| 8 | + const onSaveClicked = useCallback(() => { |
| 9 | + if (tokenRef.current?.value) { |
| 10 | + setAPIKey(tokenRef.current?.value); |
| 11 | + } |
| 12 | + |
| 13 | + if (getAPIKey()) { |
| 14 | + // Only go to next stage if there is an API key present |
| 15 | + setupDispatcher("next_stage"); |
| 16 | + } |
| 17 | + }, [setupDispatcher]); |
| 18 | + |
| 19 | + return ( |
| 20 | + <div className="bg-white shadow sm:rounded-lg"> |
| 21 | + <div className="px-4 py-5 sm:p-6"> |
| 22 | + <h3 className="text-base font-semibold leading-6 text-gray-900"> |
| 23 | + Autonomous AI |
| 24 | + </h3> |
| 25 | + <div className="mt-2 max-w-xl text-sm text-gray-500"> |
| 26 | + <p> |
| 27 | + Give your custom AI a name and set it on a mission to achieve any |
| 28 | + goal you can imagine – all running within your browser. Watch it |
| 29 | + generate tasks, execute them, and learn from the outcomes for |
| 30 | + optimal results 🚀 |
| 31 | + </p> |
| 32 | + </div> |
| 33 | + <div className="mt-5 sm:flex sm:items-center"> |
| 34 | + <PluginGrid /> |
| 35 | + </div> |
| 36 | + <h3 className="mt-4 text-base font-semibold leading-6 text-gray-900"> |
| 37 | + Token |
| 38 | + </h3> |
| 39 | + <div className="mt-2 max-w-xl text-sm text-gray-500"> |
| 40 | + <p> |
| 41 | + AutoGPT uses OpenAI GPT directly from browser. The token is required |
| 42 | + to call those APIs and is only stored on your browser. You can go to{" "} |
| 43 | + <a |
| 44 | + href="https://platform.openai.com/account/api-keys" |
| 45 | + target="_blank" |
| 46 | + className="text-blue-600 underline underline-offset-1" |
| 47 | + > |
| 48 | + OpenAI |
| 49 | + </a>{" "} |
| 50 | + to create a new token. |
| 51 | + </p> |
| 52 | + </div> |
| 53 | + |
| 54 | + <form className="mt-5 sm:flex sm:items-center"> |
| 55 | + <div className="sm:w-full sm:max-w-2xl"> |
| 56 | + <label htmlFor="token" className="sr-only"> |
| 57 | + Token |
| 58 | + </label> |
| 59 | + <input |
| 60 | + ref={tokenRef} |
| 61 | + type="text" |
| 62 | + name="token" |
| 63 | + id="token" |
| 64 | + className="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" |
| 65 | + placeholder={getAPIKey() ?? "sk-1234..."} |
| 66 | + /> |
| 67 | + </div> |
| 68 | + <button |
| 69 | + type="button" |
| 70 | + className="mt-3 inline-flex w-full items-center justify-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 sm:ml-3 sm:mt-0 sm:w-auto" |
| 71 | + onClick={onSaveClicked} |
| 72 | + > |
| 73 | + Start |
| 74 | + </button> |
| 75 | + </form> |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + ); |
| 79 | +} |
| 80 | + |
| 81 | +interface PluginGroupInfo { |
| 82 | + emoji: string; |
| 83 | + name: string; |
| 84 | + description: string; |
| 85 | +} |
| 86 | + |
| 87 | +const PLUGIN_INFOS: PluginGroupInfo[] = [ |
| 88 | + { |
| 89 | + emoji: "🌐", |
| 90 | + name: "Web Explorer", |
| 91 | + description: "Browse the internet effortlessly with this powerful tool.", |
| 92 | + }, |
| 93 | + { |
| 94 | + emoji: "💻", |
| 95 | + name: "Code Crafter", |
| 96 | + description: "Generate code tailored to accomplish your goals", |
| 97 | + }, |
| 98 | + { |
| 99 | + emoji: "🤖", |
| 100 | + name: "Agent Architect", |
| 101 | + description: "Design and delegate tasks to GPT-based agents.", |
| 102 | + }, |
| 103 | + { |
| 104 | + emoji: "📁", |
| 105 | + name: "File Forge", |
| 106 | + description: "Create and edit files.", |
| 107 | + }, |
| 108 | +]; |
| 109 | + |
| 110 | +function PluginGrid() { |
| 111 | + return ( |
| 112 | + <div className="grid grid-cols-1 gap-4 sm:grid-cols-2"> |
| 113 | + {PLUGIN_INFOS.map((pluginInfo, index) => ( |
| 114 | + <div |
| 115 | + key={index} |
| 116 | + className="relative flex cursor-pointer items-center space-x-3 rounded-lg border border-gray-300 bg-white px-6 py-5 shadow-sm focus-within:ring-2 focus-within:ring-indigo-500 focus-within:ring-offset-2 hover:border-gray-400 sm:max-w-xs" |
| 117 | + > |
| 118 | + <div className="flex-shrink-0 text-3xl">{pluginInfo.emoji}</div> |
| 119 | + <div className="min-w-0 flex-1"> |
| 120 | + <a href="#" className="focus:outline-none"> |
| 121 | + <span className="absolute inset-0" aria-hidden="true" /> |
| 122 | + <p className="text-sm font-medium text-gray-900"> |
| 123 | + {pluginInfo.name} |
| 124 | + </p> |
| 125 | + <div className="text-sm text-gray-500"> |
| 126 | + {pluginInfo.description} |
| 127 | + </div> |
| 128 | + </a> |
| 129 | + </div> |
| 130 | + </div> |
| 131 | + ))} |
| 132 | + </div> |
| 133 | + ); |
| 134 | +} |
0 commit comments