Skip to content

Commit

Permalink
update pre-commit prettier to 3.3.2 (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
j13huang authored Jul 17, 2024
1 parent c3d9575 commit a7c7135
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 66 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ repos:
)$
args: [-L rouge]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.3.2
hooks:
- id: prettier
exclude: ^(extension/|.*\.json$)
2 changes: 1 addition & 1 deletion evals/src/autoevals.eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const datasets = [

const runScorerT = wrapTraced(async function runScorer(
scorer: string,
input: any
input: any,
) {
switch (scorer) {
case "Factuality":
Expand Down
6 changes: 3 additions & 3 deletions evals/src/sync_datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ async function getCoqa(): Promise<z.infer<typeof coqaSchema>[]> {
await duckq(
conn,
`SELECT * FROM 'hf://datasets/stanfordnlp/coqa/data/validation-00000-of-00001.parquet'
LIMIT 20`
)
LIMIT 20`,
),
);
}

Expand Down Expand Up @@ -75,7 +75,7 @@ async function coqaContextRelevancy(): Promise<ContextRelevancyCase[]> {

const input = questions[0];
const contexts = answers.answer_start.map((answer_start, i) =>
story.substring(answer_start, answers.answer_end[i])
story.substring(answer_start, answers.answer_end[i]),
);

cases.push({
Expand Down
12 changes: 6 additions & 6 deletions js/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const JSONDiff: ScorerWithPartial<
score: await jsonDiff(output, expected, stringScorer, numberScorer),
};
},
"JSONDiff"
"JSONDiff",
);

/**
Expand All @@ -43,7 +43,7 @@ async function jsonDiff(
o1: any,
o2: any,
stringScorer: Scorer<string, {}>,
numberScorer: Scorer<number, {}>
numberScorer: Scorer<number, {}>,
): Promise<number | null> {
if (isObject(o1) && isObject(o2)) {
if (Object.keys(o1).length == 0 && Object.keys(o2).length == 0) {
Expand All @@ -54,13 +54,13 @@ async function jsonDiff(
Object.fromEntries(
Object.keys(o1)
.concat(Object.keys(o2))
.map((k) => [k, true])
)
.map((k) => [k, true]),
),
);

const baseScores = (
await Promise.all(
allKeys.map((k) => jsonDiff(o1[k], o2[k], stringScorer, numberScorer))
allKeys.map((k) => jsonDiff(o1[k], o2[k], stringScorer, numberScorer)),
)
).filter((s) => s !== null) as number[];
return baseScores.reduce((acc, s) => acc + s, 0) / baseScores.length;
Expand All @@ -73,7 +73,7 @@ async function jsonDiff(
await Promise.all(
Array.from({
length: Math.min(o1.length, o2.length),
}).map((_, i) => jsonDiff(o1[i], o2[i], stringScorer, numberScorer))
}).map((_, i) => jsonDiff(o1[i], o2[i], stringScorer, numberScorer)),
)
).filter((s) => s !== null) as number[];
return (
Expand Down
10 changes: 5 additions & 5 deletions js/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export const ListContains: ScorerWithPartial<
output: output_item,
expected: expected_item,
})
).score ?? 0
)
)
)
).score ?? 0,
),
),
),
);

if (similarities.length === 1 && similarities[0].length === 1) {
Expand All @@ -68,7 +68,7 @@ export const ListContains: ScorerWithPartial<
expected: expected[c],
score: similarities[r][c],
}
: null
: null,
)
.filter((pair) => pair !== null) as Array<{
output: string;
Expand Down
28 changes: 14 additions & 14 deletions js/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const COT_RESPONSE_SCHEMA = {

export function buildClassificationTools(
useCoT: boolean,
choiceStrings: string[]
choiceStrings: string[],
): ChatCompletionTool[] {
const params = useCoT ? COT_RESPONSE_SCHEMA : PLAIN_RESPONSE_SCHEMA;
const enumParams = {
Expand Down Expand Up @@ -83,7 +83,7 @@ export type OpenAIClassifierArgs<RenderArgs> = {
RenderArgs;

export async function OpenAIClassifier<RenderArgs, Output>(
args: ScorerArgs<Output, OpenAIClassifierArgs<RenderArgs>>
args: ScorerArgs<Output, OpenAIClassifierArgs<RenderArgs>>,
): Promise<Score> {
const {
name,
Expand Down Expand Up @@ -144,7 +144,7 @@ export async function OpenAIClassifier<RenderArgs, Output>(
openAiBaseUrl,
openAiDefaultHeaders,
openAiDangerouslyAllowBrowser,
}
},
);

if (resp.choices.length > 0) {
Expand All @@ -159,7 +159,7 @@ export async function OpenAIClassifier<RenderArgs, Output>(

function parseResponse(
resp: ChatCompletionMessage,
choiceScores: Record<string, number>
choiceScores: Record<string, number>,
): Omit<Score, "name"> {
let score = 0;
const metadata: Record<string, unknown> = {};
Expand Down Expand Up @@ -210,7 +210,7 @@ export function LLMClassifierFromTemplate<RenderArgs>({
}): Scorer<string, LLMClassifierArgs<RenderArgs>> {
const choiceStrings = Object.keys(choiceScores);
const ret = async (
runtimeArgs: ScorerArgs<string, LLMClassifierArgs<RenderArgs>>
runtimeArgs: ScorerArgs<string, LLMClassifierArgs<RenderArgs>>,
) => {
const useCoT = runtimeArgs.useCoT ?? useCoTArg ?? true;

Expand Down Expand Up @@ -259,7 +259,7 @@ export interface ModelGradedSpec {

export function LLMClassifierFromSpec<RenderArgs>(
name: string,
spec: ModelGradedSpec
spec: ModelGradedSpec,
): Scorer<any, LLMClassifierArgs<RenderArgs>> {
return LLMClassifierFromTemplate({
name,
Expand All @@ -273,15 +273,15 @@ export function LLMClassifierFromSpec<RenderArgs>(

export function LLMClassifierFromSpecFile<RenderArgs>(
name: string,
templateName: keyof typeof templates
templateName: keyof typeof templates,
): Scorer<any, LLMClassifierArgs<RenderArgs>> {
const doc = yaml.load(templates[templateName]) as ModelGradedSpec;
return LLMClassifierFromSpec(name, doc);
}

function buildLLMClassifier<RenderArgs>(
name: string,
templateName: keyof typeof templates
templateName: keyof typeof templates,
): ScorerWithPartial<string, LLMClassifierArgs<RenderArgs>> {
if (!(templateName in templates)) {
throw new Error(`Model template ${name} not found`);
Expand All @@ -290,9 +290,9 @@ function buildLLMClassifier<RenderArgs>(
return makePartial(
LLMClassifierFromSpecFile<RenderArgs>(
name,
templateName as keyof typeof templates
templateName as keyof typeof templates,
),
name
name,
);
}

Expand All @@ -302,7 +302,7 @@ function buildLLMClassifier<RenderArgs>(
*/
export const Battle = buildLLMClassifier<{ instructions: string }>(
"Battle",
"battle"
"battle",
);

/**
Expand All @@ -311,7 +311,7 @@ export const Battle = buildLLMClassifier<{ instructions: string }>(
*/
export const ClosedQA = buildLLMClassifier<{ input: string; criteria: any }>(
"ClosedQA",
"closed_q_a"
"closed_q_a",
);

/**
Expand All @@ -333,7 +333,7 @@ export const Factuality = buildLLMClassifier<{
*/
export const Possible = buildLLMClassifier<{ input: string }>(
"Possible",
"possible"
"possible",
);

/**
Expand All @@ -351,7 +351,7 @@ export const Sql = buildLLMClassifier<{ input: string }>("Sql", "sql");
*/
export const Summary = buildLLMClassifier<{ input: string }>(
"Summary",
"summary"
"summary",
);

/**
Expand Down
2 changes: 1 addition & 1 deletion js/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ export const NumericDiff: ScorerWithPartial<number, {}> = makePartial(
score,
};
},
"NumericDiff"
"NumericDiff",
);
2 changes: 1 addition & 1 deletion js/oai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ declare global {

export async function cachedChatCompletion(
params: CachedLLMParams,
options: { cache?: ChatCache } & OpenAIAuth
options: { cache?: ChatCache } & OpenAIAuth,
): Promise<ChatCompletion> {
let openai = buildOpenAIClient(options);
return await openai.chat.completions.create(params);
Expand Down
2 changes: 1 addition & 1 deletion js/partial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ScorerWithPartial<Output, Extra>

export function makePartial<Output, Extra>(
fn: Scorer<Output, Extra>,
name?: string
name?: string,
): ScorerWithPartial<Output, Extra> {
const ret: any = fn.bind({});
ret.partial = (args: Partial<ScorerArgs<Output, Extra>>) => {
Expand Down
Loading

0 comments on commit a7c7135

Please sign in to comment.