(
_prompt: string,
signal: AbortSignal,
options: LLMFullCompletionOptions = {},
)
| 701 | } |
| 702 | |
| 703 | async *streamComplete( |
| 704 | _prompt: string, |
| 705 | signal: AbortSignal, |
| 706 | options: LLMFullCompletionOptions = {}, |
| 707 | ) { |
| 708 | this.lastRequestId = undefined; |
| 709 | const { completionOptions, logEnabled, raw } = |
| 710 | this._parseCompletionOptions(options); |
| 711 | const interaction = logEnabled |
| 712 | ? this.logger?.createInteractionLog() |
| 713 | : undefined; |
| 714 | let status: InteractionStatus = "in_progress"; |
| 715 | |
| 716 | let prompt = pruneRawPromptFromTop( |
| 717 | completionOptions.model, |
| 718 | this.contextLength, |
| 719 | _prompt, |
| 720 | completionOptions.maxTokens ?? DEFAULT_MAX_TOKENS, |
| 721 | ); |
| 722 | |
| 723 | if (!raw) { |
| 724 | prompt = this._templatePromptLikeMessages(prompt); |
| 725 | } |
| 726 | |
| 727 | if (logEnabled) { |
| 728 | interaction?.logItem({ |
| 729 | kind: "startComplete", |
| 730 | prompt, |
| 731 | options: completionOptions, |
| 732 | provider: this.providerName, |
| 733 | }); |
| 734 | if (this.llmRequestHook) { |
| 735 | this.llmRequestHook(completionOptions.model, prompt); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | let completion = ""; |
| 740 | try { |
| 741 | if (this.shouldUseOpenAIAdapter("streamComplete") && this.openaiAdapter) { |
| 742 | if (completionOptions.stream === false) { |
| 743 | // Stream false |
| 744 | const response = await this.openaiAdapter.completionNonStream( |
| 745 | { ...toCompleteBody(prompt, completionOptions), stream: false }, |
| 746 | signal, |
| 747 | ); |
| 748 | this.lastRequestId = response.id ?? this.lastRequestId; |
| 749 | completion = response.choices[0]?.text ?? ""; |
| 750 | yield completion; |
| 751 | } else { |
| 752 | // Stream true |
| 753 | for await (const chunk of this.openaiAdapter.completionStream( |
| 754 | { |
| 755 | ...toCompleteBody(prompt, completionOptions), |
| 756 | stream: true, |
| 757 | }, |
| 758 | signal, |
| 759 | )) { |
| 760 | if (!this.lastRequestId && typeof (chunk as any).id === "string") { |
nothing calls this directly
no test coverage detected