File tree 6 files changed +13
-7
lines changed
6 files changed +13
-7
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @instructor-ai/instructor " : patch
3
+ ---
4
+
5
+ Fixing inference on stream types when using npm or pnpm
Original file line number Diff line number Diff line change 19
19
"files" : [
20
20
" dist/**"
21
21
],
22
- "typings " : " ./dist/index.d.ts" ,
22
+ "types " : " ./dist/index.d.ts" ,
23
23
"scripts" : {
24
24
"test" : " echo \" Error: no test specified\" && exit 1" ,
25
25
"build" : " tsup" ,
Original file line number Diff line number Diff line change @@ -202,7 +202,9 @@ class Instructor {
202
202
) : Promise < ReturnTypeBasedOnParams < P > > => {
203
203
if ( this . isChatCompletionCreateParamsWithModel ( params ) ) {
204
204
if ( params . stream ) {
205
- return this . chatCompletionStream ( params ) as ReturnTypeBasedOnParams < P >
205
+ return this . chatCompletionStream ( params ) as ReturnTypeBasedOnParams <
206
+ P & { stream : true }
207
+ >
206
208
} else {
207
209
return this . chatCompletionStandard ( params ) as ReturnTypeBasedOnParams < P >
208
210
}
Original file line number Diff line number Diff line change 1
1
import OpenAI from "openai"
2
- import type { ChatCompletionCreateParams } from "openai/resources/index.mjs"
3
- import { Stream } from "openai/streaming.mjs"
2
+ import { Stream } from "openai/streaming"
4
3
import { z } from "zod"
5
4
6
5
import { MODE } from "@/constants/modes"
@@ -27,10 +26,10 @@ export type InstructorChatCompletionParams<T extends z.AnyZodObject> = {
27
26
}
28
27
29
28
export type ChatCompletionCreateParamsWithModel < T extends z . AnyZodObject > =
30
- InstructorChatCompletionParams < T > & ChatCompletionCreateParams
29
+ InstructorChatCompletionParams < T > & OpenAI . ChatCompletionCreateParams
31
30
32
31
export type ReturnWithoutModel < P > =
33
- P extends { stream : true } ? Stream < OpenAI . Chat . Completions . ChatCompletionChunk >
32
+ P extends { stream : true } ? OpenAI . Chat . Completions . ChatCompletion
34
33
: OpenAI . Chat . Completions . ChatCompletion
35
34
36
35
export type ReturnTypeBasedOnParams < P > =
Original file line number Diff line number Diff line change 9
9
import Instructor from "@/instructor"
10
10
import { describe , expect , test } from "bun:test"
11
11
import OpenAI from "openai"
12
- import { Stream } from "openai/streaming.mjs "
12
+ import { Stream } from "openai/streaming"
13
13
import { type } from "ts-inference-check"
14
14
import { z } from "zod"
15
15
You can’t perform that action at this time.
0 commit comments