Skip to content

Commit

Permalink
fix: implement review suggestions + renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
0xMochan committed Sep 23, 2024
1 parent 6dd9cd1 commit 1e39374
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions rig-core/src/providers/anthropic/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use serde::{Deserialize, Serialize};
use super::completion::{CompletionModel, ANTHROPIC_VERSION_LATEST};

// ================================================================
// Main Cohere Client
// Main Anthropic Client
// ================================================================
const COHERE_API_BASE_URL: &str = "https://api.anthropic.com";
const ANTHROPIC_API_BASE_URL: &str = "https://api.anthropic.com";

#[derive(Clone)]
pub struct ClientBuilder<'a> {
Expand All @@ -28,7 +28,6 @@ pub struct ClientBuilder<'a> {
///
/// // Initialize the Anthropic client
/// let anthropic_client = ClientBuilder::new("your-claude-api-key")
/// .base_url("https://api.anthropic.com")
/// .anthropic_version(ANTHROPIC_VERSION_LATEST)
/// .anthropic_beta("prompt-caching-2024-07-31")
/// .build()
Expand All @@ -37,7 +36,7 @@ impl<'a> ClientBuilder<'a> {
pub fn new(api_key: &'a str) -> Self {
Self {
api_key,
base_url: COHERE_API_BASE_URL,
base_url: ANTHROPIC_API_BASE_URL,
anthropic_version: ANTHROPIC_VERSION_LATEST,
anthropic_betas: None,
}
Expand Down Expand Up @@ -80,6 +79,13 @@ pub struct Client {
}

impl Client {
/// Create a new Anthropic client with the given API key, base URL, betas, and version.
/// Note, you proably want to use the `ClientBuilder` instead.
///
/// Panics:
/// - If the API key or version cannot be parsed as a Json value from a String.
/// - This should really never happen.
/// - If the reqwest client cannot be built (if the TLS backend cannot be initialized).
pub fn new(api_key: &str, base_url: &str, betas: Option<Vec<&str>>, version: &str) -> Self {
Self {
base_url: base_url.to_string(),
Expand All @@ -103,7 +109,7 @@ impl Client {
headers
})
.build()
.expect("Cohere reqwest client should build"),
.expect("Anthropic reqwest client should build"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion rig-core/src/providers/anthropic/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub struct ToolDefinition {
#[derive(Debug, Deserialize, Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum CacheControl {
Ephemeral {},
Ephemeral,
}

impl TryFrom<CompletionResponse> for completion::CompletionResponse<CompletionResponse> {
Expand Down

0 comments on commit 1e39374

Please sign in to comment.