|
| 1 | +import { testClickhouseDb } from "../src/lib/db/test/TestClickhouseWrapper"; |
| 2 | +import { RequestResponseRMT } from "../src/lib/db/ClickhouseWrapper"; |
| 3 | +import { randomUUID } from "node:crypto"; |
| 4 | + |
| 5 | +function parseArg(name: string, fallback?: string): string | undefined { |
| 6 | + const prefix = `--${name}=`; |
| 7 | + const arg = process.argv.find((a) => a.startsWith(prefix)); |
| 8 | + if (!arg) return fallback; |
| 9 | + return arg.slice(prefix.length); |
| 10 | +} |
| 11 | + |
| 12 | +async function main() { |
| 13 | + const count = Number(parseArg("count", "500")); |
| 14 | + const orgId = parseArg("orgId", "83635a30-5ba6-41a8-8cc6-fb7df941b24a")!; |
| 15 | + |
| 16 | + console.log(`[seed-clickhouse] Seeding request_response_rmt with ${count} rows for orgId=${orgId}`); |
| 17 | + |
| 18 | + // Ensure tables exist |
| 19 | + await testClickhouseDb.createTables(); |
| 20 | + |
| 21 | + const now = Date.now(); |
| 22 | + const rows: RequestResponseRMT[] = Array.from({ length: count }).map((_, i) => { |
| 23 | + const ts = new Date(now - i * 1000) |
| 24 | + .toISOString() |
| 25 | + .replace("T", " ") |
| 26 | + .replace("Z", "") |
| 27 | + .replace(/\.\d+$/, ""); |
| 28 | + return { |
| 29 | + response_id: randomUUID(), |
| 30 | + response_created_at: ts, |
| 31 | + latency: 100 + (i % 50), |
| 32 | + status: 200, |
| 33 | + completion_tokens: 20 + (i % 10), |
| 34 | + prompt_tokens: 10 + (i % 5), |
| 35 | + prompt_cache_write_tokens: 0, |
| 36 | + prompt_cache_read_tokens: 0, |
| 37 | + prompt_audio_tokens: 0, |
| 38 | + completion_audio_tokens: 0, |
| 39 | + model: i % 2 === 0 ? "gpt-4o-mini" : "stardust", |
| 40 | + request_id: randomUUID(), |
| 41 | + request_created_at: ts, |
| 42 | + user_id: `user-${i % 3}`, |
| 43 | + organization_id: orgId, |
| 44 | + proxy_key_id: null as any, |
| 45 | + threat: false, |
| 46 | + time_to_first_token: 50, |
| 47 | + provider: "OPENAI", |
| 48 | + country_code: "US", |
| 49 | + target_url: "https://api.openai.com/v1/chat/completions", |
| 50 | + properties: {}, |
| 51 | + scores: {}, |
| 52 | + request_body: "test", |
| 53 | + response_body: "test", |
| 54 | + assets: [`asset-${i}`], |
| 55 | + // Let ClickHouse defaults apply for updated_at, cache_reference_id, cache_enabled, cost, etc. |
| 56 | + } as RequestResponseRMT; |
| 57 | + }); |
| 58 | + |
| 59 | + const result = await testClickhouseDb.dbInsertClickhouse("request_response_rmt", rows); |
| 60 | + if (result.error) { |
| 61 | + console.error("[seed-clickhouse] Insert failed:", result.error); |
| 62 | + process.exit(1); |
| 63 | + } |
| 64 | + console.log("[seed-clickhouse] Done. Query ID:", result.data); |
| 65 | +} |
| 66 | + |
| 67 | +main().catch((err) => { |
| 68 | + console.error("[seed-clickhouse] Unexpected error:", err); |
| 69 | + process.exit(1); |
| 70 | +}); |
| 71 | + |
| 72 | + |
0 commit comments