Skip to content

Add support for Anthropic AI model in configuration and implementation #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2025
Merged
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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ AIScript supports the following AI models:

- [x] OpenAI ((uses `OPENAI_API_KEY` environment variable by default))
- [x] DeepSeek
- [ ] Anthropic
- [x] Anthropic

Configuration by `project.toml`:

Expand All @@ -133,6 +133,11 @@ model = "gpt-3.5-turbo"
[ai.deepseek]
api_key = "YOUR_API_KEY"
model = "deepseek-chat"

# or use Anthropic
[ai.anthropic]
api_key = "YOUR_API_KEY"
model = "claude-3-5-sonnet-latest"
```

## Roadmap
Expand Down
15 changes: 13 additions & 2 deletions aiscript-vm/src/ai/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ pub use prompt::{PromptConfig, prompt_with_config};

use serde::Deserialize;

// Deepseek
const DEEPSEEK_API_ENDPOINT: &str = "https://api.deepseek.com/v1";
const DEEPSEEK_V3: &str = "deepseek-chat";

// Anthropic
const ANTHROPIC_API_ENDPOINT: &str = "https://api.anthropic.com/v1";
const CLAUDE_3_5_SONNET: &str = "claude-3-5-sonnet-latest";

#[derive(Debug, Clone, Deserialize)]
pub enum AiConfig {
#[serde(rename = "openai")]
Expand Down Expand Up @@ -69,7 +74,11 @@ pub(crate) fn openai_client(config: Option<&AiConfig>) -> OpenAIClient {
.with_api_key(api_key)
.build()
.unwrap(),
Some(AiConfig::Anthropic(_)) => unimplemented!("Anthropic API not yet supported"),
Some(AiConfig::Anthropic(ModelConfig { api_key, .. })) => OpenAIClient::builder()
.with_endpoint(ANTHROPIC_API_ENDPOINT)
.with_api_key(api_key)
.build()
.unwrap(),
}
}

Expand All @@ -82,6 +91,8 @@ pub(crate) fn default_model(config: Option<&AiConfig>) -> String {
Some(AiConfig::DeepSeek(ModelConfig { model, .. })) => {
model.clone().unwrap_or(DEEPSEEK_V3.to_string())
}
Some(AiConfig::Anthropic(_)) => unimplemented!("Anthropic API not yet supported"),
Some(AiConfig::Anthropic(ModelConfig { model, .. })) => {
model.clone().unwrap_or(CLAUDE_3_5_SONNET.to_string())
}
}
}
Loading