From c19dc125b06ba5b3ad985f2995f7fc0587629871 Mon Sep 17 00:00:00 2001 From: franktip Date: Mon, 1 Jul 2024 10:36:02 -0400 Subject: [PATCH] autoformat --- benchmark/run.ts | 10 ++++++++-- src/chatmodel.ts | 34 +++++++++++++++++++++++++--------- src/promise-utils.ts | 2 +- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/benchmark/run.ts b/benchmark/run.ts index d74003a..6db1917 100644 --- a/benchmark/run.ts +++ b/benchmark/run.ts @@ -180,7 +180,7 @@ if (require.main === module) { demandOption: false, description: "use custom rate-limiting for benchmarking (if specified, this supercedes the rateLimit option)", - } + }, }); const argv = await parser.argv; @@ -191,7 +191,13 @@ if (require.main === module) { "Warning: --strictResponses has no effect when not using --responses" ); } - model = new ChatModel(argv.model, argv.nrAttempts, argv.rateLimit, argv.benchmark, { max_tokens: argv.maxTokens } ); + model = new ChatModel( + argv.model, + argv.nrAttempts, + argv.rateLimit, + argv.benchmark, + { max_tokens: argv.maxTokens } + ); } else { model = MockCompletionModel.fromFile( argv.responses, diff --git a/src/chatmodel.ts b/src/chatmodel.ts index 6ac1b7f..b9733e4 100644 --- a/src/chatmodel.ts +++ b/src/chatmodel.ts @@ -1,7 +1,12 @@ import axios from "axios"; import { performance } from "perf_hooks"; import { ICompletionModel } from "./completionModel"; -import { retry, RateLimiter, BenchmarkRateLimiter, FixedRateLimiter } from "./promise-utils"; +import { + retry, + RateLimiter, + BenchmarkRateLimiter, + FixedRateLimiter, +} from "./promise-utils"; const defaultPostOptions = { max_tokens: 1000, // maximum number of tokens to return @@ -32,21 +37,26 @@ export class ChatModel implements ICompletionModel { private readonly nrAttempts: number, private readonly rateLimit: number, private readonly benchmark: boolean, - private readonly instanceOptions: PostOptions = {}, + private readonly instanceOptions: PostOptions = {} ) { this.apiEndpoint = getEnv("TESTPILOT_LLM_API_ENDPOINT"); this.authHeaders = getEnv("TESTPILOT_LLM_AUTH_HEADERS"); if (this.benchmark) { this.rateLimiter = new BenchmarkRateLimiter(); - console.log(`Using ${this.model} at ${this.apiEndpoint} with ${this.nrAttempts} attempts and benchmark rate limit.`); + console.log( + `Using ${this.model} at ${this.apiEndpoint} with ${this.nrAttempts} attempts and benchmark rate limit.` + ); } else if (this.rateLimit > 0) { this.rateLimiter = new FixedRateLimiter(this.rateLimit); - console.log(`Using ${this.model} at ${this.apiEndpoint} with ${this.nrAttempts} attempts and fixed rate of ${this.rateLimit} ms.`); + console.log( + `Using ${this.model} at ${this.apiEndpoint} with ${this.nrAttempts} attempts and fixed rate of ${this.rateLimit} ms.` + ); } else { this.rateLimiter = undefined; - console.log(`Using ${this.model} at ${this.apiEndpoint} with ${this.nrAttempts} attempts and no rate limit.`); + console.log( + `Using ${this.model} at ${this.apiEndpoint} with ${this.nrAttempts} attempts and no rate limit.` + ); } - } /** @@ -92,12 +102,18 @@ export class ChatModel implements ICompletionModel { let res; if (this.rateLimiter) { - res = await retry( () => - this.rateLimiter!.next(() => axios.post(this.apiEndpoint, postOptions, { headers })), + res = await retry( + () => + this.rateLimiter!.next(() => + axios.post(this.apiEndpoint, postOptions, { headers }) + ), this.nrAttempts ); } else { - res = await retry( () => axios.post(this.apiEndpoint, postOptions, { headers }), this.nrAttempts); + res = await retry( + () => axios.post(this.apiEndpoint, postOptions, { headers }), + this.nrAttempts + ); } performance.measure( diff --git a/src/promise-utils.ts b/src/promise-utils.ts index 762d7f4..b94a109 100644 --- a/src/promise-utils.ts +++ b/src/promise-utils.ts @@ -112,4 +112,4 @@ export class BenchmarkRateLimiter extends RateLimiter { } return super.next(p); } -} \ No newline at end of file +}