File tree Expand file tree Collapse file tree
packages/langbase/src/pipes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * Generates a text completion using `generateText()`
3+ *
4+ * @docs : https://langbase.com/docs/langbase-sdk/generate-text
5+ */
6+
17import 'dotenv/config' ;
28import { Pipe } from 'langbase' ;
39
4- // STREAM: OFF
5- console . log ( 'STREAM-OFF: generateText()' ) ;
6-
710// 1. Initiate the Pipe.
811const pipe = new Pipe ( {
912 apiKey : process . env . PIPE_LESS_WORDY ! ,
Original file line number Diff line number Diff line change 1+ /**
2+ * Generates a text completion using `streamText()`
3+ *
4+ * @docs : https://langbase.com/docs/langbase-sdk/stream-text
5+ */
6+
17import 'dotenv/config' ;
28import { Pipe } from 'langbase' ;
39
4- // STREAM: ON
5- console . log ( 'STREAM-ON: streamText()' ) ;
6-
710// 1. Initiate the Pipe.
811const pipe = new Pipe ( {
912 apiKey : process . env . PIPE_LESS_WORDY ! ,
Original file line number Diff line number Diff line change 11import { Request } from '../common/request' ;
22import { Stream } from '../common/stream' ;
33
4+ export type Role = 'user' | 'assistant' | 'system' | 'tool' ;
5+
46export interface Message {
5- role : 'user' | 'assistant' | 'system' ;
7+ role : Role ;
68 content : string ;
79}
810
911export interface GenerateOptions {
1012 messages : Message [ ] ;
11- model ?: string ;
12- temperature ?: number ;
13- max_tokens ?: number ;
1413}
1514
16- export interface Choice {
15+ interface ChoiceNonStream {
1716 index : number ;
18- delta ?: {
19- content ?: string ;
20- } ;
21- message ?: Message ;
17+ message : Message ;
18+ logprobs : boolean | null ;
19+ finish_reason : string ;
20+ }
21+
22+ interface ChoiceStream {
23+ index : number ;
24+ delta : Delta ;
25+ logprobs : boolean | null ;
26+ finish_reason : string ;
27+ }
28+
29+ interface Delta {
30+ role ?: Role ;
31+ content ?: string ;
2232}
2333
2434export interface Usage {
@@ -34,22 +44,22 @@ export interface GenerateNonStreamResponse {
3444 object : string ;
3545 created : number ;
3646 model : string ;
37- choices : Choice [ ] ;
47+ choices : ChoiceNonStream [ ] ;
3848 usage : Usage ;
3949 system_fingerprint : string | null ;
4050 } ;
4151}
4252
53+ export type GenerateStreamResponse = Stream < GenerateStreamChunk > ;
54+
4355export interface GenerateStreamChunk {
4456 id : string ;
4557 object : string ;
4658 created : number ;
4759 model : string ;
48- choices : Choice [ ] ;
60+ choices : ChoiceStream [ ] ;
4961}
5062
51- export type GenerateStreamResponse = Stream < GenerateStreamChunk > ;
52-
5363export interface PipeOptions {
5464 apiKey : string ;
5565 baseUrl ?: string ;
You can’t perform that action at this time.
0 commit comments