Spaces:
Paused
Paused
Download node_modules/@huggingface/tasks/src/snippets/common.ts from ken-q/opencode-home: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/spaces/ken-q/opencode-home/resolve/main/node_modules/%40huggingface/tasks/src/snippets/common.ts
- Command line
-
hf download hf://spaces/ken-q/opencode-home/node_modules/@huggingface/tasks/src/snippets/common.ts
-
curl -L -o common.ts https://huggingface.co/spaces/ken-q/opencode-home/resolve/main/node_modules/%40huggingface/tasks/src/snippets/common.ts
1.16 kB
| import type { ChatCompletionInputMessage, GenerationParameters } from "../tasks/index.js"; | |
| export function stringifyMessages( | |
| messages: ChatCompletionInputMessage[], | |
| opts?: { | |
| indent?: string; | |
| attributeKeyQuotes?: boolean; | |
| customContentEscaper?: (str: string) => string; | |
| }, | |
| ): string { | |
| let messagesStr = JSON.stringify(messages, null, "\t"); | |
| if (opts?.indent) { | |
| messagesStr = messagesStr.replaceAll("\n", `\n${opts.indent}`); | |
| } | |
| if (!opts?.attributeKeyQuotes) { | |
| messagesStr = messagesStr.replace(/"([^"]+)":/g, "$1:"); | |
| } | |
| if (opts?.customContentEscaper) { | |
| messagesStr = opts.customContentEscaper(messagesStr); | |
| } | |
| return messagesStr; | |
| } | |
| type PartialGenerationParameters = Partial<Pick<GenerationParameters, "temperature" | "max_tokens" | "top_p">>; | |
| export function stringifyGenerationConfig( | |
| config: PartialGenerationParameters, | |
| opts: { | |
| indent: string; | |
| attributeValueConnector: string; | |
| attributeKeyQuotes?: boolean; | |
| }, | |
| ): string { | |
| const quote = opts.attributeKeyQuotes ? `"` : ""; | |
| return Object.entries(config) | |
| .map(([key, val]) => `${quote}${key}${quote}${opts.attributeValueConnector}${val},`) | |
| .join(`${opts.indent}`); | |
| } | |