Skip to content

Commit 088ebf1

Browse files
committed
feat: introduce --check flag to validate OpenAI API and model availability 🔍
- Add --check CLI flag to verify API key and model availability - Implement check_model method to list and validate models server-side - Integrate error handling for invalid keys or models in main.rs - Update Cargo.toml to remove unused dependencies and categorize package fields - Store last validation timestamp in configuration for audit purposes Signed-off-by: mingcheng <[email protected]>
1 parent e973114 commit 088ebf1

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* File Created: 2025-03-01 17:17:30
1010
*
1111
* Modified By: mingcheng ([email protected])
12-
* Last Modified: 2025-09-26 14:43:17
12+
* Last Modified: 2025-09-26 15:45:37
1313
*/
1414

1515
use aigitcommit::cli::Cli;
@@ -88,6 +88,8 @@ async fn main() -> std::result::Result<(), Box<dyn Error>> {
8888
// Check if the model name is valid
8989
if cli.check {
9090
trace!("check option is enabled, will check the OpenAI API key and model name");
91+
debug!("the model name is `{}`", &model_name);
92+
9193
match client.check_model(&model_name).await {
9294
Ok(()) => {
9395
debug!("the model name `{}` is available", model_name);

src/openai.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
* File Created: 2025-03-01 21:55:58
1010
*
1111
* Modified By: mingcheng ([email protected])
12-
* Last Modified: 2025-09-26 14:43:10
12+
* Last Modified: 2025-09-26 15:51:48
1313
*/
1414

15-
use crate::cli;
15+
use crate::cli::{CMD, CMD_ABOUT, CMD_ABOUT_URL};
1616
use askama::Template;
1717
use async_openai::config::OPENAI_API_BASE;
1818
use async_openai::error::OpenAIError;
@@ -55,15 +55,19 @@ impl OpenAI {
5555
.with_api_base(
5656
env::var("OPENAI_API_BASE").unwrap_or_else(|_| String::from(OPENAI_API_BASE)),
5757
)
58-
.with_org_id(cli::CMD);
58+
.with_org_id(CMD);
5959

6060
// Set up HTTP client builder with default headers
61-
let mut http_client_builder = ClientBuilder::new().user_agent(cli::CMD).default_headers({
62-
let mut headers = HeaderMap::new();
63-
headers.insert("HTTP-Referer", HeaderValue::from_static(cli::CMD_ABOUT_URL));
64-
headers.insert("X-Title", HeaderValue::from_static(cli::CMD));
65-
headers
66-
});
61+
let mut http_client_builder = ClientBuilder::new()
62+
.user_agent(format!("{}({})", CMD, CMD_ABOUT))
63+
.default_headers({
64+
let mut headers = HeaderMap::new();
65+
headers.insert("HTTP-Referer", HeaderValue::from_static(CMD_ABOUT_URL));
66+
headers.insert("X-Title", HeaderValue::from_static(CMD));
67+
headers.insert("X-Client", HeaderValue::from_static(CMD));
68+
headers.insert("X-Client-Type", HeaderValue::from_static("CLI"));
69+
headers
70+
});
6771

6872
// Set up proxy if specified
6973
let proxy_addr: String = env::var("OPENAI_API_PROXY").unwrap_or_else(|_| String::from(""));

0 commit comments

Comments
 (0)