profile-adapter.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /** Compiled synthetic model for the shipped sdk-minimal profile; tools remain production plugins. */
  2. import type { Context } from '@deepseek-ai/cordis'
  3. import { LlmAdapter, ToolCallId } from '@deepseek-ai/dsh-llm'
  4. import type { GenerateOptions, LlmResolvedModelInfo, StreamChunk } from '@deepseek-ai/dsh-llm'
  5. import { response, WORKLOAD } from './workload.ts'
  6. class ProfileAdapter extends LlmAdapter {
  7. private requests = 0
  8. override resolveModel(provider: string, model: string): Promise<LlmResolvedModelInfo> {
  9. return Promise.resolve({ provider, id: model, name: model, contextWindow: 1_000_000 })
  10. }
  11. async * stream(_options: GenerateOptions): AsyncIterable<StreamChunk> {
  12. const serial = this.requests++
  13. if (serial % 2 === 1) {
  14. yield* response(200_000 + serial, 0).chunks
  15. return
  16. }
  17. for (let index = 0; index < WORKLOAD.toolsPerLiveTurn; index++) {
  18. const id = ToolCallId('profile-call-' + String(serial) + '-' + String(index))
  19. const args = JSON.stringify({ command: 'view', path: process.cwd() + '/synthetic.txt' })
  20. yield { type: 'block-start', index, blockType: 'tool-call' }
  21. yield { type: 'tool-call-delta', index, id, name: 'str_replace_editor', argumentsDelta: args }
  22. yield { type: 'block-end', index, block: { type: 'tool-call', id, name: 'str_replace_editor', arguments: args } }
  23. }
  24. yield { type: 'finish', reason: { kind: 'tool-calls' } }
  25. }
  26. }
  27. /** Loader plugin identity. */
  28. export const name = 'backend-profile-benchmark-model'
  29. /** The scripted provider requires the production LLM registry. */
  30. export const inject = ['llm']
  31. /**
  32. * Register the synthetic provider without changing any runtime services or tools.
  33. * @param ctx - profile-owned plugin context.
  34. */
  35. export function apply(ctx: Context): void {
  36. ctx.effect(() => ctx.llm.registerAdapter(['bench'], new ProfileAdapter()))
  37. }