Skip to content

nyakiomaina/chatGPT-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAI SQL Code Generator in Rust

Simple Rust program that uses the OpenAI API to generate SQL code based on user input. For example, the user might enter something like:

Find all employees with a salary greater than 50000

The OpenAI API would then take this input and attempt to generate the corresponding SQL code, which might look something like:

SELECT * FROM employees WHERE salary > 50000;

About

This application takes user input from the console, which should be a natural language statement, and sends it to the OpenAI API, which generates a corresponding SQL query based on the input. It uses the "text-davinci-001" engine for text generation.

The user input is appended to a static preamble: "Generate a Sql code for the given statement". The response from the API, which is a SQL query, is then printed to the console. The program runs in a loop, allowing the user to provide input and receive SQL queries continuously.

Prerequisites

Rust Programming Language OpenAI account and API key hyper, hyper-tls, dotenv, serde, serde_derive, spinners crates

Installation

Before you can run this program, you need to have Rust installed on your machine. If you don't have Rust installed, follow the instructions here to install it.

You also need an API key from OpenAI. If you don't have one, you can create an account on the OpenAIwebsite , then follow the instructions to get an API key.

Add the following to your Cargo.toml file:

[dependencies]
hyper = "*"
hyper-tls = "*"
dotenv = "*"
serde = "*"
serde_derive = "*"
spinners = "*"

Usage

First, create a .env file in the root of your project and add the following line to it:

OAI_TOKEN=<Your OpenAI API Key>

Remember to replace <Your OpenAI API Key> with your actual OpenAI API key.

Then, you can run the program with the following command:

cargo run

You will be prompted to enter a statement in natural language. After you do, press Enter, and the application will display the corresponding SQL query.

Contributing

Contributions, issues and feature requests are welcome.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages