Skip to content

Commit 3a2f75d

Browse files
committed
👌 IMPROVE: types
1 parent 899dffe commit 3a2f75d

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

packages/langbase/src/pipes/pipes.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@ export interface Variable {
3030
export interface GenerateOptions {
3131
messages?: Message[];
3232
variables?: Variable[];
33+
threadId?: string;
34+
chat?: boolean;
3335
}
3436

3537
export interface StreamOptions {
3638
messages?: Message[];
3739
variables?: Variable[];
40+
threadId?: string | null;
41+
chat?: boolean;
3842
}
3943

40-
interface ChoiceNonStream {
44+
interface ChoiceGenerate {
4145
index: number;
4246
message: Message;
4347
logprobs: boolean | null;
@@ -63,22 +67,26 @@ export interface Usage {
6367
total_tokens: number;
6468
}
6569

66-
export interface GenerateNonStreamResponse {
70+
export interface GenerateResponse {
6771
completion: string;
68-
raw: {
69-
id: string;
70-
object: string;
71-
created: number;
72-
model: string;
73-
choices: ChoiceNonStream[];
74-
usage: Usage;
75-
system_fingerprint: string | null;
76-
};
72+
threadId?: string;
73+
id: string;
74+
object: string;
75+
created: number;
76+
model: string;
77+
choices: ChoiceGenerate[];
78+
usage: Usage;
79+
system_fingerprint: string | null;
7780
}
7881

79-
export type GenerateStreamResponse = Stream<GenerateStreamChunk>;
82+
export type StreamText = Stream<StreamChunk>;
8083

81-
export interface GenerateStreamChunk {
84+
export interface StreamResponse {
85+
stream: StreamText;
86+
threadId: string | null;
87+
}
88+
89+
export interface StreamChunk {
8290
id: string;
8391
object: string;
8492
created: number;
@@ -106,11 +114,10 @@ export class Pipe {
106114
});
107115
}
108116

109-
async streamText(options: StreamOptions): Promise<GenerateStreamResponse> {
110-
return this.request.post<GenerateStreamResponse>({
111-
endpoint: '/beta/generate',
117+
async streamText(options: StreamOptions): Promise<StreamResponse> {
118+
return this.request.post<StreamResponse>({
119+
endpoint: options.chat ? '/beta/chat' : '/beta/generate',
112120
body: {...options, stream: true},
113-
stream: true, // TODO: @ahmadbilaldev - why we need to add here as well?
114121
});
115122
}
116123
}

0 commit comments

Comments
 (0)