Skip to content

Commit

Permalink
feat: gpt search
Browse files Browse the repository at this point in the history
  • Loading branch information
amolsasane committed Jul 5, 2024
1 parent 414b883 commit 5d1e5fd
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/components/GptSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faChevronRight } from "@fortawesome/free-solid-svg-icons";
import langConstants from "../utils/languageConstants";
import { useDispatch, useSelector } from "react-redux";
import openai from "../utils/openai";
import { showError } from "../utils/gptSlice";

const GptSearch = () => {
Expand All @@ -12,24 +11,27 @@ const GptSearch = () => {
const searchText = useRef(null);
const dispatch = useDispatch();

const { GoogleGenerativeAI } = require("@google/generative-ai");
const genAI = new GoogleGenerativeAI(process.env.REACT_APP_GEMINI_API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });

const handleSubmit = (e) => {
e.preventDefault();
gptSearchClickHandler();
};

const gptSearchClickHandler = async () => {
try {
const gptQuery =
const promptQuery =
"Act like a movie suggestion system and show results for the query: " +
searchText.current.value +
". Give 5 movies, comma separated like the example result given ahead. Example Result: 3 Idiots, Avenger, Hulk, Raabta, Kabir Singh.";

const gptResults = await openai.chat.completions.create({
messages: [{ role: "user", content: gptQuery }],
model: "gpt-3.5-turbo",
});

console.log(gptResults.choices);
const prompt = promptQuery;
const result = await model.generateContent(prompt);
const response = await result.response;
const text = response.text();
console.log(text);
} catch (error) {
console.error("Error fetching GPT results", error);
dispatch(showError(error.message));
Expand Down

0 comments on commit 5d1e5fd

Please sign in to comment.