( ctx context.Context, debugSvc *chatdebug.Service, chat database.Chat, modelConfig database.ChatModelConfig, keys chatprovider.ProviderAPIKeys, modelOpts modelBuildOptions, messages []database.ChatMessage, fallbackModel fantasy.LanguageModel, )
| 3329 | } |
| 3330 | |
| 3331 | func (p *Server) prepareManualTitleDebugRun( |
| 3332 | ctx context.Context, |
| 3333 | debugSvc *chatdebug.Service, |
| 3334 | chat database.Chat, |
| 3335 | modelConfig database.ChatModelConfig, |
| 3336 | keys chatprovider.ProviderAPIKeys, |
| 3337 | modelOpts modelBuildOptions, |
| 3338 | messages []database.ChatMessage, |
| 3339 | fallbackModel fantasy.LanguageModel, |
| 3340 | ) (context.Context, fantasy.LanguageModel, func(error)) { |
| 3341 | titleCtx := ctx |
| 3342 | titleModel := fallbackModel |
| 3343 | finishDebugRun := func(error) {} |
| 3344 | |
| 3345 | route, routeErr := p.resolveModelRouteForConfig(ctx, chat.OwnerID, modelConfig, keys) |
| 3346 | debugOpts := modelOpts |
| 3347 | debugOpts.RecordHTTP = true |
| 3348 | var debugModelErr error |
| 3349 | var debugModel fantasy.LanguageModel |
| 3350 | if routeErr != nil { |
| 3351 | debugModelErr = routeErr |
| 3352 | } else { |
| 3353 | debugModel, debugModelErr = p.newModel(ctx, modelClientRequest{ |
| 3354 | Chat: chat, |
| 3355 | ModelName: modelConfig.Model, |
| 3356 | UserAgent: chatprovider.UserAgent(), |
| 3357 | ExtraHeaders: chatprovider.CoderHeaders(chat), |
| 3358 | }, route, debugOpts) |
| 3359 | } |
| 3360 | switch { |
| 3361 | case debugModelErr != nil: |
| 3362 | p.logger.Warn(ctx, "failed to create debug-aware manual title model", |
| 3363 | slog.F("chat_id", chat.ID), |
| 3364 | slog.F("provider", modelConfig.Provider), |
| 3365 | slog.F("model", modelConfig.Model), |
| 3366 | slog.Error(debugModelErr), |
| 3367 | ) |
| 3368 | case debugModel == nil: |
| 3369 | p.logger.Warn(ctx, "manual title debug model creation returned nil", |
| 3370 | slog.F("chat_id", chat.ID), |
| 3371 | slog.F("provider", modelConfig.Provider), |
| 3372 | slog.F("model", modelConfig.Model), |
| 3373 | ) |
| 3374 | default: |
| 3375 | titleModel = chatdebug.WrapModel(debugModel, debugSvc, chatdebug.RecorderOptions{ |
| 3376 | ChatID: chat.ID, |
| 3377 | OwnerID: chat.OwnerID, |
| 3378 | Provider: modelConfig.Provider, |
| 3379 | Model: modelConfig.Model, |
| 3380 | }) |
| 3381 | } |
| 3382 | |
| 3383 | var historyTipMessageID int64 |
| 3384 | if len(messages) > 0 { |
| 3385 | historyTipMessageID = messages[len(messages)-1].ID |
| 3386 | } |
| 3387 | |
| 3388 | // Derive a first_message label from the first user message. |
no test coverage detected