Anthropic 어댑터: 토큰 사용량(이미지·캐시 포함)을 게이지/비용 기록에 반영, 도구 결과의 이미지를 Claude에 전달, 모델 목록에 5.5 추가

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-17 22:03:41 +09:00
1 parent 1a2e27ae5a
commit aab520648b
1 file changed
+18 -3
+18 -3
View File
@@ -4,6 +4,7 @@
* Converts between the server's OpenAI-style ChatMessage format and Anthropic's format.
*/
import { logUsage } from './usage-log';
import type {
LLMProvider, ChatMessage, ContentPart, ChatOptions, ChatResult,
GenerateOptions, GenerateResult, ModelInfo,
@@ -67,7 +68,17 @@ export class AnthropicAdapter implements LLMProvider {
}
const data = await this.post('/v1/messages', body);
return fromAnthropicResponse(data);
const result = fromAnthropicResponse(data);
// 사용량: 지금까지 이 어댑터는 토큰 수를 버렸다 — 컨텍스트 게이지·비용 기록(token-usage.jsonl)에 Claude 호출이 전혀 안 잡혔다
// (2026-10-17). 입력 토큰에는 이미지·캐시된 토큰도 포함해야 실제 부담이 보인다.
const u = data?.usage;
if (u) {
const promptTokens = (Number(u.input_tokens) || 0) + (Number(u.cache_creation_input_tokens) || 0) + (Number(u.cache_read_input_tokens) || 0);
const completionTokens = Number(u.output_tokens) || 0;
logUsage(model, promptTokens, completionTokens);
return { ...result, usage: { promptTokens, completionTokens, ctxWindow: Number(options?.num_ctx) || 0 } } as ChatResult;
}
return result;
}
async generate(prompt: string, model: string, options?: GenerateOptions): Promise<GenerateResult> {
@@ -87,7 +98,9 @@ export class AnthropicAdapter implements LLMProvider {
async listModels(): Promise<ModelInfo[]> {
// Anthropic has no public list-models endpoint; return known models
return [
{ name: 'claude-opus-4-7' },
{ name: 'claude-haiku-5-5' },
{ name: 'claude-sonnet-5-5' },
{ name: 'claude-opus-5-5' },
{ name: 'claude-sonnet-4-6' },
{ name: 'claude-haiku-4-5-20251001' },
];
@@ -121,7 +134,9 @@ function toAnthropicMessages(messages: ChatMessage[]): any[] {
const block = {
type: 'tool_result',
tool_use_id: msg.tool_call_id ?? '',
content: contentToString(msg.content),
// 도구 결과의 이미지(python_eval 차트·CCTV 캡처 등)도 그대로 넘긴다 — contentToString은 이미지 파트를 버려서
// Claude가 도구가 만든 그림을 한 번도 보지 못했다. Anthropic은 tool_result 안에 text+image 블록을 허용한다.
content: toAnthropicContent(msg.content),
};
const last = out[out.length - 1];
if (last?.role === 'user' && Array.isArray(last.content)) {