Skip to content

Commit c8fbdbf

Browse files
committedJul 26, 2023
Address lint errors. Set to error.
1 parent 18e2389 commit c8fbdbf

13 files changed

+63
-33
lines changed
 

‎.eslintrc.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,5 @@
1515
"ecmaVersion": "latest",
1616
"sourceType": "module"
1717
},
18-
"plugins": ["@typescript-eslint"],
19-
"rules": {
20-
"@typescript-eslint/no-unused-vars": "warn",
21-
"@typescript-eslint/no-explicit-any": "warn"
22-
}
18+
"plugins": ["@typescript-eslint"]
2319
}

‎src/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { TextGenerationModelWithTokenization } from "../../model-function/generate-text/TextGenerationModel.js";
1+
import {
2+
TextGenerationModelSettings,
3+
TextGenerationModelWithTokenization,
4+
} from "../../model-function/generate-text/TextGenerationModel.js";
25
import { generateText } from "../../model-function/generate-text/generateText.js";
36
import { FullTokenizer } from "../../model-function/tokenize-text/Tokenizer.js";
47
import { Run } from "../../run/Run.js";
@@ -11,7 +14,7 @@ import { summarizeRecursively } from "./summarizeRecursively.js";
1114
* while leaving enough space for the model to generate text.
1215
*/
1316
export async function summarizeRecursivelyWithTextGenerationAndTokenSplitting<
14-
PROMPT
17+
PROMPT,
1518
>(
1619
{
1720
text,
@@ -21,7 +24,11 @@ export async function summarizeRecursivelyWithTextGenerationAndTokenSplitting<
2124
join,
2225
}: {
2326
text: string;
24-
model: TextGenerationModelWithTokenization<PROMPT, any, any> &
27+
model: TextGenerationModelWithTokenization<
28+
PROMPT,
29+
unknown,
30+
TextGenerationModelSettings
31+
> &
2532
FullTokenizer;
2633
prompt: (input: { text: string }) => Promise<PROMPT>;
2734
reservedCompletionTokens: number;

‎src/composed-function/use-tool/useTool.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import { generateJsonOrText } from "../../model-function/generate-json/generateJ
1414
import { NoSuchToolError } from "./NoSuchToolError.js";
1515
import { Tool } from "./Tool.js";
1616

17+
// In this file, using 'any' is required to allow for flexibility in the inputs. The actual types are
18+
// retrieved through lookups such as TOOL["name"], such that any does not affect any client.
19+
/* eslint-disable @typescript-eslint/no-explicit-any */
20+
1721
/**
1822
* `useTool` uses `generateJson` to generate parameters for a tool and then executes the tool with the parameters.
1923
*
@@ -25,7 +29,7 @@ export async function useTool<
2529
PROMPT,
2630
RESPONSE,
2731
SETTINGS extends GenerateJsonModelSettings,
28-
TOOL extends Tool<any, any, any>
32+
TOOL extends Tool<any, any, any>,
2933
>(
3034
model: GenerateJsonModel<PROMPT, RESPONSE, SETTINGS>,
3135
tool: TOOL,
@@ -76,7 +80,7 @@ export async function useToolOrGenerateText<
7680
PROMPT,
7781
RESPONSE,
7882
SETTINGS extends GenerateJsonOrTextModelSettings,
79-
TOOLS extends Array<Tool<any, any, any>>
83+
TOOLS extends Array<Tool<any, any, any>>,
8084
>(
8185
model: GenerateJsonOrTextModel<PROMPT, RESPONSE, SETTINGS>,
8286
tools: TOOLS,

‎src/model-function/generate-json/generateJson.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ export function generateJson<
1212
STRUCTURE,
1313
PROMPT,
1414
RESPONSE,
15-
SETTINGS extends GenerateJsonModelSettings
15+
NAME extends string,
16+
SETTINGS extends GenerateJsonModelSettings,
1617
>(
1718
model: GenerateJsonModel<PROMPT, RESPONSE, SETTINGS>,
18-
schemaDefinition: SchemaDefinition<any, STRUCTURE>,
19+
schemaDefinition: SchemaDefinition<NAME, STRUCTURE>,
1920
prompt: (
20-
schemaDefinition: SchemaDefinition<any, STRUCTURE>
21+
schemaDefinition: SchemaDefinition<NAME, STRUCTURE>
2122
) => PROMPT & GenerateJsonPrompt<RESPONSE>,
2223
options?: FunctionOptions<SETTINGS>
2324
): Promise<STRUCTURE> {

‎src/model-function/generate-json/generateJsonOrText.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ import { NoSuchSchemaError } from "./NoSuchSchemaError.js";
99
import { SchemaDefinition } from "./SchemaDefinition.js";
1010
import { SchemaValidationError } from "./SchemaValidationError.js";
1111

12+
// In this file, using 'any' is required to allow for flexibility in the inputs. The actual types are
13+
// retrieved through lookups such as TOOL["name"], such that any does not affect any client.
14+
/* eslint-disable @typescript-eslint/no-explicit-any */
15+
1216
// [ { name: "n", schema: z.object<SCHEMA> } | { ... } ]
1317
type SchemaDefinitionArray<T extends SchemaDefinition<any, any>[]> = T;
1418

1519
// { n: { name: "n", schema: z.object<SCHEMA> }, ... }
1620
type ToSchemaDefinitionsMap<
17-
T extends SchemaDefinitionArray<SchemaDefinition<any, any>[]>
21+
T extends SchemaDefinitionArray<SchemaDefinition<any, any>[]>,
1822
> = {
1923
[K in T[number]["name"]]: Extract<T[number], SchemaDefinition<K, any>>;
2024
};
@@ -27,14 +31,14 @@ type ToSchemaUnion<T> = {
2731
}[keyof T];
2832

2933
type ToOutputValue<
30-
SCHEMAS extends SchemaDefinitionArray<SchemaDefinition<any, any>[]>
34+
SCHEMAS extends SchemaDefinitionArray<SchemaDefinition<any, any>[]>,
3135
> = ToSchemaUnion<ToSchemaDefinitionsMap<SCHEMAS>>;
3236

3337
export function generateJsonOrText<
3438
SCHEMAS extends SchemaDefinition<any, any>[],
3539
PROMPT,
3640
RESPONSE,
37-
SETTINGS extends GenerateJsonOrTextModelSettings
41+
SETTINGS extends GenerateJsonOrTextModelSettings,
3842
>(
3943
model: GenerateJsonOrTextModel<PROMPT, RESPONSE, SETTINGS>,
4044
schemaDefinitions: SCHEMAS,

‎src/model-function/stream-text/TextDeltaEventSource.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const textDeltaEventDataSchema = z.object({
1414
type TextDeltaEventData = z.infer<typeof textDeltaEventDataSchema>;
1515

1616
function enqueueData(
17-
controller: ReadableStreamDefaultController<any>,
17+
controller: ReadableStreamDefaultController<unknown>,
1818
data: TextDeltaEventData
1919
) {
2020
controller.enqueue(textEncoder.encode(`data: ${JSON.stringify(data)}\n\n`));

‎src/model-provider/openai/chat/OpenAIChatModel.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { OpenAIChatMessage } from "./OpenAIChatMessage.js";
2525
import {
2626
OpenAIChatAutoFunctionPrompt,
2727
OpenAIChatSingleFunctionPrompt,
28+
OpenAIFunctionDescription,
2829
} from "./OpenAIChatPrompt.js";
2930
import {
3031
OpenAIChatDelta,
@@ -172,7 +173,8 @@ export class OpenAIChatModel
172173
OpenAIChatSettings
173174
>,
174175
GenerateJsonOrTextModel<
175-
OpenAIChatSingleFunctionPrompt<any> | OpenAIChatAutoFunctionPrompt<any>,
176+
| OpenAIChatSingleFunctionPrompt<unknown>
177+
| OpenAIChatAutoFunctionPrompt<Array<OpenAIFunctionDescription<unknown>>>,
176178
OpenAIChatResponse,
177179
OpenAIChatSettings
178180
>
@@ -295,8 +297,8 @@ export class OpenAIChatModel
295297
*/
296298
generateJsonResponse(
297299
prompt:
298-
| OpenAIChatSingleFunctionPrompt<any>
299-
| OpenAIChatAutoFunctionPrompt<any>,
300+
| OpenAIChatSingleFunctionPrompt<unknown>
301+
| OpenAIChatAutoFunctionPrompt<Array<OpenAIFunctionDescription<unknown>>>,
300302
options?: FunctionOptions<OpenAIChatSettings> | undefined
301303
): PromiseLike<OpenAIChatResponse> {
302304
const settingsWithFunctionCall = Object.assign({}, options, {

‎src/model-provider/openai/chat/OpenAIChatPrompt.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import { SchemaDefinition } from "../../../model-function/generate-json/SchemaDe
88
import { OpenAIChatMessage } from "./OpenAIChatMessage.js";
99
import { OpenAIChatResponse } from "./OpenAIChatModel.js";
1010

11+
// In this file, using 'any' is required to allow for flexibility in the inputs. The actual types are
12+
// retrieved through lookups such as TOOL["name"], such that any does not affect any client.
13+
/* eslint-disable @typescript-eslint/no-explicit-any */
14+
1115
export type OpenAIFunctionDescription<T> = {
1216
name: string;
1317
description?: string;
@@ -65,7 +69,7 @@ export const OpenAIChatFunctionPrompt = {
6569
},
6670

6771
forOpenAIFunctionDescriptions<
68-
FUNCTIONS extends Array<OpenAIFunctionDescription<any>>
72+
FUNCTIONS extends Array<OpenAIFunctionDescription<any>>,
6973
>(options: { messages: OpenAIChatMessage[]; fns: FUNCTIONS }) {
7074
return new OpenAIChatAutoFunctionPrompt(options);
7175
},
@@ -152,7 +156,7 @@ export class OpenAIChatSingleFunctionPrompt<T>
152156
}
153157

154158
export class OpenAIChatAutoFunctionPrompt<
155-
FUNCTIONS extends Array<OpenAIFunctionDescription<any>>
159+
FUNCTIONS extends Array<OpenAIFunctionDescription<any>>,
156160
> implements GenerateJsonOrTextPrompt<OpenAIChatResponse>
157161
{
158162
readonly messages: OpenAIChatMessage[];

‎src/util/api/throttleMaxConcurrency.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ThrottleFunction } from "./ThrottleFunction.js";
33
class MaxConcurrencyThrottler {
44
private maxConcurrentCalls: number;
55
private activeCallCount: number;
6-
private callQueue: Array<() => Promise<any>>;
6+
private callQueue: Array<() => Promise<unknown>>;
77

88
constructor({ maxConcurrentCalls }: { maxConcurrentCalls: number }) {
99
this.maxConcurrentCalls = maxConcurrentCalls;

‎src/util/never.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
12
export function never(_: never) {}

‎src/vector-index/VectorIndexSimilarTextChunkRetriever.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { FunctionOptions } from "../model-function/FunctionOptions.js";
2-
import { TextEmbeddingModel } from "../model-function/embed-text/TextEmbeddingModel.js";
2+
import {
3+
TextEmbeddingModel,
4+
TextEmbeddingModelSettings,
5+
} from "../model-function/embed-text/TextEmbeddingModel.js";
36
import { embedText } from "../model-function/embed-text/embedText.js";
47
import { TextChunk } from "../text-chunk/TextChunk.js";
58
import {
@@ -15,12 +18,13 @@ export interface VectorIndexTextChunkRetrieverSettings {
1518

1619
export class VectorIndexSimilarTextChunkRetriever<
1720
CHUNK extends TextChunk,
18-
INDEX
21+
INDEX,
22+
SETTINGS extends TextEmbeddingModelSettings,
1923
> implements
2024
TextChunkRetriever<CHUNK, string, VectorIndexTextChunkRetrieverSettings>
2125
{
2226
private readonly vectorIndex: VectorIndex<CHUNK, INDEX>;
23-
private readonly embeddingModel: TextEmbeddingModel<any, any>;
27+
private readonly embeddingModel: TextEmbeddingModel<unknown, SETTINGS>;
2428
private readonly settings: VectorIndexTextChunkRetrieverSettings;
2529

2630
constructor({
@@ -30,7 +34,7 @@ export class VectorIndexSimilarTextChunkRetriever<
3034
similarityThreshold,
3135
}: {
3236
vectorIndex: VectorIndex<CHUNK, INDEX>;
33-
embeddingModel: TextEmbeddingModel<any, any>;
37+
embeddingModel: TextEmbeddingModel<unknown, SETTINGS>;
3438
} & VectorIndexTextChunkRetrieverSettings) {
3539
this.vectorIndex = vectorIndex;
3640
this.embeddingModel = embeddingModel;

‎src/vector-index/VectorIndexTextChunkStore.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { nanoid as createId } from "nanoid";
2-
import { TextEmbeddingModel } from "../model-function/embed-text/TextEmbeddingModel.js";
2+
import {
3+
TextEmbeddingModel,
4+
TextEmbeddingModelSettings,
5+
} from "../model-function/embed-text/TextEmbeddingModel.js";
36
import {
47
embedText,
58
embedTexts,
@@ -10,12 +13,16 @@ import { TextChunkRetrieverSettings } from "../text-chunk/retrieve-text-chunks/T
1013
import { VectorIndex } from "./VectorIndex.js";
1114
import { FunctionOptions } from "../model-function/FunctionOptions.js";
1215

13-
export class VectorIndexTextChunkStore<CHUNK extends TextChunk, INDEX> {
16+
export class VectorIndexTextChunkStore<
17+
CHUNK extends TextChunk,
18+
INDEX,
19+
MODEL extends TextEmbeddingModel<unknown, TextEmbeddingModelSettings>,
20+
> {
1421
private readonly _index: VectorIndex<CHUNK, INDEX>;
1522

1623
private readonly generateId: () => string;
1724

18-
private readonly embeddingModel: TextEmbeddingModel<any, any>;
25+
private readonly embeddingModel: MODEL;
1926
private readonly queryFunctionId?: string;
2027
private readonly upsertFunctionId?: string;
2128

@@ -28,7 +35,7 @@ export class VectorIndexTextChunkStore<CHUNK extends TextChunk, INDEX> {
2835
}: {
2936
index: VectorIndex<CHUNK, INDEX>;
3037
generateId?: () => string;
31-
embeddingModel: TextEmbeddingModel<any, any>;
38+
embeddingModel: MODEL;
3239
queryFunctionId?: string;
3340
upsertFunctionId?: string;
3441
}) {

‎src/vector-index/upsertTextChunks.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export async function upsertTextChunks<
1919
chunks,
2020
ids,
2121
}: {
22-
vectorIndex: VectorIndex<CHUNK, any>;
23-
embeddingModel: TextEmbeddingModel<any, SETTINGS>;
22+
vectorIndex: VectorIndex<CHUNK, unknown>;
23+
embeddingModel: TextEmbeddingModel<unknown, SETTINGS>;
2424
generateId?: () => string;
2525
chunks: CHUNK[];
2626
ids?: Array<string | undefined>;

1 commit comments

Comments
 (1)

vercel[bot] commented on Jul 26, 2023

@vercel[bot]
Please sign in to comment.