🧠 OpenAI APIs can be used with the Rust programming language to provide developers with access to powerful artificial intelligence systems.
🦀 The Rust programming language is an open source language that has been designed with safety and speed in mind.
⚙️ To use OpenAI APIs with Rust, developers must first install the Rust compiler, Rust libraries, and the OpenAI SDK. Once these components are installed, developers can invoke OpenAI APIs using standard HTTP POST and GET actions.
- Take your first steps with Rust
- Setup Rust Development Environment
- OpenAI API Introduction
- OpenAI API Text Completions
- OpenAI API Image Generation
- OpenAI API Chat Completion
You can view a sample console app using GPT-3 Completions code in the "src/openai_apis_completions/" directory in this repository.
You can view a sample console app using DALL-E image generation model code in the "src/openai_apis_image_generations/" directory in this repository.
You can view a sample console app that runs as a chat, using ChatGPT model {gpt-3.5-turbo}. The code for this sample is in the "src/openai_apis_chatgpt/" directory in this repository.
Disclaimer: This scenario does not implement a multi-turn conversations model. Right now, the scenario is a single-turn Q&A without any conversations.
Cargo run is the easiest way to test the OpenAI Completions and the Image Generation sample apps.
In scenarios 1 and 2, the console app receives 2 parametres: API Key and Prompt.
In example:
❯ cargo run <OpenAI API Key> "<Prompt>"
This is a sample output for the text completion scenario
cargo run <API Key> "generate a 2 paragraph description on how to use OpenAI APIs using Rust programming language"
Finished dev [unoptimized + debuginfo] target(s) in 3.04s
Prompt: generate a 2 paragraph description on how to use OpenAI APIs using Rust programming language
🔥 Success!
💬 Response:
OpenAI APIs can be used with the Rust programming language to provide developers with access to powerful artificial intelligence systems. ...
This is a sample output for the image generarion scenario
cargo run <API Key> "a cat playing soccer on the moon"
Finished dev [unoptimized + debuginfo] target(s) in 0.83s
Prompt: a cat playing soccer on mars
🔥 Success!
💬 Response: https://<location of the generated image>
And this is the generated image of a cat playing soccer on the moon:
Cargo run is the easiest way to test the OpenAI ChatGPT sample app.
In scenario 3, the console app receives 1 parametres: API Key.
In example:
❯ cargo run <OpenAI API Key>
This is a sample output for the chatgpt console app scenario
Welcome to ChatGPT API demo in Rust!
====================================
Please enter a question or [exit] to stop:
2 + 2
Your question: 2 + 2
🔥 Success!
💬 Response: 2 + 2 equals 4.
====================================
Please enter a question or [exit] to stop:
what is the rust programming language?
Your question: what is the rust programming language?
🔥 Success!
💬 Response: Rust is a system programming language that was initially developed by Mozilla in 2010. It is designed to be safe, concurrent, and fast while also being memory efficient. Rust was created to address the challenges of writing secure and scalable system software, by providing modern language features such as ownership, borrowing, and lifetimes, which help to prevent common programming errors such as null pointer dereferencing, data races, and buffer overflows. Rust is open source and has a growing community contributing to its development and adoption.
====================================
Please enter a question or [exit] to stop:
exit
Exiting...
In my personal blog "ElBruno.com", I wrote about several scenarios on how to work and code with Rust.
👤 Bruno Capuano
- Website: https://elbruno.com
- Twitter: @elbruno
- Github: @elbruno
- LinkedIn: @elbruno
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
Copyright © 2021 Bruno Capuano.
This project is MIT licensed.