diff --git a/src/components/Main/Main.jsx b/src/components/Main/Main.jsx index 1a659ef..2f7bb2c 100644 --- a/src/components/Main/Main.jsx +++ b/src/components/Main/Main.jsx @@ -1,16 +1,25 @@ -import React from 'react' +import React, { useContext } from 'react' import './Main.css' import { assets } from '../../assets/assets' +import { Context } from '../../context/Context' const Main = () => { + + const {onSent,recentPrompt,showResult,loading,resultData,input,setInput} = useContext(Context); + return (

Core Assistant Inspired by Gemini

+ +
-
+ + {!showResult + ?<> +

Hello, Traveller

How can I help you today?

@@ -32,14 +41,17 @@ const Main = () => {
+ :
+
} +
- + setInput(e.target.value)} value={input} placeholder="Enter a prompt here" />
- + onSent()} alt="" />

Made using Gemini Api. Core may display inaccurate info, including about people, so double-check it's responses

diff --git a/src/config/gemini.js b/src/config/gemini.js index 0ef3e3a..fe4c5da 100644 --- a/src/config/gemini.js +++ b/src/config/gemini.js @@ -48,7 +48,7 @@ async function runChat(prompt) { const result = await chat.sendMessage(prompt); const response = result.response; console.log(response.text()); - + return response.text(); } export default runChat; \ No newline at end of file diff --git a/src/context/Context.jsx b/src/context/Context.jsx index fb06e84..4cb5528 100644 --- a/src/context/Context.jsx +++ b/src/context/Context.jsx @@ -1,4 +1,4 @@ -import { createContext } from "react"; +import { createContext, useState } from "react"; import runChat from "../config/gemini"; export const Context = createContext(); @@ -13,7 +13,14 @@ const ContextProvider = (props) => { const [resultData,setResultData] = useState(""); const onSent = async (prompt) => { - await runChat(prompt) + + setResultData("") + setLoading(true) + setShowResult(true) + const response = await runChat(input) + setResultData(response) + setLoading(false) + setInput('') }