feat: add dynamic model fetching from Anthropic API #2
No files matched your search
+10
-4
@@ -24,7 +24,7 @@ export class AnthropicClient {
|
|||||||
enableCommentary = false,
|
enableCommentary = false,
|
||||||
commentaryStyle: CommentaryStyle = 'constructive',
|
commentaryStyle: CommentaryStyle = 'constructive',
|
||||||
customCommentaryPrompt?: string
|
customCommentaryPrompt?: string
|
||||||
): Promise<{ cleanedText: string; commentary?: string }> {
|
): Promise<{ cleanedText: string; commentary?: string; usage?: { input_tokens: number; output_tokens: number } }> {
|
||||||
if (!this.apiKey) {
|
if (!this.apiKey) {
|
||||||
throw new Error('API key is required');
|
throw new Error('API key is required');
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,13 @@ You MUST use exactly these markers. Do not deviate from this format.`;
|
|||||||
};
|
};
|
||||||
|
|
||||||
const response = await this.makeRequestWithRetry(request);
|
const response = await this.makeRequestWithRetry(request);
|
||||||
return this.parseStructuredResponse(response, enableCommentary);
|
const responseText = this.extractTextFromResponse(response);
|
||||||
|
const parsed = this.parseStructuredResponse(responseText, enableCommentary);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...parsed,
|
||||||
|
usage: response.usage
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async testConnection(model: string): Promise<{
|
async testConnection(model: string): Promise<{
|
||||||
@@ -130,13 +136,13 @@ You MUST use exactly these markers. Do not deviate from this format.`;
|
|||||||
|
|
||||||
// MARK: - Private Methods
|
// MARK: - Private Methods
|
||||||
|
|
||||||
private async makeRequestWithRetry(request: AnthropicRequest): Promise<string> {
|
private async makeRequestWithRetry(request: AnthropicRequest): Promise<AnthropicResponse> {
|
||||||
let lastError: Error = new Error('No attempts made');
|
let lastError: Error = new Error('No attempts made');
|
||||||
|
|
||||||
for (let attempt = 1; attempt <= this.MAX_RETRIES; attempt++) {
|
for (let attempt = 1; attempt <= this.MAX_RETRIES; attempt++) {
|
||||||
try {
|
try {
|
||||||
const response = await this.makeRequest(request);
|
const response = await this.makeRequest(request);
|
||||||
return this.extractTextFromResponse(response);
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
lastError = error instanceof Error ? error : new Error('Unknown error');
|
lastError = error instanceof Error ? error : new Error('Unknown error');
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export class CleanupService {
|
|||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { cleanedText, commentary } = await this.client.cleanupText(
|
const { cleanedText, commentary, usage } = await this.client.cleanupText(
|
||||||
text,
|
text,
|
||||||
settings.model,
|
settings.model,
|
||||||
settings.cleanupPrompt,
|
settings.cleanupPrompt,
|
||||||
@@ -53,8 +53,8 @@ export class CleanupService {
|
|||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
model: settings.model,
|
model: settings.model,
|
||||||
tokensUsed: {
|
tokensUsed: {
|
||||||
input: 0, // We don't have access to this from the response
|
input: usage?.input_tokens ?? 0,
|
||||||
output: 0 // We don't have access to this from the response
|
output: usage?.output_tokens ?? 0
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user