Skip to content

Commit

Permalink
Rename openai_utils module to openai_bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinegb committed Feb 17, 2023
1 parent dacfde2 commit 0f622c8
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 42 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ features = ["derive"]
[dependencies.openai_proc_macros]
path = "openai_proc_macros"

[dependencies.openai_utils]
path = "openai_utils"
[dependencies.openai_bootstrap]
path = "openai_bootstrap"

[dev-dependencies.tokio]
version = "1.25"
Expand Down
2 changes: 1 addition & 1 deletion openai_utils/Cargo.toml → openai_bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "openai_utils"
name = "openai_bootstrap"
version.workspace = true
authors.workspace = true
edition.workspace = true
Expand Down
17 changes: 17 additions & 0 deletions openai_bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pub const BASE_URL: &str = "https://api.openai.com/v1";

#[macro_export]
macro_rules! authorization {
($request:expr) => {{
use dotenvy::dotenv;
use reqwest::{header::AUTHORIZATION, RequestBuilder};
use std::env;

dotenv().ok();

let token =
env::var("OPENAI_KEY").expect("environment variable `OPENAI_KEY` should be defined");

$request.header(AUTHORIZATION, format!("Bearer {token}"))
}};
}
4 changes: 2 additions & 2 deletions openai_proc_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ convert_case = "0.6"
version = "0.11"
features = [ "blocking", "json" ]

[dependencies.openai_utils]
path = "../openai_utils"
[dependencies.openai_bootstrap]
path = "../openai_bootstrap"

[dependencies.serde]
version = "1.0"
Expand Down
16 changes: 8 additions & 8 deletions openai_proc_macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use convert_case::{Case, Casing};
use openai_bootstrap::{authorization, BASE_URL};
use proc_macro::TokenStream;
use quote::{ quote, format_ident };
use quote::{format_ident, quote};
use reqwest::blocking::Client;
use openai_utils::{ BASE_URL, authorization };
use serde::Deserialize;
use convert_case::{ Case, Casing };

#[derive(Deserialize)]
struct Models {
Expand All @@ -20,18 +20,18 @@ pub fn generate_model_id_enum(_input: TokenStream) -> TokenStream {
let client = Client::new();

let response: Models = authorization!(client.get(format!("{BASE_URL}/models")))
.send().unwrap().json().unwrap();
.send()
.unwrap()
.json()
.unwrap();

let mut model_id_idents = Vec::new();
let mut model_ids = Vec::new();
let mut model_indexes = Vec::new();
let mut index: u32 = 0;

for model in response.data {
if model.id.contains(':')
|| model.id.contains('.')
|| model.id.contains("deprecated")
{
if model.id.contains(':') || model.id.contains('.') || model.id.contains("deprecated") {
continue;
}

Expand Down
19 changes: 0 additions & 19 deletions openai_utils/src/lib.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{ Deserialize, Serialize };
use super::{ models::ModelID, Usage };
use std::collections::HashMap;
use reqwest::Client;
use openai_utils::{ BASE_URL, authorization };
use openai_bootstrap::{ BASE_URL, authorization };

#[derive(Deserialize)]
pub struct Completion {
Expand Down
2 changes: 1 addition & 1 deletion src/edits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use serde::{ Deserialize, Serialize };
use super::{ Usage, models::ModelID };
use reqwest::Client;
use openai_utils::{ BASE_URL, authorization };
use openai_bootstrap::{ BASE_URL, authorization };

#[derive(Deserialize)]
pub struct Edit {
Expand Down
2 changes: 1 addition & 1 deletion src/embeddings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use serde::{ Deserialize, Serialize };
use reqwest::Client;
use super::{ models::ModelID, Usage };
use openai_utils::{ BASE_URL, authorization };
use openai_bootstrap::{ BASE_URL, authorization };

#[derive(Serialize)]
struct CreateEmbeddingsRequestBody<'a> {
Expand Down
2 changes: 1 addition & 1 deletion src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use serde::Deserialize;
use reqwest::Client;
use openai_proc_macros::generate_model_id_enum;
use openai_utils::{ BASE_URL, authorization };
use openai_bootstrap::{ BASE_URL, authorization };

#[derive(Deserialize)]
pub struct Model {
Expand Down

0 comments on commit 0f622c8

Please sign in to comment.