| 200 | } |
| 201 | |
| 202 | func (d *debugModel) Generate( |
| 203 | ctx context.Context, |
| 204 | call fantasy.Call, |
| 205 | ) (*fantasy.Response, error) { |
| 206 | if d.svc == nil { |
| 207 | return d.inner.Generate(ctx, call) |
| 208 | } |
| 209 | if _, ok := RunFromContext(ctx); !ok { |
| 210 | return d.inner.Generate(ctx, call) |
| 211 | } |
| 212 | |
| 213 | handle, enrichedCtx := beginStep(ctx, d.svc, d.opts, OperationGenerate, |
| 214 | normalizeCall(call)) |
| 215 | if handle == nil { |
| 216 | return d.inner.Generate(ctx, call) |
| 217 | } |
| 218 | |
| 219 | // Keep the step alive during the blocking provider call so the |
| 220 | // stale finalizer does not mark it as interrupted. |
| 221 | heartbeatDone := make(chan struct{}) |
| 222 | launchHeartbeat(ctx, handle.svc, handle.stepCtx.StepID, handle.stepCtx.RunID, handle.stepCtx.ChatID, heartbeatDone) |
| 223 | |
| 224 | resp, err := d.inner.Generate(enrichedCtx, call) |
| 225 | close(heartbeatDone) |
| 226 | if err != nil { |
| 227 | handle.finish(ctx, stepStatusForError(err), nil, nil, normalizeError(ctx, err), nil) |
| 228 | return nil, err |
| 229 | } |
| 230 | if resp == nil { |
| 231 | err = xerrors.Errorf("Generate: %w", ErrNilModelResult) |
| 232 | handle.finish(ctx, StatusError, nil, nil, normalizeError(ctx, err), nil) |
| 233 | return nil, err |
| 234 | } |
| 235 | |
| 236 | handle.finish(ctx, StatusCompleted, normalizeResponse(resp), &resp.Usage, nil, nil) |
| 237 | return resp, nil |
| 238 | } |
| 239 | |
| 240 | func (d *debugModel) Stream( |
| 241 | ctx context.Context, |