(body: Partial<ChatRequest>)
| 6 | |
| 7 | export class TextSDK extends Client { |
| 8 | private async *chatStream(body: Partial<ChatRequest>): AsyncGenerator<StreamEvent> { |
| 9 | const url = chatEndpoint(this.config.baseUrl); |
| 10 | |
| 11 | const res = await this.request({ |
| 12 | url, |
| 13 | method: 'POST', |
| 14 | body, |
| 15 | stream: true, |
| 16 | authStyle: 'x-api-key', |
| 17 | }); |
| 18 | |
| 19 | const contentType = res.headers.get('content-type') || ''; |
| 20 | |
| 21 | if (!contentType.includes('text/event-stream') && !contentType.includes('stream')) { |
| 22 | throw new SDKError( |
| 23 | `Expected SSE stream but got content-type "${contentType}". Server may be experiencing issues.`, |
| 24 | ExitCode.GENERAL, |
| 25 | ); |
| 26 | } |
| 27 | |
| 28 | yield* this.streamSSE<StreamEvent>(res); |
| 29 | } |
| 30 | |
| 31 | async chat(request: Partial<ChatRequest> & { stream: true }): Promise<AsyncGenerator<StreamEvent>>; |
| 32 | async chat(request: Partial<ChatRequest>): Promise<ChatResponse>; |
no test coverage detected