Spaces:
Sleeping
Sleeping
Commit
·
dd57645
1
Parent(s):
2b72918
process multiple requests in a file
Browse files
index.ts
CHANGED
|
@@ -110,21 +110,6 @@ tags:
|
|
| 110 |
}
|
| 111 |
}
|
| 112 |
|
| 113 |
-
function writeTraceToFile(trace: typeof requestTraces[0]): string {
|
| 114 |
-
try {
|
| 115 |
-
const timestamp = new Date(trace.timestamp_start).getTime();
|
| 116 |
-
const model = trace.model || 'unknown';
|
| 117 |
-
const filename = `${timestamp}_${model.replace(/\//g, '_')}.json`;
|
| 118 |
-
const filePath = join(LOGS_DIR, filename);
|
| 119 |
-
|
| 120 |
-
writeFileSync(filePath, JSON.stringify(trace, null, 2));
|
| 121 |
-
return filePath;
|
| 122 |
-
} catch (error) {
|
| 123 |
-
console.error('Error writing trace to file:', error);
|
| 124 |
-
return '';
|
| 125 |
-
}
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
async function uploadTraceFile(filePath: string, datasetName: string): Promise<boolean> {
|
| 129 |
try {
|
| 130 |
if (!HF_ACCESS_TOKEN) {
|
|
@@ -154,6 +139,20 @@ async function uploadTraceFile(filePath: string, datasetName: string): Promise<b
|
|
| 154 |
}
|
| 155 |
}
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
async function writeBatchedTraces() {
|
| 158 |
if (requestTraces.length === 0) {
|
| 159 |
return;
|
|
@@ -167,14 +166,9 @@ async function writeBatchedTraces() {
|
|
| 167 |
|
| 168 |
console.log(`Processing batch of ${batchSize} traces...`);
|
| 169 |
|
| 170 |
-
//
|
| 171 |
-
const
|
| 172 |
-
|
| 173 |
-
const filePath = writeTraceToFile(trace);
|
| 174 |
-
if (filePath) {
|
| 175 |
-
filePaths.push(filePath);
|
| 176 |
-
}
|
| 177 |
-
}
|
| 178 |
|
| 179 |
if (HF_ACCESS_TOKEN) {
|
| 180 |
const response = await whoAmI({ accessToken: HF_ACCESS_TOKEN });
|
|
|
|
| 110 |
}
|
| 111 |
}
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
async function uploadTraceFile(filePath: string, datasetName: string): Promise<boolean> {
|
| 114 |
try {
|
| 115 |
if (!HF_ACCESS_TOKEN) {
|
|
|
|
| 139 |
}
|
| 140 |
}
|
| 141 |
|
| 142 |
+
function writeBatchToFile(traces: typeof requestTraces): string {
|
| 143 |
+
try {
|
| 144 |
+
const timestamp = Date.now();
|
| 145 |
+
const filename = `batch_${timestamp}.json`;
|
| 146 |
+
const filePath = join(LOGS_DIR, filename);
|
| 147 |
+
|
| 148 |
+
writeFileSync(filePath, JSON.stringify(traces, null, 2));
|
| 149 |
+
return filePath;
|
| 150 |
+
} catch (error) {
|
| 151 |
+
console.error('Error writing batch to file:', error);
|
| 152 |
+
return '';
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
async function writeBatchedTraces() {
|
| 157 |
if (requestTraces.length === 0) {
|
| 158 |
return;
|
|
|
|
| 166 |
|
| 167 |
console.log(`Processing batch of ${batchSize} traces...`);
|
| 168 |
|
| 169 |
+
// Write all traces to a single batch file
|
| 170 |
+
const filePath = writeBatchToFile(tracesToWrite);
|
| 171 |
+
const filePaths = filePath ? [filePath] : [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
if (HF_ACCESS_TOKEN) {
|
| 174 |
const response = await whoAmI({ accessToken: HF_ACCESS_TOKEN });
|