feat(embedding): add OpenAI proxy support for IP-based URLs
- Add OPENAI_BASE_URL configuration to .env.example - Update EmbeddingService to disable TLS verification for IP-based proxy URLs - Mirror the same proxy handling pattern used in Anthropic API Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
925283d8e6
commit
91f8792110
|
|
@ -35,6 +35,8 @@ ANTHROPIC_BASE_URL=https://api.anthropic.com
|
|||
# OpenAI API (用于 Embedding)
|
||||
# ===========================================
|
||||
OPENAI_API_KEY=sk-xxx
|
||||
# 如果在中国大陆部署,需要配置代理地址
|
||||
# OPENAI_BASE_URL=https://your-openai-proxy.com/v1
|
||||
|
||||
# ===========================================
|
||||
# PostgreSQL Database
|
||||
|
|
|
|||
|
|
@ -22,12 +22,25 @@ export class EmbeddingService implements OnModuleInit {
|
|||
return;
|
||||
}
|
||||
|
||||
const baseURL = this.configService.get<string>('OPENAI_BASE_URL');
|
||||
const isProxyUrl = baseURL && (baseURL.match(/^\d+\.\d+\.\d+\.\d+/) || baseURL.match(/^https?:\/\/\d+\.\d+\.\d+\.\d+/));
|
||||
|
||||
// If using IP-based proxy, disable TLS certificate verification
|
||||
if (isProxyUrl) {
|
||||
console.log(`[EmbeddingService] Using OpenAI proxy (TLS verification disabled): ${baseURL}`);
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
||||
}
|
||||
|
||||
this.openai = new OpenAI({
|
||||
apiKey,
|
||||
baseURL: this.configService.get<string>('OPENAI_BASE_URL'), // 支持自定义endpoint
|
||||
baseURL: baseURL || undefined,
|
||||
});
|
||||
|
||||
console.log('[EmbeddingService] Initialized with OpenAI embedding model');
|
||||
if (baseURL && !isProxyUrl) {
|
||||
console.log(`[EmbeddingService] Using OpenAI API base URL: ${baseURL}`);
|
||||
} else if (!baseURL) {
|
||||
console.log('[EmbeddingService] Initialized with OpenAI embedding model');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue