This project is an educational fullstack application written in Rust, using the Yew.rs framework for the frontend and the Rocket framework for the backend. It is designed to allow users to make requests to OpenAI, and have the responses returned to them. The requests are protected by unique keys, which must be added by an admin, and each key has 10 questions associated with it. On the frontend, the user must provide the key and the question to the AI in order for the request to be processed. The entire project was created for educational purposes, and a series of YouTube videos have been recorded to demonstrate the project and its features.
-
Open backend directory
-
Create a new Database instance with the following commands
sqlite3 ./keys.db
create table keys (id varchar(255), left int);
.q
- Create a
.env
file in the root folder and add the following variables:
OPENAI_KEY=<OPENAI_API_KEY>
ADMIN_KEY=<RANDOM_ADMIN_PASSWORD>
Hint: You can get your own OpenAI API key from https://beta.openai.com/
-
Inside of the backend directory run command
cargo run
-
Open second instance of terminal and go to frontend directory
-
Run
trunk serve
command
In order to add new keys for users to use call the following POST request
URL: http://127.0.0.1:8000/api/v1/add_key
BODY: {
"password": <ADMIN_KEY>
}
In order to see all keys call the following GET request
URL: http://127.0.0.1:8000/api/v1/query_all
BODY: {
"password": <ADMIN_KEY>
}