mirror of
https://github.com/mii443/openai-api-rs.git
synced 2025-08-22 15:15:34 +00:00
Add models api
This commit is contained in:
@ -23,7 +23,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("Content: {:?}", result.choices[0].message.content);
|
||||
|
||||
// print response headers
|
||||
for (key, value) in client.headers.unwrap().iter() {
|
||||
for (key, value) in client.response_headers.unwrap().iter() {
|
||||
println!("{}: {:?}", key, value);
|
||||
}
|
||||
|
||||
|
23
examples/model.rs
Normal file
23
examples/model.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use openai_api_rs::v1::api::OpenAIClient;
|
||||
use std::env;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
|
||||
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;
|
||||
|
||||
let result = client.list_models().await?;
|
||||
let models = result.data;
|
||||
|
||||
for model in models {
|
||||
println!("Model id: {:?}", model.id);
|
||||
}
|
||||
|
||||
let result = client.retrieve_model("gpt-4.1".to_string()).await?;
|
||||
println!("Model id: {:?}", result.id);
|
||||
println!("Model object: {:?}", result.object);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// OPENAI_API_KEY=xxxx cargo run --package openai-api-rs --example model
|
@ -24,7 +24,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let result = client.chat_completion(req).await?;
|
||||
println!("Content: {:?}", result.choices[0].message.content);
|
||||
println!("Response Headers: {:?}", client.headers);
|
||||
println!("Response Headers: {:?}", client.response_headers);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user