Skip to content

Commit cb5357f

Browse files
authored
Add support for Anthropic AI model in configuration and implementation (#45)
1 parent 6a047b0 commit cb5357f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ AIScript supports the following AI models:
119119

120120
- [x] OpenAI ((uses `OPENAI_API_KEY` environment variable by default))
121121
- [x] DeepSeek
122-
- [ ] Anthropic
122+
- [x] Anthropic
123123

124124
Configuration by `project.toml`:
125125

@@ -133,6 +133,11 @@ model = "gpt-3.5-turbo"
133133
[ai.deepseek]
134134
api_key = "YOUR_API_KEY"
135135
model = "deepseek-chat"
136+
137+
# or use Anthropic
138+
[ai.anthropic]
139+
api_key = "YOUR_API_KEY"
140+
model = "claude-3-5-sonnet-latest"
136141
```
137142

138143
## Roadmap

aiscript-vm/src/ai/mod.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ pub use prompt::{PromptConfig, prompt_with_config};
99

1010
use serde::Deserialize;
1111

12+
// Deepseek
1213
const DEEPSEEK_API_ENDPOINT: &str = "https://api.deepseek.com/v1";
1314
const DEEPSEEK_V3: &str = "deepseek-chat";
1415

16+
// Anthropic
17+
const ANTHROPIC_API_ENDPOINT: &str = "https://api.anthropic.com/v1";
18+
const CLAUDE_3_5_SONNET: &str = "claude-3-5-sonnet-latest";
19+
1520
#[derive(Debug, Clone, Deserialize)]
1621
pub enum AiConfig {
1722
#[serde(rename = "openai")]
@@ -69,7 +74,11 @@ pub(crate) fn openai_client(config: Option<&AiConfig>) -> OpenAIClient {
6974
.with_api_key(api_key)
7075
.build()
7176
.unwrap(),
72-
Some(AiConfig::Anthropic(_)) => unimplemented!("Anthropic API not yet supported"),
77+
Some(AiConfig::Anthropic(ModelConfig { api_key, .. })) => OpenAIClient::builder()
78+
.with_endpoint(ANTHROPIC_API_ENDPOINT)
79+
.with_api_key(api_key)
80+
.build()
81+
.unwrap(),
7382
}
7483
}
7584

@@ -82,6 +91,8 @@ pub(crate) fn default_model(config: Option<&AiConfig>) -> String {
8291
Some(AiConfig::DeepSeek(ModelConfig { model, .. })) => {
8392
model.clone().unwrap_or(DEEPSEEK_V3.to_string())
8493
}
85-
Some(AiConfig::Anthropic(_)) => unimplemented!("Anthropic API not yet supported"),
94+
Some(AiConfig::Anthropic(ModelConfig { model, .. })) => {
95+
model.clone().unwrap_or(CLAUDE_3_5_SONNET.to_string())
96+
}
8697
}
8798
}

0 commit comments

Comments
 (0)