Skip to content

Commit c273834

Browse files
committed
refactor stringifyGenerationConfig
1 parent eb6cf10 commit c273834

File tree

4 files changed

+11
-25
lines changed

4 files changed

+11
-25
lines changed

packages/tasks/src/snippets/common.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,17 @@ export function stringifyMessages(
2323

2424
type PartialGenerationParameters = Partial<Pick<GenerationParameters, "temperature" | "max_tokens" | "top_p">>;
2525

26-
export interface StringifyGenerationConfigOptions {
27-
sep: string;
28-
start: string;
29-
end: string;
30-
attributeValueConnector: string;
31-
attributeKeyQuotes?: boolean;
32-
}
33-
3426
export function stringifyGenerationConfig(
3527
config: PartialGenerationParameters,
36-
opts: StringifyGenerationConfigOptions
28+
opts: {
29+
indent: string;
30+
attributeValueConnector: string;
31+
attributeKeyQuotes?: boolean;
32+
}
3733
): string {
3834
const quote = opts.attributeKeyQuotes ? `"` : "";
3935

40-
return (
41-
opts.start +
42-
Object.entries(config)
43-
.map(([key, val]) => `${quote}${key}${quote}${opts.attributeValueConnector}${val}`)
44-
.join(opts.sep) +
45-
opts.end
46-
);
36+
return Object.entries(config)
37+
.map(([key, val]) => `${quote}${key}${quote}${opts.attributeValueConnector}${val}`)
38+
.join(`,${opts.indent}`);
4739
}

packages/tasks/src/snippets/curl.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ export const snippetTextGeneration = (
4646
customContentEscaper: (str) => str.replace(/'/g, "'\\''"),
4747
})},
4848
${stringifyGenerationConfig(config, {
49-
sep: ",\n ",
50-
start: "",
51-
end: "",
49+
indent: "\n ",
5250
attributeKeyQuotes: true,
5351
attributeValueConnector: ": ",
5452
})},

packages/tasks/src/snippets/js.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ export const snippetTextGeneration = (
5050
...(opts?.top_p ? { top_p: opts.top_p } : undefined),
5151
};
5252
const configStr = stringifyGenerationConfig(config, {
53-
sep: ",\n\t",
54-
start: "",
55-
end: "",
53+
indent: "\n\t",
5654
attributeValueConnector: ": ",
5755
});
5856

packages/tasks/src/snippets/python.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ export const snippetConversational = (
2626
...(opts?.top_p ? { top_p: opts.top_p } : undefined),
2727
};
2828
const configStr = stringifyGenerationConfig(config, {
29-
sep: ",\n\t",
30-
start: "",
31-
end: "",
29+
indent: "\n\t",
3230
attributeValueConnector: "=",
3331
});
3432

0 commit comments

Comments
 (0)