Anthropic Module¶
Overview¶
The Anthropic module provides integration with Anthropic's Claude language models. This module configures and manages connections to Claude models for AI-powered functionality within the BidScript application.
Configuration¶
The Anthropic integration is configured in anthropic.config.ts, which includes:
- API key management
- Model configuration (Claude 3.5 Sonnet, Claude 3.7 Sonnet)
- Error handling and logging
Key Components¶
AnthropicConfigService¶
The AnthropicConfigService is the main service responsible for:
- Loading and validating Anthropic API credentials
- Providing model-specific configurations
- Managing deployment keys
export type DeploymentKey =
| ModelType.CLAUDE_3_7_SONNET
| ModelType.CLAUDE_3_5_SONNET;
@Injectable()
export class AnthropicConfigService {
private readonly logger = new Logger(AnthropicConfigService.name);
private readonly anthropicApiConfig: Record<DeploymentKey, AnthropicConfig>;
constructor(private configService: ConfigService) {
// Load configuration from environment variables
const anthropic_key = this.configService.get<string>("ANTHROPIC_API_KEY");
this.anthropicApiConfig = {
[ModelType.CLAUDE_3_7_SONNET]: {
apiKey: anthropic_key || "",
},
[ModelType.CLAUDE_3_5_SONNET]: {
apiKey: anthropic_key || "",
},
};
}
// Methods to access and validate configurations
}
Integration with Other Modules¶
The Anthropic module integrates with:
- Chat Module: For generating responses in chat contexts
- RAG Module: For retrieval-augmented generation with Claude models
- LangChain Module: For chaining together LLM operations
Environment Variables¶
The module requires the following environment variables:
ANTHROPIC_API_KEY: API key for accessing Anthropic's Claude API
Usage Example¶
// Example of using the Anthropic module for generating text
import { AnthropicConfigService } from "./anthropic/anthropic.config";
import { ModelType } from "./config/model.config";
import { Anthropic } from "@langchain/anthropic";
// In a service that uses Anthropic
@Injectable()
export class SomeService {
constructor(private anthropicConfigService: AnthropicConfigService) {}
async generateText(prompt: string): Promise<string> {
const config = this.anthropicConfigService.getConfig(
ModelType.CLAUDE_3_5_SONNET
);
const model = new Anthropic({
apiKey: config.apiKey,
});
const response = await model.invoke(prompt);
return response;
}
}
Dependencies¶
@langchain/anthropic: LangChain integration for Anthropic models@nestjs/config: NestJS configuration module