-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcreate_providers.sh
More file actions
executable file
·81 lines (62 loc) · 1.95 KB
/
create_providers.sh
File metadata and controls
executable file
·81 lines (62 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# Script to create provider template files
# Usage: ./create_providers.sh
PROVIDERS=("empower" "exa_ai" "firecrawl")
for PROVIDER in "${PROVIDERS[@]}"; do
PROVIDER_DIR="src/core/providers/${PROVIDER}"
mkdir -p "${PROVIDER_DIR}"
# Capitalize provider name for struct names
PROVIDER_STRUCT=$(echo "${PROVIDER}" | sed 's/_/ /g' | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2))}1' | sed 's/ //g')
# mod.rs
cat > "${PROVIDER_DIR}/mod.rs" <<EOF
//! ${PROVIDER_STRUCT} Provider
pub mod client;
pub mod config;
pub mod error;
pub mod models;
pub mod provider;
pub mod streaming;
pub use client::${PROVIDER_STRUCT}Client;
pub use config::${PROVIDER_STRUCT}Config;
pub use error::${PROVIDER_STRUCT}ErrorMapper;
pub use models::{${PROVIDER_STRUCT}ModelRegistry, get_${PROVIDER}_registry};
pub use provider::${PROVIDER_STRUCT}Provider;
EOF
# config.rs
cat > "${PROVIDER_DIR}/config.rs" <<EOF
//! ${PROVIDER_STRUCT} Configuration
use crate::core::traits::ProviderConfig;
use crate::define_provider_config;
define_provider_config!(${PROVIDER_STRUCT}Config {});
impl ${PROVIDER_STRUCT}Config {
pub fn from_env() -> Self {
Self::new("${PROVIDER}")
}
pub fn get_api_base(&self) -> String {
self.base
.api_base
.clone()
.unwrap_or_else(|| "https://api.example.com".to_string())
}
}
impl ProviderConfig for ${PROVIDER_STRUCT}Config {
fn validate(&self) -> Result<(), String> {
self.base.validate("${PROVIDER}")
}
fn api_key(&self) -> Option<&str> {
self.base.api_key.as_deref()
}
fn api_base(&self) -> Option<&str> {
self.base.api_base.as_deref()
}
fn timeout(&self) -> std::time::Duration {
self.base.timeout_duration()
}
fn max_retries(&self) -> u32 {
self.base.max_retries
}
}
EOF
echo "Created provider: ${PROVIDER}"
done
echo "All providers created successfully!"