Giter Club home page Giter Club logo

whichcelebrity's Introduction

Which Celebrity Are You?

An online quiz that utilizes AI to determine which celebrity (or famous person in history) you are the most like based on your answers to the questions provided.

No need for a database, session, or external state management tool(s).

npm install
npm run dev

Configuration

.env.local

OpenAI

API for AI responses

OPENAI_ORGANIZATION=
OPENAI_API_KEY=

View / create your API key: API keys - OpenAI API.

Unsplash

API for images

UNSPLASH_ACCESS_KEY=
UNSPLASH_SECRET_KEY=

View / create your Unsplash API key: Unsplash | Developers

~/src/constants

Within the /constants directory is where you can make instant changes to the configuration of the application. You can change the color scheme, font usage, and questions/answers for the quiz.

OpenAI

The OpenAI model is defined in ~/src/lib/openai.ts.

import OpenAI from "openai";

const openai = new OpenAI({
    apiKey: process.env.OPENAI_API_KEY,
    organization: process.env.OPENAI_ORGANIZATION,
});

export default openai;

The information being "fed" to your OpenAI query is defined within ~/src/lib/query.ts.

Example:

import openai from "./openai";
import { ChatCompletionMessage } from "openai/resources/index.mjs";

const systemRoleContent = "You are capable of seeing the color of someone's aura based on how they answer questions. Your job is to look at a user's answers to specific questions and determine the color of their aura. Each question is numbered in order. The question and it's answer are separated by a |. Each question is separated by |||. Respond with a color.";

const model = 'gpt-3.5-turbo';

const query = async (prompt: string) => {

    if (prompt.length < 1) return false;

    const list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

    function sleep(milliseconds: number): Promise<any> {
        return new Promise((resolve) => setTimeout(resolve, milliseconds));
    }

    for (const item in list) {
        const res: string | ChatCompletionMessage = await openai.chat.completions.create({
            model: model,
            messages: [
                { 'role': 'system', 'content': systemRoleContent }, // Tells the AI it's job
                { 'role': 'user', 'content': prompt },
            ],
            temperature: 0.86, // Values accepted: 0 - 2. The higher the value, the more random. The lower, the more deterministic. Recommended value: 0.5 - 1.
        }).then((res) => res.choices[Number(item)].message)
            .catch((err) => `Celebrity couldn't be determined! (Error: ${err.message})`);

            await sleep(500);

            if (typeof res === 'object') {
                return res.content; // Ensure you get a string back
            }

            return res;
    }
}

export default query;

The systemRoleContent variable is the key to establishing how you'd like the AI model to respond based on the information fed to it. If you wish to change this, you'll need to alter external parts of the code that parse through how to handle & format the response.

API Routes

/api/result/[id]

The route for gathering a result is dynamic based on the ID. The ID is generated as an array of the indexes of answers chosen.

If there are 5 questions and a user picks the 1st choice for each question, the route would be /api/result/00000

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.