MCPcopy Index your code
hub / github.com/coder/coder / Generate

Method Generate

coderd/x/chatd/chatdebug/model.go:202–238  ·  view source on GitHub ↗
(
	ctx context.Context,
	call fantasy.Call,
)

Source from the content-addressed store, hash-verified

200}
201
202func (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
240func (d *debugModel) Stream(
241 ctx context.Context,

Calls 9

RunFromContextFunction · 0.85
beginStepFunction · 0.85
normalizeCallFunction · 0.85
launchHeartbeatFunction · 0.85
stepStatusForErrorFunction · 0.85
normalizeErrorFunction · 0.85
normalizeResponseFunction · 0.85
finishMethod · 0.80
ErrorfMethod · 0.45