({
row,
dataset,
logger,
}: {
row: ChatCompletionTraceRow
dataset?: string
logger: Logger
})
| 115 | } |
| 116 | |
| 117 | export async function insertChatCompletionTraceBigquery({ |
| 118 | row, |
| 119 | dataset, |
| 120 | logger, |
| 121 | }: { |
| 122 | row: ChatCompletionTraceRow |
| 123 | dataset?: string |
| 124 | logger: Logger |
| 125 | }) { |
| 126 | const resolvedDataset = dataset ?? DATASET |
| 127 | try { |
| 128 | await getClient() |
| 129 | .dataset(resolvedDataset) |
| 130 | .table(CHAT_COMPLETION_TRACES_TABLE) |
| 131 | .insert({ |
| 132 | ...row, |
| 133 | request: JSON.stringify(row.request), |
| 134 | messages: JSON.stringify(row.messages), |
| 135 | delta_message_hashes: JSON.stringify(row.delta_message_hashes), |
| 136 | tools: row.tools ? JSON.stringify(row.tools) : null, |
| 137 | }) |
| 138 | |
| 139 | logger.debug( |
| 140 | { |
| 141 | traceId: row.id, |
| 142 | userId: row.user_id, |
| 143 | clientId: row.client_id, |
| 144 | traceSessionId: row.trace_session_id, |
| 145 | traceLineageId: row.trace_lineage_id, |
| 146 | runId: row.run_id, |
| 147 | messageStartIndex: row.message_start_index, |
| 148 | messageDeltaCount: row.message_delta_count, |
| 149 | fullSnapshot: row.full_snapshot, |
| 150 | }, |
| 151 | 'Inserted chat completion trace into BigQuery', |
| 152 | ) |
| 153 | return true |
| 154 | } catch (error) { |
| 155 | logger.error( |
| 156 | { error: getErrorObject(error), traceId: row.id }, |
| 157 | 'Failed to insert chat completion trace into BigQuery', |
| 158 | ) |
| 159 | |
| 160 | return false |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | export async function insertMessageBigquery({ |
| 165 | row, |
no test coverage detected