Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,16 @@ ORCAROUTER_API_KEY=<your_orcarouter_api_key>

</details>

<details>
<summary><strong>Cheaper Inference</strong></summary>

```bash
# .env
CHEAPERINFERENCE_API_KEY=<your_cheaperinference_api_key>
```

</details>

<details>
<summary><strong>Meta</strong></summary>

Expand Down
29 changes: 29 additions & 0 deletions crates/forge_domain/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ impl ProviderId {
pub const KIMI_CODING: ProviderId = ProviderId(Cow::Borrowed("kimi_coding"));
pub const MOONSHOT: ProviderId = ProviderId(Cow::Borrowed("moonshot"));
pub const ALIBABA_TOKEN_PLAN: ProviderId = ProviderId(Cow::Borrowed("alibaba_token_plan"));
pub const CHEAPER_INFERENCE: ProviderId = ProviderId(Cow::Borrowed("cheaper_inference"));

/// Returns all built-in provider IDs
///
Expand Down Expand Up @@ -135,6 +136,7 @@ impl ProviderId {
ProviderId::KIMI_CODING,
ProviderId::MOONSHOT,
ProviderId::ALIBABA_TOKEN_PLAN,
ProviderId::CHEAPER_INFERENCE,
]
}

Expand Down Expand Up @@ -173,6 +175,7 @@ impl ProviderId {
"neuralwatt" => "Neuralwatt".to_string(),
"orca_router" => "OrcaRouter".to_string(),
"meta" => "Meta".to_string(),
"cheaper_inference" => "Cheaper Inference".to_string(),
_ => {
// For other providers, use UpperCamelCase conversion
use convert_case::{Case, Casing};
Expand Down Expand Up @@ -235,6 +238,7 @@ impl std::str::FromStr for ProviderId {
"kimi_coding" => ProviderId::KIMI_CODING,
"moonshot" => ProviderId::MOONSHOT,
"alibaba_token_plan" => ProviderId::ALIBABA_TOKEN_PLAN,
"cheaper_inference" => ProviderId::CHEAPER_INFERENCE,
// For custom providers, use Cow::Owned to avoid memory leaks
custom => ProviderId(Cow::Owned(custom.to_string())),
};
Expand Down Expand Up @@ -614,6 +618,10 @@ mod tests {
assert_eq!(ProviderId::AMBIENT.to_string(), "Ambient");
assert_eq!(ProviderId::ORCA_ROUTER.to_string(), "OrcaRouter");
assert_eq!(ProviderId::META.to_string(), "Meta");
assert_eq!(
ProviderId::CHEAPER_INFERENCE.to_string(),
"Cheaper Inference"
);
}

#[test]
Expand Down Expand Up @@ -657,6 +665,7 @@ mod tests {
assert!(built_in.contains(&ProviderId::AMBIENT));
assert!(built_in.contains(&ProviderId::ORCA_ROUTER));
assert!(built_in.contains(&ProviderId::META));
assert!(built_in.contains(&ProviderId::CHEAPER_INFERENCE));
}

#[test]
Expand Down Expand Up @@ -792,6 +801,26 @@ mod tests {
assert!(built_in.contains(&ProviderId::META));
}

#[test]
fn test_cheaper_inference_from_str() {
let actual = ProviderId::from_str("cheaper_inference").unwrap();
let expected = ProviderId::CHEAPER_INFERENCE;
assert_eq!(actual, expected);
}

#[test]
fn test_cheaper_inference_display_name() {
let actual = ProviderId::CHEAPER_INFERENCE.to_string();
let expected = "Cheaper Inference".to_string();
assert_eq!(actual, expected);
}

#[test]
fn test_cheaper_inference_in_built_in_providers() {
let built_in = ProviderId::built_in_providers();
assert!(built_in.contains(&ProviderId::CHEAPER_INFERENCE));
}

#[test]
fn test_moonshot_display_name() {
let actual = ProviderId::MOONSHOT.to_string();
Expand Down
9 changes: 9 additions & 0 deletions crates/forge_repo/src/provider/provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -4468,5 +4468,14 @@
}
],
"auth_methods": ["api_key"]
},
{
"id": "cheaper_inference",
"api_key_vars": "CHEAPERINFERENCE_API_KEY",
"url_param_vars": [],
"response_type": "OpenAI",
"url": "https://api.cheaperinference.com/v1/chat/completions",
"models": "https://api.cheaperinference.com/v1/models",
"auth_methods": ["api_key"]
}
]
26 changes: 26 additions & 0 deletions crates/forge_repo/src/provider/provider_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,32 @@ mod tests {
}
}

#[test]
fn test_cheaper_inference_config() {
let configs = get_provider_configs();
let config = configs
.iter()
.find(|c| c.id == ProviderId::CHEAPER_INFERENCE)
.unwrap();
assert_eq!(config.id, ProviderId::CHEAPER_INFERENCE);
assert_eq!(
config.api_key_vars,
Some("CHEAPERINFERENCE_API_KEY".to_string())
);
assert!(config.url_param_vars.is_empty());
assert_eq!(config.response_type, Some(ProviderResponse::OpenAI));
assert_eq!(
config.url.as_str(),
"https://api.cheaperinference.com/v1/chat/completions"
);
match config.models.as_ref().expect("models should be present") {
Models::Url(model_url) => {
assert_eq!(model_url, "https://api.cheaperinference.com/v1/models");
}
other => panic!("expected URL-driven models, got {other:?}"),
}
}

#[test]
fn test_meta_config() {
let configs = get_provider_configs();
Expand Down
Loading