feat(conversation): add proxy support for Anthropic API
- Add https-proxy-agent dependency - Configure httpAgent in ClaudeAgentService when ANTHROPIC_PROXY_URL is set - Add ANTHROPIC_PROXY_URL environment variable to docker-compose.yml Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
210e752223
commit
c6c9623f36
|
|
@ -232,6 +232,7 @@ services:
|
||||||
REDIS_URL: redis://:${REDIS_PASSWORD:-redis123}@redis:6379
|
REDIS_URL: redis://:${REDIS_PASSWORD:-redis123}@redis:6379
|
||||||
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY}
|
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY}
|
||||||
ANTHROPIC_BASE_URL: ${ANTHROPIC_BASE_URL:-https://api.anthropic.com}
|
ANTHROPIC_BASE_URL: ${ANTHROPIC_BASE_URL:-https://api.anthropic.com}
|
||||||
|
ANTHROPIC_PROXY_URL: ${ANTHROPIC_PROXY_URL:-}
|
||||||
KNOWLEDGE_SERVICE_URL: http://knowledge-service:3003
|
KNOWLEDGE_SERVICE_URL: http://knowledge-service:3003
|
||||||
CORS_ORIGINS: https://iconsulting.szaiai.com,http://localhost:5173
|
CORS_ORIGINS: https://iconsulting.szaiai.com,http://localhost:5173
|
||||||
ports:
|
ports:
|
||||||
|
|
@ -262,6 +263,7 @@ services:
|
||||||
REDIS_URL: redis://:${REDIS_PASSWORD:-redis123}@redis:6379
|
REDIS_URL: redis://:${REDIS_PASSWORD:-redis123}@redis:6379
|
||||||
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY}
|
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY}
|
||||||
ANTHROPIC_BASE_URL: ${ANTHROPIC_BASE_URL:-https://api.anthropic.com}
|
ANTHROPIC_BASE_URL: ${ANTHROPIC_BASE_URL:-https://api.anthropic.com}
|
||||||
|
ANTHROPIC_PROXY_URL: ${ANTHROPIC_PROXY_URL:-}
|
||||||
ports:
|
ports:
|
||||||
- "3005:3005"
|
- "3005:3005"
|
||||||
networks:
|
networks:
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,8 @@
|
||||||
"rxjs": "^7.8.0",
|
"rxjs": "^7.8.0",
|
||||||
"socket.io": "^4.8.3",
|
"socket.io": "^4.8.3",
|
||||||
"typeorm": "^0.3.19",
|
"typeorm": "^0.3.19",
|
||||||
"uuid": "^9.0.0"
|
"uuid": "^9.0.0",
|
||||||
|
"https-proxy-agent": "^7.0.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nestjs/cli": "^10.0.0",
|
"@nestjs/cli": "^10.0.0",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { Injectable, OnModuleInit } from '@nestjs/common';
|
import { Injectable, OnModuleInit } from '@nestjs/common';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import Anthropic from '@anthropic-ai/sdk';
|
import Anthropic from '@anthropic-ai/sdk';
|
||||||
|
import { HttpsProxyAgent } from 'https-proxy-agent';
|
||||||
import { ImmigrationToolsService } from './tools/immigration-tools.service';
|
import { ImmigrationToolsService } from './tools/immigration-tools.service';
|
||||||
import { buildSystemPrompt, SystemPromptConfig } from './prompts/system-prompt';
|
import { buildSystemPrompt, SystemPromptConfig } from './prompts/system-prompt';
|
||||||
|
|
||||||
|
|
@ -33,9 +34,19 @@ export class ClaudeAgentService implements OnModuleInit {
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
onModuleInit() {
|
onModuleInit() {
|
||||||
this.client = new Anthropic({
|
const proxyUrl = this.configService.get<string>('ANTHROPIC_PROXY_URL');
|
||||||
|
const clientOptions: Anthropic.ClientOptions = {
|
||||||
apiKey: this.configService.get<string>('ANTHROPIC_API_KEY'),
|
apiKey: this.configService.get<string>('ANTHROPIC_API_KEY'),
|
||||||
});
|
};
|
||||||
|
|
||||||
|
// Configure proxy if specified
|
||||||
|
if (proxyUrl) {
|
||||||
|
console.log(`Using proxy for Anthropic API: ${proxyUrl}`);
|
||||||
|
const agent = new HttpsProxyAgent(proxyUrl);
|
||||||
|
clientOptions.httpAgent = agent;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.client = new Anthropic(clientOptions);
|
||||||
|
|
||||||
// Initialize with default config
|
// Initialize with default config
|
||||||
this.systemPromptConfig = {
|
this.systemPromptConfig = {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue