Skip to content

Commit f2f31eb

Browse files
committed
chore: add stringify! and remove redundant macro inputs
1 parent d7050a0 commit f2f31eb

10 files changed

Lines changed: 39 additions & 67 deletions

File tree

src/providers/PROVIDERS.md

Whitespace-only changes.

src/providers/amazon_bedrock/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ crate::openai_compatible_provider!(
1616
AmazonBedrock,
1717
AmazonBedrockBuilder,
1818
AmazonBedrockProviderSettings,
19-
"Amazon Bedrock",
20-
"anthropic.claude-3-5-sonnet-20241022-v2:0",
21-
"anthropic_claude_3_5_sonnet_v1_0()"
19+
"anthropic.claude-3-5-sonnet-20241022-v2:0"
2220
);
2321

2422
// Generate the language model implementation
25-
crate::openai_compatible_language_model!(AmazonBedrock, "Amazon Bedrock");
23+
crate::openai_compatible_language_model!(AmazonBedrock);

src/providers/deepseek/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ crate::openai_compatible_provider!(
1616
DeepSeek,
1717
DeepSeekBuilder,
1818
DeepSeekProviderSettings,
19-
"DeepSeek",
20-
"deepseek-chat",
21-
"deepseek_chat()"
19+
"deepseek-chat"
2220
);
2321

2422
// Generate the language model implementation
25-
crate::openai_compatible_language_model!(DeepSeek, "DeepSeek");
23+
crate::openai_compatible_language_model!(DeepSeek);

src/providers/groq/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ crate::openai_compatible_provider!(
1616
Groq,
1717
GroqBuilder,
1818
GroqProviderSettings,
19-
"Groq",
20-
"llama-3.3-70b-specdec",
21-
"llama_3_3_70b_spec_dec()"
19+
"llama-3.3-70b-specdec"
2220
);
2321

2422
// Generate the language model implementation
25-
crate::openai_compatible_language_model!(Groq, "Groq");
23+
crate::openai_compatible_language_model!(Groq);

src/providers/mistral/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ crate::openai_compatible_provider!(
1616
Mistral,
1717
MistralBuilder,
1818
MistralProviderSettings,
19-
"Mistral",
20-
"mistral-large",
21-
"mistral_large()"
19+
"mistral-large"
2220
);
2321

2422
// Generate the language model implementation
25-
crate::openai_compatible_language_model!(Mistral, "Mistral");
23+
crate::openai_compatible_language_model!(Mistral);

