Spaces:
Runtime error
Runtime error
Download src/lib/cli-helper/config-generator/codex.ts from YOGESHJIO5770/ai_api: direct link, hf CLI and curl.
- Browser
- Download file 808 Bytes
-
https://huggingface.co/spaces/YOGESHJIO5770/ai_api/resolve/main/src/lib/cli-helper/config-generator/codex.ts
- Command line
-
hf download hf://spaces/YOGESHJIO5770/ai_api/src/lib/cli-helper/config-generator/codex.ts
-
curl -L -o codex.ts https://huggingface.co/spaces/YOGESHJIO5770/ai_api/resolve/main/src/lib/cli-helper/config-generator/codex.ts
808 Bytes
| import path from "node:path"; | |
| import os from "node:os"; | |
| let yaml: typeof import("js-yaml") | null = null; | |
| async function loadYaml() { | |
| if (!yaml) { | |
| yaml = await import("js-yaml"); | |
| } | |
| return yaml; | |
| } | |
| const CONFIG_PATH = path.join(os.homedir(), ".codex", "config.yaml"); | |
| export async function generateCodexConfig(options: { | |
| baseUrl: string; | |
| apiKey: string; | |
| model?: string; | |
| }): Promise<string> { | |
| const y = await loadYaml(); | |
| let base = options.baseUrl; | |
| let end = base.length; | |
| while (end > 0 && base[end - 1] === "/") end--; | |
| base = end < base.length ? base.slice(0, end) : base; | |
| if (base.endsWith("/v1")) base = base.slice(0, -3); | |
| const config = { | |
| openai: { | |
| api_key: options.apiKey, | |
| base_url: `${base}/v1`, | |
| }, | |
| }; | |
| return y.dump(config, { lineWidth: -1 }); | |
| } | |