|
3 | 3 | import * as Core from 'groq-sdk/core';
|
4 | 4 | import { APIResource } from 'groq-sdk/resource';
|
5 | 5 | import * as CompletionsAPI from 'groq-sdk/resources/chat/completions';
|
| 6 | +import { Stream } from 'groq-sdk/lib/streaming'; |
| 7 | +import { ChatCompletionChunk } from 'groq-sdk/lib/chat_completions_ext'; |
6 | 8 |
|
7 | 9 | export class Completions extends APIResource {
|
8 | 10 | /**
|
9 | 11 | * Creates a completion for a chat prompt
|
10 | 12 | */
|
11 |
| - create(body: CompletionCreateParams, options?: Core.RequestOptions): Core.APIPromise<ChatCompletion> { |
12 |
| - return this._client.post('/openai/v1/chat/completions', { body, ...options }); |
| 13 | + create( |
| 14 | + body: ChatCompletionCreateParamsNonStreaming, |
| 15 | + options?: Core.RequestOptions, |
| 16 | + ): Core.APIPromise<ChatCompletion>; |
| 17 | + create( |
| 18 | + body: ChatCompletionCreateParamsStreaming, |
| 19 | + options?: Core.RequestOptions, |
| 20 | + ): Core.APIPromise<Stream<ChatCompletionChunk>>; |
| 21 | + create( |
| 22 | + body: ChatCompletionCreateParamsBase, |
| 23 | + options?: Core.RequestOptions, |
| 24 | + ): Core.APIPromise<Stream<ChatCompletionChunk> | ChatCompletion>; |
| 25 | + create( |
| 26 | + body: ChatCompletionCreateParams, |
| 27 | + options?: Core.RequestOptions, |
| 28 | + ): Core.APIPromise<ChatCompletion> | Core.APIPromise<Stream<ChatCompletionChunk>> { |
| 29 | + return this._client.post('/openai/v1/chat/completions', { body, ...options, stream: body.stream ?? false }) as |
| 30 | + | Core.APIPromise<ChatCompletion> |
| 31 | + | Core.APIPromise<Stream<ChatCompletionChunk>>; |
13 | 32 | }
|
14 | 33 | }
|
15 | 34 |
|
@@ -109,7 +128,7 @@ export namespace ChatCompletion {
|
109 | 128 | }
|
110 | 129 | }
|
111 | 130 |
|
112 |
| -export interface CompletionCreateParams { |
| 131 | +export interface ChatCompletionCreateParamsBase { |
113 | 132 | messages: Array<CompletionCreateParams.Message>;
|
114 | 133 |
|
115 | 134 | model: string;
|
@@ -233,3 +252,15 @@ export namespace Completions {
|
233 | 252 | export import ChatCompletion = CompletionsAPI.ChatCompletion;
|
234 | 253 | export import CompletionCreateParams = CompletionsAPI.CompletionCreateParams;
|
235 | 254 | }
|
| 255 | + |
| 256 | +export interface ChatCompletionCreateParamsNonStreaming extends ChatCompletionCreateParamsBase { |
| 257 | + stream?: false; |
| 258 | +} |
| 259 | + |
| 260 | +export interface ChatCompletionCreateParamsStreaming extends ChatCompletionCreateParamsBase { |
| 261 | + stream: true; |
| 262 | +} |
| 263 | + |
| 264 | +export type ChatCompletionCreateParams = |
| 265 | + | ChatCompletionCreateParamsNonStreaming |
| 266 | + | ChatCompletionCreateParamsStreaming; |
0 commit comments