Skip to content

alqinsidev/go-gemini-sandbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gemini AI Sandbox

Gemini AI Sandbox is an application designed to manage pairs of questions and answers utilized by Gemini AI to provide responses based on predefined information.

Tech Used

  • GO as the programming language
  • Gin as the HTTP Framework
  • MySQL as the Database
  • Generative AI SDK package from Google for interacting with Gemini AI

How It's Work

workflow

  1. User Asking: Users submit questions via the POST /chat endpoint to the system.
  2. Pre-stored Information: The application querying stored information in the database.
  3. Populated Information: The database provides the stored information to the application.
  4. Gemini Integration: The application forwards the user's question, along with the retrieved information, to Gemini Pro.
  5. Gemini Response: Gemini Pro generates an answer to the user's question based on the provided information.
  6. User Response: Finally, the user receives the answer to their question.

Populating Information

Before using the Chat API, you need to set pairs of questions and answers using the Informations API.

Usecase

For example, if you want Gemini to answer questions about personal information, you need to set up relevant information.

Information Example

Store this pair of questions and expected answers using Informations API:

Question: What is your name?

Answer: John Doe

The expected behavior for Gemini when using the Chat API after storing this information would be:

// Your Question
What is your last name?

// Gemini Answer
Doe

How to Run

Prerequisite

Ensure you have a Google Cloud Project API Key.

Running on Docker

Note: Update the API_KEY in the docker-compose.yml with your API key.

Follow these steps to run Gemini AI Sandbox as a Docker container:

Start Docker Container

docker-compose up -d

Run the Migration

docker exec gemini-api "./migration"

API

Here are list of available API

Informations

Add New Information
Description

Store new pair of question and answer used later by gemini to provide an answer

URL

POST /informations

Request Body
{
    "question": string, // user question
    "answer": string // answer expectation
}
Response - 201
{
    "data":{
        "id": int,
        "question": string,
        "answer": string
    },
    "success": boolean
}
Get Stored Information List
Description

Return stored information

URL

GET /informations

Response - 200
{
    "data": [
        {
            "id": int,
            "question": string,
            "answer": string
        }
    ],
    "success": boolean
}
Get Stored Information By ID
Description

Return stored information by id

URL

GET /informations/:id

Params

id: integer

Response - 200
{
    "data":{
        "id": int,
        "question": string,
        "answer": string
    },
    "success": boolean
}
Edit Information
Description

Edit stored pair of question and answer

URL

PUT /informations/:id

Request Params

id: integer

Request Body
{
    "question": string, // user question
    "answer": string // answer expectation
}
Response - 200
{
    "data":{
        "id": int,
        "question": string,
        "answer": string
    },
    "success": boolean
}
Delete Stored Information
Description

Delete stored information

URL

DELETE /informations/:id

Params

id: integer

Response - 200
{
    "data":{
        "id": int,
        "question": string,
        "answer": string
    },
    "success": boolean
}

Chat

Ask a question
Description

Ask Gemini a question, and gemini will answer it based on the information stored before

URL

POST /chat

Request Body
{
    "question": string
}
Response - 200
{
    "data": {
        "question": string,
        "answer": string
    },
    "success": boolean
}