src/providers/openai_chat_completions/macros.rs

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ macro_rules! openai_compatible_settings {
6464
/// # Arguments
6565
///
6666
/// * `$provider_struct` - The name of the provider struct (e.g., `DeepSeek`)
67-
/// * `$provider_display_name` - Display name for the provider (e.g., `"DeepSeek"`)
6867
#[macro_export]
6968
macro_rules! openai_compatible_language_model {
70-
($provider_struct:ident, $provider_display_name:literal) => {
69+
($provider_struct:ident) => {
7170
pub mod language_model {
7271
//! Language model implementation for this provider.
7372
@@ -90,15 +89,15 @@ macro_rules! openai_compatible_language_model {
9089
self.inner.name()
9190
}
9291

93-
#[doc = concat!("Generates text using the ", $provider_display_name, " provider.")]
92+
#[doc = concat!("Generates text using the ", stringify!($provider_struct), " provider.")]
9493
async fn generate_text(
9594
&mut self,
9695
options: LanguageModelOptions,
9796
) -> Result<LanguageModelResponse> {
9897
self.inner.generate_text(options).await
9998
}
10099

101-
#[doc = concat!("Streams text using the ", $provider_display_name, " provider.")]
100+
#[doc = concat!("Streams text using the ", stringify!($provider_struct), " provider.")]
102101
async fn stream_text(
103102
&mut self,
104103
options: LanguageModelOptions,
@@ -115,10 +114,9 @@ macro_rules! openai_compatible_language_model {
115114
/// # Arguments
116115
///
117116
/// * `$provider_struct` - The name of the provider struct (e.g., `OpenRouter`)
118-
/// * `$provider_display_name` - Display name for the provider (e.g., `"OpenRouter"`)
119117
#[macro_export]
120118
macro_rules! openai_compatible_embedding_model {
121-
($provider_struct:ident, $provider_display_name:literal) => {
119+
($provider_struct:ident) => {
122120
pub mod embedding_model {
123121
//! Embedding model implementation for this provider.
124122
@@ -156,18 +154,14 @@ macro_rules! openai_compatible_embedding_model {
156154
/// * `$provider_struct` - The name of the provider struct (e.g., `DeepSeek`)
157155
/// * `$builder_struct` - The name of the builder struct (e.g., `DeepSeekBuilder`)
158156
/// * `$settings_struct` - The name of the settings struct (e.g., `DeepSeekProviderSettings`)
159-
/// * `$provider_display_name` - Display name for the provider (e.g., `"DeepSeek"`)
160157
/// * `$example_model` - Example model identifier for docs (e.g., `"deepseek-chat"`)
161-
/// * `$example_method` - Example constructor method for docs (e.g., `"deepseek_chat()"`)
162158
#[macro_export]
163159
macro_rules! openai_compatible_provider {
164160
(
165161
$provider_struct:ident,
166162
$builder_struct:ident,
167163
$settings_struct:ident,
168-
$provider_display_name:literal,
169-
$example_model:literal,
170-
$example_method:literal
164+
$example_model:literal
171165
) => {
172166
use $crate::Error;
173167
use $crate::core::DynamicModel;
@@ -177,32 +171,32 @@ macro_rules! openai_compatible_provider {
177171
use $crate::providers::openai_chat_completions::OpenAIChatCompletions;
178172
use settings::$settings_struct;
179173

180-
#[doc = concat!("The ", $provider_display_name, " provider, wrapping OpenAI Chat Completions API.")]
174+
#[doc = concat!("The ", stringify!($provider_struct), " provider, wrapping OpenAI Chat Completions API.")]
181175
#[derive(Debug, Clone)]
182176
pub struct $provider_struct<M: ModelName> {
183-
#[doc = concat!("Configuration settings for the ", $provider_display_name, " provider.")]
177+
#[doc = concat!("Configuration settings for the ", stringify!($provider_struct), " provider.")]
184178
pub settings: $settings_struct,
185179
pub(crate) inner: OpenAIChatCompletions<M>,
186180
}
187181

188182
impl<M: ModelName> $provider_struct<M> {
189-
#[doc = concat!($provider_display_name, " provider setting builder.")]
183+
#[doc = concat!(stringify!($provider_struct), " provider setting builder.")]
190184
pub fn builder() -> $builder_struct<M> {
191185
$builder_struct::default()
192186
}
193187
}
194188

195189
impl $provider_struct<DynamicModel> {
196190
#[doc = concat!(
197-
"Creates a ", $provider_display_name, " provider with a dynamic model name using default settings.\n\n",
191+
"Creates a ", stringify!($provider_struct), " provider with a dynamic model name using default settings.\n\n",
198192
"This allows you to specify the model name as a string rather than\n",
199-
"using methods like `", stringify!($provider_struct), "::", $example_method, "`, etc.\n\n",
193+
"using typed constructor methods.\n\n",
200194
"**WARNING**: when using `DynamicModel`, model capabilities are not validated.\n",
201195
"This means there is no compile-time guarantee that the model supports requested features.\n\n",
202196
"For custom configuration (API key, base URL, etc.), use the builder pattern:\n",
203197
"`", stringify!($provider_struct), "::<DynamicModel>::builder().model_name(...).api_key(...).build()`\n\n",
204198
"# Parameters\n\n",
205-
"* `model_name` - The ", $provider_display_name, " model identifier (e.g., \"", $example_model, "\")\n\n",
199+
"* `model_name` - The model identifier (e.g., \"", $example_model, "\")\n\n",
206200
"# Returns\n\n",
207201
"A configured `", stringify!($provider_struct), "<DynamicModel>` provider instance with default settings."
208202
)]
@@ -215,20 +209,20 @@ macro_rules! openai_compatible_provider {
215209
}
216210

217211
impl<M: ModelName> Default for $provider_struct<M> {
218-
#[doc = concat!("Creates a new ", $provider_display_name, " provider with default settings.")]
212+
#[doc = concat!("Creates a new ", stringify!($provider_struct), " provider with default settings.")]
219213
fn default() -> $provider_struct<M> {
220214
$builder_struct::default().build().unwrap()
221215
}
222216
}
223217

224-
#[doc = concat!($provider_display_name, " provider builder")]
218+
#[doc = concat!(stringify!($provider_struct), " provider builder")]
225219
pub struct $builder_struct<M: ModelName> {
226220
settings: $settings_struct,
227221
inner: OpenAIChatCompletions<M>,
228222
}
229223

230224
impl<M: ModelName> Default for $builder_struct<M> {
231-
#[doc = concat!("Creates a new ", $provider_display_name, " provider builder with default settings.")]
225+
#[doc = concat!("Creates a new ", stringify!($provider_struct), " provider builder with default settings.")]
232226
fn default() -> Self {
233227
let settings = $settings_struct::default();
234228
let mut inner = OpenAIChatCompletions::default();
@@ -242,7 +236,7 @@ macro_rules! openai_compatible_provider {
242236

243237
impl<M: ModelName> $builder_struct<M> {
244238
#[doc = concat!(
245-
"Sets the provider name for the ", $provider_display_name, " provider.\n\n",
239+
"Sets the provider name for the ", stringify!($provider_struct), " provider.\n\n",
246240
"# Parameters\n\n",
247241
"* `provider_name` - The provider name string.\n\n",
248242
"# Returns\n\n",
@@ -256,7 +250,7 @@ macro_rules! openai_compatible_provider {
256250
}
257251

258252
#[doc = concat!(
259-
"Sets the base URL for the ", $provider_display_name, " provider.\n\n",
253+
"Sets the base URL for the ", stringify!($provider_struct), " provider.\n\n",
260254
"# Parameters\n\n",
261255
"* `base_url` - The base URL string for API requests.\n\n",
262256
"# Returns\n\n",
@@ -270,7 +264,7 @@ macro_rules! openai_compatible_provider {
270264
}
271265

272266
#[doc = concat!(
273-
"Sets the API key for the ", $provider_display_name, " provider.\n\n",
267+
"Sets the API key for the ", stringify!($provider_struct), " provider.\n\n",
274268
"# Parameters\n\n",
275269
"* `api_key` - The API key string for authentication.\n\n",
276270
"# Returns\n\n",
@@ -284,7 +278,7 @@ macro_rules! openai_compatible_provider {
284278
}
285279

286280
#[doc = concat!(
287-
"Builds the ", $provider_display_name, " provider.\n\n",
281+
"Builds the ", stringify!($provider_struct), " provider.\n\n",
288282
"Validates the configuration and creates the provider instance.\n\n",
289283
"# Returns\n\n",
290284
"A `Result` containing the configured `", stringify!($provider_struct), "<M>` or an `Error`."
@@ -314,10 +308,9 @@ macro_rules! openai_compatible_provider {
314308
"Sets the model name from a string. e.g., \"", $example_model, "\"\n\n",
315309
"**WARNING**: when using `DynamicModel`, model capabilities are not validated.\n",
316310
"This means there is no compile-time guarantee that the model supports requested features.\n\n",
317-
"For compile-time model validation, use the constructor methods like `",
318-
stringify!($provider_struct), "::", $example_method, "`.\n\n",
311+
"For compile-time model validation, use typed constructor methods.\n\n",
319312
"# Parameters\n\n",
320-
"* `model_name` - The ", $provider_display_name, " model identifier (e.g., \"", $example_model, "\")\n\n",
313+
"* `model_name` - The model identifier (e.g., \"", $example_model, "\")\n\n",
321314
"# Returns\n\n",
322315
"The builder with the model name set."
323316
)]

src/providers/openrouter/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ crate::openai_compatible_provider!(
1616
OpenRouter,
1717
OpenRouterBuilder,
1818
OpenRouterProviderSettings,
19-
"OpenRouter",
20-
"anthropic/claude-3.5-sonnet",
21-
"anthropic_claude_3_5_sonnet()"
19+
"anthropic/claude-3.5-sonnet"
2220
);
2321

2422
// Generate the language model implementation
25-
crate::openai_compatible_language_model!(OpenRouter, "OpenRouter");
23+
crate::openai_compatible_language_model!(OpenRouter);
2624

2725
// Generate the embedding model implementation
28-
crate::openai_compatible_embedding_model!(OpenRouter, "OpenRouter");
26+
crate::openai_compatible_embedding_model!(OpenRouter);

src/providers/togetherai/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ crate::openai_compatible_provider!(
1616
TogetherAI,
1717
TogetherAIBuilder,
1818
TogetherAIProviderSettings,
19-
"Together AI",
20-
"Llama-3.3-70B-Instruct-Turbo",
21-
"llama_3_3_70b_spec_dec()"
19+
"Llama-3.3-70B-Instruct-Turbo"
2220
);
2321

2422
// Generate the language model implementation
25-
crate::openai_compatible_language_model!(TogetherAI, "Together AI");
23+
crate::openai_compatible_language_model!(TogetherAI);
2624

2725
// Generate the embedding model implementation
28-
crate::openai_compatible_embedding_model!(TogetherAI, "Together AI");
26+
crate::openai_compatible_embedding_model!(TogetherAI);

src/providers/vercel/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ crate::openai_compatible_provider!(
1616
Vercel,
1717
VercelBuilder,
1818
VercelProviderSettings,
19-
"Vercel",
20-
"claude-3-5-haiku-2024-10-22",
21-
"claude_3_5_haiku()"
19+
"claude-3-5-haiku-2024-10-22"
2220
);
2321

2422
// Generate the language model implementation
25-
crate::openai_compatible_language_model!(Vercel, "Vercel");
23+
crate::openai_compatible_language_model!(Vercel);
2624

2725
// Generate the embedding model implementation
28-
crate::openai_compatible_embedding_model!(Vercel, "Vercel");
26+
crate::openai_compatible_embedding_model!(Vercel);

src/providers/xai/mod.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ crate::openai_compatible_settings!(
1212
);
1313

1414
// Generate the provider struct and builder
15-
crate::openai_compatible_provider!(
16-
XAI,
17-
XAIBuilder,
18-
XAISettings,
19-
"xAI",
20-
"grok-2-latest",
21-
"grok_2()"
22-
);
15+
crate::openai_compatible_provider!(XAI, XAIBuilder, XAISettings, "grok-2-latest");
2316

2417
// Generate the language model implementation
25-
crate::openai_compatible_language_model!(XAI, "xAI");
18+
crate::openai_compatible_language_model!(XAI);

0 commit comments

Comments
 (0)