Implement MVP test
This commit is contained in:
parent
c91252e552
commit
ded63bc494
1504
Cargo.lock
generated
Normal file
1504
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,3 +6,7 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = "1.0.71"
|
||||||
|
openai_rs = { path = "./OpenAI-Rust" }
|
||||||
|
tiktoken = { path = "./tiktoken" }
|
||||||
|
tokio = { version = "1.28.2", features = ["full"] }
|
||||||
|
34
src/main.rs
34
src/main.rs
@ -1,3 +1,33 @@
|
|||||||
fn main() {
|
use openai_rs::{chat::{ChatHistoryBuilder, ChatMessage, Role}, context::Context};
|
||||||
println!("Hello, world!");
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
println!("Getting API key");
|
||||||
|
let ctx = get_api().unwrap();
|
||||||
|
|
||||||
|
println!("Generating completion...");
|
||||||
|
let completion = ctx
|
||||||
|
.create_chat_completion_sync(
|
||||||
|
ChatHistoryBuilder::default()
|
||||||
|
.messages(vec![ChatMessage::new(Role::User, "Who are you?")])
|
||||||
|
.model("gpt-4"),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert!(
|
||||||
|
completion.is_ok(),
|
||||||
|
"Could not create completion: {}",
|
||||||
|
completion.unwrap_err()
|
||||||
|
);
|
||||||
|
|
||||||
|
let result = completion.unwrap();
|
||||||
|
assert!(result.choices.len() == 1, "No completion found");
|
||||||
|
println!("Got completion: {:?}", result.choices[0].message);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_api() -> anyhow::Result<Context> {
|
||||||
|
Ok(Context::new(
|
||||||
|
std::fs::read_to_string(std::path::Path::new("apikey.txt"))?
|
||||||
|
.trim()
|
||||||
|
.to_string(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user