-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovider-openai-chat.ts
More file actions
23 lines (21 loc) · 1.04 KB
/
provider-openai-chat.ts
File metadata and controls
23 lines (21 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { createEval2Otel, convertOpenAIChatToEval2Otel } from '../src';
import * as fs from 'fs';
import * as readline from 'readline';
// Usage: ts-node examples/provider-openai-chat.ts <openai_chat.jsonl>
// Each line: { startTime, endTime, request, response }
async function main() {
const file = process.argv[2];
if (!file) { console.error('Usage: ts-node examples/provider-openai-chat.ts <openai_chat.jsonl>'); process.exit(1); }
const inst = createEval2Otel({ serviceName: 'openai-chat-replay', useSdk: false } as any);
const rl = readline.createInterface({ input: fs.createReadStream(file), crlfDelay: Infinity });
for await (const line of rl) {
const trimmed = line.trim(); if (!trimmed) continue;
const obj = JSON.parse(trimmed);
const start = obj.startTime ?? Date.now();
const end = obj.endTime ?? (start + 1);
const evalRes = convertOpenAIChatToEval2Otel(obj.request, obj.response, start, end);
inst.processEvaluation(evalRes);
}
await inst.shutdown();
}
main().catch((e) => { console.error(e); process.exit(1); });