♻️ refactor: enhance logging and provider handling for Anthropic integration

This commit is contained in:
Vaayne
2025-09-29 14:38:41 +08:00
parent 5b98ef5b3d
commit cc871b7a72
7 changed files with 59 additions and 168 deletions
+14 -4
View File
@@ -65,7 +65,13 @@ async function handleStreamingResponse(
res.write('data: [DONE]\n\n')
flushStream()
} catch (streamError: any) {
logger.error('Stream error', { error: streamError })
logger.error('Stream error', {
error: streamError,
provider: provider.id,
model: request.model,
apiHost: provider.apiHost,
anthropicApiHost: provider.anthropicApiHost
})
res.write(
`data: ${JSON.stringify({
type: 'error',
@@ -156,9 +162,13 @@ async function processMessageRequest(
})
}
logger.silly('Processing message request', {
request,
provider: provider.id
logger.info('Processing anthropic messages request', {
provider: provider.id,
apiHost: provider.apiHost,
anthropicApiHost: provider.anthropicApiHost,
model: request.model,
stream: request.stream,
thinking: request.thinking
})
// Handle streaming
+20 -2
View File
@@ -27,9 +27,27 @@ export class ModelsService {
for (const model of models) {
const provider = providers.find((p) => p.id === model.provider)
if (!provider || (provider.isAnthropicModel && !provider.isAnthropicModel(model))) {
continue
logger.debug(
`Processing model ${model.id} from provider ${model.provider}`,
{ isAnthropicModel: provider?.isAnthropicModel }
);
if (
!provider ||
(filter.providerType === "anthropic" &&
provider.isAnthropicModel &&
!provider.isAnthropicModel(model))
) {
continue;
}
// Special case: For "aihubmix", it should be covered by above condition, but just in case
if (
provider.id === "aihubmix" &&
filter.providerType === "anthropic" &&
!model.id.includes("claude")
) {
continue;
}
const openAIModel = transformModelToOpenAI(model, provider)
const fullModelId = openAIModel.id // This is already in format "provider:model_id"