Skip to content

Commit

Permalink
Switch OAI to tokenizer
Browse files Browse the repository at this point in the history
  • Loading branch information
brianreicher committed Nov 18, 2023
1 parent aeb979c commit 02aa21e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tokenizer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod oai;
pub mod tokenizer;
pub mod pinecone_utils;
6 changes: 3 additions & 3 deletions tokenizer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ async fn main() -> std::io::Result<()> {
mongo.connect().await?;

// set collection to tokenize
let collection = "github_data";
let oai_key = "generate_2023";
let collection: &str = "github_data";
let oai_key: &str = "generate_2023";

// TODO: create a new collection for each repo, insert documents into sub collections
let tokenizer: OpenAIClient = OpenAIClient::new(oai_key, mongo, collection);
let tokenizer: Tokenizer = Tokenizer::new(oai_key, mongo, collection);
tokenizer.tokenize_collection(collection);

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions tokenizer/src/oai.rs → tokenizer/src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use std::error::Error;
use std::env;


pub struct OpenAIClient {
pub struct Tokenizer {
oai_client: Client,
mongo_model: &MongoDriver,
collection: String,
}

impl OpenAIClient {
impl Tokenizer {

pub fn new(openai_api_key: &str, mongo_model: &MongoDriver, collection: &str) -> Self {
OpenAIClient {
Expand All @@ -35,7 +35,7 @@ impl OpenAIClient {
let args: openai_rust::embeddings::EmbeddingsArguments = openai_rust::embeddings::EmbeddingsArguments::new("text-embedding-ada-002", text.to_owned());
let embedding: Vec<openai_rust::embeddings::EmbeddingsData> = self.oai_client.create_embeddings(args).await.unwrap().data;

let update_doc = doc! {
let update_doc: Document = doc! {
"$set": { "embedding": embedding }
};

Expand Down

0 comments on commit 02aa21e

Please sign in to comment.