#gpt #gptapi

gptrust_http

The HTTP bindings for gptrust_api

5 releases

0.1.4 May 9, 2023
0.1.3 May 7, 2023
0.1.2 Mar 26, 2023
0.1.1 Mar 26, 2023
0.1.0 Jan 29, 2023

#104 in Audio

Download history 22/week @ 2023-02-18 3/week @ 2023-02-25 14/week @ 2023-03-04 6/week @ 2023-03-11 16/week @ 2023-03-18 59/week @ 2023-03-25 16/week @ 2023-04-01 19/week @ 2023-04-08 9/week @ 2023-04-15 2/week @ 2023-04-22 21/week @ 2023-04-29 76/week @ 2023-05-06 15/week @ 2023-05-13 5/week @ 2023-05-20 20/week @ 2023-05-27 33/week @ 2023-06-03

75 downloads per month
Used in 4 crates (2 directly)

MIT license

8KB
176 lines

gptrust

Rust bindings to OpenAI, GPT

Unofficial and community maintained library, MIT Licensed

Goals

We have two main goals of this project.

  1. Create a library to provide a convenient access to openai API and hide all the complexity of raw json over HTTP (and headers), i.e. implement https://github.com/openai/openai-openapi/blob/master/openapi.yaml

  2. Using that library, create a proxy so that any other program can use openai (irrespective of the language they are written). They can communicate to the proxy over a pipe. E.g a python application can do a simply (pseudocode) with open("/dev/chatgpt") as gpt: gpt.write(); gpt.read() and the whole complexity of auth, billing will be managed by the proxy

  3. Create a CLI frontend, which will just take relevant parameters and post them to the API. Maybe we can call it openaictl (like kubectl)

Impatient run

Pre-requisite

On a vanilla Ubuntu LTS

sudo apt-get update
sudo apt-get install cargo libssl-dev pkg-config 

Take a spin:

 git clone https://github.com/gptrust/gptrust.git
 cd gptrust/
 OPENAI_API_KEY="sk-pasteyouropeaiapikeyhere" cargo run -- --help

Usage example

Setup the API key:

$ export OPENAI_API_KEY=sk-pasteyourapikeyhere 

chat complete (usually the system is ignored, so just using the user prompt) (seems gpt knows more than the wikipedia page though I wonder which model knows more?

$ cargo run -- chat complete --model=gpt-4 --max-tokens=80 "Oberea lutea is a species of"
Result: "beetle in the family Cerambycidae. It is commonly known as the longhorn beetle or the 
         longicorn beetle. These beetles are characterized by their elongated bodies and long 
         antennae, which can be as long as or even longer than their bodies. Oberea lutea is 
         typically yellowish or greenish and can be found in various habitats such as forests, 
         parks" ...etc(1)
$ cargo run -- chat complete --model=gpt-3.5-turbo --max-tokens=80 "Oberea lutea is a species of"
Result: "longhorn beetle found in Europe and western Asia. It is known for its distinctive bright 
         yellow coloration and long antennae, which can be up to twice the length of the beetle's
         body. The larvae of O. lutea feed on various species of deciduous trees, including oak, 
         beech, and birch. This beetle is not considered a major pest, but large populations can 
         cause" ...etc(1)

images generations (prints the URL as well downloads it in local directory):

$ cargo run -- images generations "A fat cat sitting on top of a TV, cartoon"
Result: "https://oaidalleapiprodscus.blob.core.windows.net/private/org-ioVS0wAWUCPVBK4x45pqIGCj/
         user-HeHal853pZkGvhrECcr1Tzoa/img-U4nhGTI4zLuviyDQyUJvstue.png?......" ...etc(1)
$ ls -l img*
-rw-rw-r-- 1 ubuntu ubuntu 787387 Apr 29 11:40 img-U4nhGTI4zLuviyDQyUJvstue.png

audio transcriptions (transcribes an MP3, we can't stream for now, need the file on local disk)

$ cargo run -- audio transcriptions ~/QueenBohemianRhapsody_Mama.ogg.mp3
My bad, just killed a man Put a gun against his head Pulled my trigger, now he's dead

$ cargo run -- audio transcriptions ~/ezekiel-25-17.mp3
The path of the righteous man is beset on all sides by the inequities of the selfish and the
tyranny of evil men. Blessed is he who in the name of charity and goodwill shepherds the weak
through the valley of darkness, for he is truly his brother's keeper and the finder of lost
children. And I will strike down upon thee with great vengeance and furious anger those who
attempt to poison and destroy my brothers. And you will know my name is the Lord when I...

(Of course we know Bohemian Rhapsody starts with a regret but whisper-1 makes it obvious)

Dependencies

~4–11MB
~179K SLoC