diff --git a/.py b/.py new file mode 100644 index 000000000..ded9a0078 --- /dev/null +++ b/.py @@ -0,0 +1,20 @@ +from openai import OpenAI + +client = OpenAI( + api_key="AIzaSyCRLceQ6TDxRrZVhNZT94gdS_o4wmEu2cA", + base_url="https://generativelanguage.googleapis.com/v1beta/openai/" +) + +response = client.chat.completions.create( + model="gemini-2.5-flash", + reasoning_effort="low", + messages=[ + {"role": "system", "content": "You are a helpful assistant."}, + { + "role": "user", + "content": "Explain to me how AI works" + } + ] +) + +print(response.choices[0].message) \ No newline at end of file diff --git a/README.md b/README.md index 8f359581e..bd1fed729 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ Generate small apps with one prompt. Powered by the Gemini API.

-Try it in https://huggingface.co/spaces/osanseviero/InstantCoder - This project is fully based on [llamacoder](https://github.com/Nutlope/llamacoder). Please follow [Nutlope](https://github.com/Nutlope) and give them a star. ## Tech stack @@ -13,12 +11,8 @@ This project is fully based on [llamacoder](https://github.com/Nutlope/llamacode - [Sandpack](https://sandpack.codesandbox.io/) for the code sandbox - Next.js app router with Tailwind -You can also experiment with Gemini in [Google AI Studio](https://aistudio.google.com/). - ## Cloning & running - -1. Clone the repo: `git clone https://github.com/osanseviero/GemCoder` -2. Create a `.env` file and add your [Google AI Studio API key](https://aistudio.google.com/app/apikey): `GOOGLE_AI_API_KEY=` -3. Run `npm install` and `npm run dev` to install dependencies and run locally +1. Create a `.env` file and add your [Google AI Studio API key](https://aistudio.google.com/app/apikey): `AIzaSyCRLceQ6TDxRrZVhNZT94gdS_o4wmEu2cA` +2. Run `npm install` and `npm run dev` to install dependencies and run locally **This is a personal project and not a Google official project** diff --git a/app/(main)/page.tsx b/app/(main)/page.tsx index 15bb0f0e8..d3ed42a9f 100644 --- a/app/(main)/page.tsx +++ b/app/(main)/page.tsx @@ -1,250 +1,38 @@ -"use client"; +// app/page.tsx +'use client'; -import CodeViewer from "@/components/code-viewer"; -import { useScrollTo } from "@/hooks/use-scroll-to"; -import { CheckIcon } from "@heroicons/react/16/solid"; -import { ArrowLongRightIcon, ChevronDownIcon } from "@heroicons/react/20/solid"; -import { ArrowUpOnSquareIcon } from "@heroicons/react/24/outline"; -import * as Select from "@radix-ui/react-select"; -import * as Switch from "@radix-ui/react-switch"; -import { AnimatePresence, motion } from "framer-motion"; -import { FormEvent, useEffect, useState } from "react"; -import LoadingDots from "../../components/loading-dots"; - -function removeCodeFormatting(code: string): string { - return code.replace(/```(?:typescript|javascript|tsx)?\n([\s\S]*?)```/g, '$1').trim(); -} +import { useState } from 'react'; +import CodeGenerator from '@/components/codegenrator'; +import CodeViewer from '@/components/code-viewer'; +import { Toaster } from 'sonner'; export default function Home() { - let [status, setStatus] = useState< - "initial" | "creating" | "created" | "updating" | "updated" - >("initial"); - let [prompt, setPrompt] = useState(""); - let models = [ - { - label: "gemini-2.0-flash-exp", - value: "gemini-2.0-flash-exp", - }, - { - label: "gemini-1.5-pro", - value: "gemini-1.5-pro", - }, - { - label: "gemini-1.5-flash", - value: "gemini-1.5-flash", - } - ]; - let [model, setModel] = useState(models[0].value); - let [modification, setModification] = useState(""); - let [generatedCode, setGeneratedCode] = useState(""); - let [initialAppConfig, setInitialAppConfig] = useState({ - model: "", - }); - let [ref, scrollTo] = useScrollTo(); - let [messages, setMessages] = useState<{ role: string; content: string }[]>( - [], - ); - - let loading = status === "creating" || status === "updating"; - - async function createApp(e: FormEvent) { - e.preventDefault(); - - if (status !== "initial") { - scrollTo({ delay: 0.5 }); - } - - setStatus("creating"); - setGeneratedCode(""); - - let res = await fetch("/api/generateCode", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - model, - messages: [{ role: "user", content: prompt }], - }), - }); - - if (!res.ok) { - throw new Error(res.statusText); - } - - if (!res.body) { - throw new Error("No response body"); - } - - const reader = res.body.getReader(); - let receivedData = ""; + const [generatedCode, setGeneratedCode] = useState(''); - while (true) { - const { done, value } = await reader.read(); - if (done) { - break; - } - receivedData += new TextDecoder().decode(value); - const cleanedData = removeCodeFormatting(receivedData); - setGeneratedCode(cleanedData); - } - - setMessages([{ role: "user", content: prompt }]); - setInitialAppConfig({ model }); - setStatus("created"); - } - - useEffect(() => { - let el = document.querySelector(".cm-scroller"); - if (el && loading) { - let end = el.scrollHeight - el.clientHeight; - el.scrollTo({ top: end }); - } - }, [loading, generatedCode]); + const handleCodeGenerated = (code: string) => { + setGeneratedCode(code); + }; return ( -
- - - Powered by Gemini API - - -

- Turn your idea -
into an app -

- -
-
-
-
-
-
-