Skip to content

Commit 194e307

Browse files
committed
pass in logger to relace api
1 parent fa7a47a commit 194e307

File tree

3 files changed

+69
-45
lines changed

3 files changed

+69
-45
lines changed

backend/src/admin/relabelRuns.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import { rerank } from '../llm-apis/relace-api'
1616
import { promptAiSdk } from '../llm-apis/vercel-ai-sdk/ai-sdk'
1717
import { messagesWithSystem } from '../util/messages'
1818

19-
import type { Logger } from '@codebuff/types/logger'
20-
2119
import type { System } from '../llm-apis/claude'
2220
import type {
2321
GetExpandedFileContextForTrainingBlobTrace,
@@ -27,6 +25,7 @@ import type {
2725
Relabel,
2826
} from '@codebuff/bigquery'
2927
import type { Message } from '@codebuff/common/types/messages/codebuff-message'
28+
import type { Logger } from '@codebuff/types/logger'
3029
import type { Request, Response } from 'express'
3130

3231
// --- GET Handler Logic ---
@@ -151,7 +150,11 @@ export async function relabelForUserHandler(params: {
151150

152151
const allResults = []
153152

154-
const relaceResults = relabelUsingFullFilesForUser({ userId, limit, logger })
153+
const relaceResults = relabelUsingFullFilesForUser({
154+
userId,
155+
limit,
156+
logger,
157+
})
155158

156159
// Process each model
157160
for (const model of modelsToRelabel) {
@@ -303,7 +306,12 @@ async function relabelUsingFullFilesForUser(params: {
303306
)
304307
) {
305308
relabelPromises.push(
306-
relabelWithClaudeWithFullFileContext({ trace, fileBlobs, model, logger }),
309+
relabelWithClaudeWithFullFileContext({
310+
trace,
311+
fileBlobs,
312+
model,
313+
logger,
314+
}),
307315
)
308316
didRelabel = true
309317
}
@@ -348,12 +356,15 @@ async function relabelWithRelace(params: {
348356
}),
349357
)
350358

351-
const relaced = await rerank(filesWithPath, query, {
359+
const relaced = await rerank({
360+
files: filesWithPath,
361+
prompt: query,
352362
clientSessionId: trace.payload.client_session_id,
353363
fingerprintId: trace.payload.fingerprint_id,
354364
userInputId: trace.payload.user_input_id,
355365
userId: 'test-user-id', // Make sure we don't bill em for it!!
356366
messageId: trace.id,
367+
logger,
357368
})
358369

359370
const relabel = {
@@ -415,7 +426,10 @@ export async function relabelWithClaudeWithFullFileContext(params: {
415426
}
416427

417428
const output = await promptAiSdk({
418-
messages: messagesWithSystem({ messages: trace.payload.messages as Message[], system }),
429+
messages: messagesWithSystem({
430+
messages: trace.payload.messages as Message[],
431+
system,
432+
}),
419433
model: model as any, // Model type is string here for flexibility
420434
clientSessionId: 'relabel-trace-api',
421435
fingerprintId: 'relabel-trace-api',

backend/src/fast-rewrite.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,18 @@ export async function fastRewrite(params: {
4040
} = params
4141
const relaceStartTime = Date.now()
4242
const messageId = generateCompactId('cb-')
43-
let response = await promptRelaceAI(
44-
initialContent,
43+
let response = await promptRelaceAI({
44+
initialCode: initialContent,
4545
editSnippet,
4646
instructions,
47-
{
48-
clientSessionId,
49-
fingerprintId,
50-
userInputId,
51-
userId,
52-
userMessage,
53-
messageId,
54-
},
55-
)
47+
clientSessionId,
48+
fingerprintId,
49+
userInputId,
50+
userId,
51+
userMessage,
52+
messageId,
53+
logger,
54+
})
5655
const relaceDuration = Date.now() - relaceStartTime
5756

5857
// Check if response still contains lazy edits

backend/src/llm-apis/relace-api.ts

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,40 @@ import {
66
import { env } from '@codebuff/internal'
77

88
import { saveMessage } from '../llm-apis/message-cost-tracker'
9-
import { logger } from '../util/logger'
109
import { countTokens } from '../util/token-counter'
1110
import { promptAiSdk } from './vercel-ai-sdk/ai-sdk'
1211

12+
import type { Logger } from '@codebuff/types/logger'
13+
1314
const timeoutPromise = (ms: number) =>
1415
new Promise((_, reject) =>
1516
setTimeout(() => reject(new Error('Relace API request timed out')), ms),
1617
)
1718

18-
export async function promptRelaceAI(
19-
initialCode: string,
20-
editSnippet: string,
21-
instructions: string | undefined,
22-
options: {
23-
clientSessionId: string
24-
fingerprintId: string
25-
userInputId: string
26-
userId: string | undefined
27-
messageId: string
28-
userMessage?: string
29-
},
30-
) {
19+
export async function promptRelaceAI(params: {
20+
initialCode: string
21+
editSnippet: string
22+
instructions: string | undefined
23+
clientSessionId: string
24+
fingerprintId: string
25+
userInputId: string
26+
userId: string | undefined
27+
messageId: string
28+
userMessage?: string
29+
logger: Logger
30+
}) {
3131
const {
32+
initialCode,
33+
editSnippet,
34+
instructions,
3235
clientSessionId,
3336
fingerprintId,
3437
userInputId,
3538
userId,
3639
userMessage,
3740
messageId,
38-
} = options
41+
logger,
42+
} = params
3943
const startTime = Date.now()
4044

4145
try {
@@ -151,19 +155,26 @@ export type FileWithPath = {
151155
content: string
152156
}
153157

154-
export async function rerank(
155-
files: FileWithPath[],
156-
prompt: string,
157-
options: {
158-
clientSessionId: string
159-
fingerprintId: string
160-
userInputId: string
161-
userId: string | undefined
162-
messageId: string
163-
},
164-
) {
165-
const { clientSessionId, fingerprintId, userInputId, userId, messageId } =
166-
options
158+
export async function rerank(params: {
159+
files: FileWithPath[]
160+
prompt: string
161+
clientSessionId: string
162+
fingerprintId: string
163+
userInputId: string
164+
userId: string | undefined
165+
messageId: string
166+
logger: Logger
167+
}) {
168+
const {
169+
files,
170+
prompt,
171+
clientSessionId,
172+
fingerprintId,
173+
userInputId,
174+
userId,
175+
messageId,
176+
logger,
177+
} = params
167178
const startTime = Date.now()
168179

169180
if (!prompt || !files.length) {

0 commit comments

Comments
 (0)