Skip to content

Commit 04df775

Browse files
committed
add openAI call
1 parent 7722fe4 commit 04df775

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/api_handler/call_request.rs

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
1-
use crate::models::general::llm::{Message};
1+
use crate::models::general::llm::Message;
22

33
use dotenv::dotenv;
4+
use reqwest::header::{HeaderMap, HeaderValue};
45
use std::env;
6+
// backend_hive
57

6-
use reqwest::Client;
7-
8-
9-
//call LLM GPT
8+
// Call LLM GPT
109
pub async fn call_gpt(message: Vec<Message>) {
1110
dotenv().ok();
1211

13-
//extract api keys
14-
let api_keys: String = env::var("GPT_API_KEY").expect("GPT_API_KEY");
12+
// Extract api keys
13+
let api_key: String = env::var("OPEN_AI_KEY").expect("OPEN_AI_KEY not found");
14+
let api_org: String = env::var("OPEN_AI_ORG").expect("OPEN_AI_ORG not found");
15+
16+
// Confirm endpoint
17+
let url: &str = "https://api.openai.com/v1/chat/completions";
18+
19+
// Create headers
20+
let mut headers = HeaderMap::new();
21+
22+
// Create api key headers
23+
headers.insert(
24+
"authorization",
25+
HeaderValue::from_str(&format!("Bearer {}", api_key)).unwrap(),
26+
);
1527

28+
// Create OpenAI org Header
29+
headers.insert(
30+
"OpenAI-Organization",
31+
HeaderValue::from_str(&api_org.as_str()).unwrap(),
32+
);
1633
}

0 commit comments

Comments
 (0)