Skip to content

Commit 5394d67

Browse files
committed
fix: Linting
1 parent 862d18f commit 5394d67

15 files changed

+23
-62
lines changed

src/Client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export class AI21 extends Core.APIClient {
4545
this._options = options;
4646
}
4747

48-
protected override authHeaders(opts: Models.FinalRequestOptions): Core.Headers {
48+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
49+
protected override authHeaders(_: Models.FinalRequestOptions): Core.Headers {
4950
return {
5051
Authorization: `Bearer ${this.apiKey}`,
5152
};

src/Core.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AI21Error } from './errors.js';
22
import { VERSION } from './version.js';
33

44
import fetch from 'node-fetch';
5-
import { HeadersInit } from 'node-fetch';
5+
import { HeadersInit, RequestInit } from 'node-fetch';
66
import {
77
RequestOptions,
88
FinalRequestOptions,
@@ -94,6 +94,7 @@ export abstract class APIClient {
9494
};
9595
}
9696

97+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
9798
protected authHeaders(opts: FinalRequestOptions): Headers {
9899
return {};
99100
}
@@ -123,7 +124,9 @@ export abstract class APIClient {
123124
...opts,
124125
};
125126

126-
return this.performRequest(options as FinalRequestOptions).then(handleAPIResponse);
127+
return this.performRequest(options as FinalRequestOptions).then(
128+
(response) => handleAPIResponse<Rsp>(response) as Rsp,
129+
);
127130
}
128131

129132
private async performRequest(options: FinalRequestOptions): Promise<APIResponseProps> {
@@ -138,7 +141,7 @@ export abstract class APIClient {
138141
const response = await fetch(url, {
139142
method: options.method,
140143
headers: headers as HeadersInit,
141-
signal: controller.signal as any, // Type cast to avoid AbortSignal compatibility issue
144+
signal: controller.signal as RequestInit['signal'],
142145
body: options.body ? JSON.stringify(options.body) : undefined,
143146
});
144147

src/ResponseHandler.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import { APIResponseProps } from './models';
22
import { AI21Error } from './errors';
33
import { Stream } from './Streaming';
4+
import { Response } from 'node-fetch';
45

5-
export async function handleAPIResponse({ response, options }: APIResponseProps): Promise<any> {
6+
type APIResponse<T = unknown> = {
7+
data: T;
8+
response: Response;
9+
};
10+
11+
export async function handleAPIResponse<T>({
12+
response,
13+
options,
14+
}: APIResponseProps): Promise<Stream<T> | APIResponse<T>> {
615
if (options.stream) {
716
if (!response.body) {
817
throw new AI21Error('Response body is null');
918
}
10-
return new Stream(response);
19+
return new Stream<T>(response);
1120
}
1221

1322
const contentType = response.headers.get('content-type');

src/Streaming/SSEDecoder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class DefaultSSEDecoder implements SSEDecoder {
2424
throw new Error('Response body is null');
2525
}
2626

27-
const webReadableStream = Readable.toWeb(response.body as any) as ReadableStream;
27+
const webReadableStream = Readable.toWeb(response.body as Readable);
2828
const reader = webReadableStream.getReader();
2929

3030
let buffer = '';

src/Streaming/Stream.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Response as NodeResponse } from 'node-fetch';
2-
import { Readable } from 'stream';
32
import { DefaultSSEDecoder } from './SSEDecoder';
43
import { SSEDecoder } from './SSEDecoder';
54
import { SSE_DONE_MSG } from './Consts';
@@ -8,7 +7,7 @@ import { StreamingDecodeError } from '../errors';
87
function getStreamMessage<T>(chunk: string): T {
98
try {
109
return JSON.parse(chunk);
11-
} catch (e) {
10+
} catch {
1211
throw new StreamingDecodeError(chunk);
1312
}
1413
}

src/models/chat/ChatCompletionsRequest.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface ChatCompletionCreateParamsBase {
1616
tools?: ToolDefinition[] | null;
1717
response_format?: ResponseFormat | null;
1818
documents?: DocumentSchema[] | null;
19-
[key: string]: any;
19+
[key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
2020
}
2121

2222
export interface ChatCompletionCreateParamsNonStreaming extends ChatCompletionCreateParamsBase {
@@ -30,11 +30,3 @@ export interface ChatCompletionCreateParamsStreaming extends ChatCompletionCreat
3030
export type ChatCompletionCreateParams =
3131
| ChatCompletionCreateParamsNonStreaming
3232
| ChatCompletionCreateParamsStreaming;
33-
34-
export declare namespace ChatCompletions {
35-
export {
36-
type ChatCompletionCreateParams,
37-
type ChatCompletionCreateParamsNonStreaming,
38-
type ChatCompletionCreateParamsStreaming,
39-
};
40-
}

src/models/chat/ChatCompletionsResponse.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,3 @@ export interface UsageInfo {
4242
completion_tokens: number;
4343
total_tokens: number;
4444
}
45-
46-
export declare namespace ChatCompletions {
47-
export {
48-
type ChatCompletionResponseChoice,
49-
type ChatCompletionResponse,
50-
type ChoiceDelta,
51-
type ChoicesChunk,
52-
type ChatCompletionChunk,
53-
type UsageInfo,
54-
};
55-
}

src/models/chat/ChatMessage.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,3 @@ export interface SystemMessage extends ChatMessage {
2525
}
2626

2727
export type ChatMessageParam = UserMessage | AssistantMessage | ToolMessage | SystemMessage | ChatMessage;
28-
29-
export declare namespace ChatCompletions {
30-
export { type ChatMessage, type AssistantMessage, type ToolMessage, type UserMessage, type SystemMessage };
31-
}

src/models/chat/ChatModel.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
export type ChatModel = 'jamba-1.5-mini' | 'jamba-1.5-large';
2-
3-
export declare namespace ChatModel {
4-
export { type ChatModel };
5-
}

src/models/chat/DocumentSchema.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,3 @@ export interface DocumentSchema {
33
id?: string;
44
metadata?: Record<string, string>;
55
}
6-
7-
export declare namespace ChatCompletions {
8-
export { type DocumentSchema };
9-
}

0 commit comments

Comments
 (0)