@@ -26,30 +26,26 @@ const client = new Openlayer({
26
26
apiKey: process .env [' OPENLAYER_API_KEY' ], // This is the default and can be omitted
27
27
});
28
28
29
- async function main () {
30
- const response = await client .inferencePipelines .data .stream (' 182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e' , {
31
- config: {
32
- inputVariableNames: [' user_query' ],
33
- outputColumnName: ' output' ,
34
- numOfTokenColumnName: ' tokens' ,
35
- costColumnName: ' cost' ,
36
- timestampColumnName: ' timestamp' ,
29
+ const response = await client .inferencePipelines .data .stream (' 182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e' , {
30
+ config: {
31
+ inputVariableNames: [' user_query' ],
32
+ outputColumnName: ' output' ,
33
+ numOfTokenColumnName: ' tokens' ,
34
+ costColumnName: ' cost' ,
35
+ timestampColumnName: ' timestamp' ,
36
+ },
37
+ rows: [
38
+ {
39
+ user_query: ' what is the meaning of life?' ,
40
+ output: ' 42' ,
41
+ tokens: 7 ,
42
+ cost: 0.02 ,
43
+ timestamp: 1610000000 ,
37
44
},
38
- rows: [
39
- {
40
- user_query: ' what is the meaning of life?' ,
41
- output: ' 42' ,
42
- tokens: 7 ,
43
- cost: 0.02 ,
44
- timestamp: 1610000000 ,
45
- },
46
- ],
47
- });
48
-
49
- console .log (response .success );
50
- }
45
+ ],
46
+ });
51
47
52
- main ( );
48
+ console . log ( response . success );
53
49
```
54
50
55
51
### Request & Response types
@@ -64,8 +60,42 @@ const client = new Openlayer({
64
60
apiKey: process .env [' OPENLAYER_API_KEY' ], // This is the default and can be omitted
65
61
});
66
62
67
- async function main() {
68
- const params: Openlayer .InferencePipelines .DataStreamParams = {
63
+ const params: Openlayer .InferencePipelines .DataStreamParams = {
64
+ config: {
65
+ inputVariableNames: [' user_query' ],
66
+ outputColumnName: ' output' ,
67
+ numOfTokenColumnName: ' tokens' ,
68
+ costColumnName: ' cost' ,
69
+ timestampColumnName: ' timestamp' ,
70
+ },
71
+ rows: [
72
+ {
73
+ user_query: ' what is the meaning of life?' ,
74
+ output: ' 42' ,
75
+ tokens: 7 ,
76
+ cost: 0.02 ,
77
+ timestamp: 1610000000 ,
78
+ },
79
+ ],
80
+ };
81
+ const response: Openlayer .InferencePipelines .DataStreamResponse = await client .inferencePipelines .data .stream (
82
+ ' 182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e' ,
83
+ params ,
84
+ );
85
+ ```
86
+
87
+ Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
88
+
89
+ ## Handling errors
90
+
91
+ When the library is unable to connect to the API,
92
+ or if the API returns a non-success status code (i.e., 4xx or 5xx response),
93
+ a subclass of ` APIError ` will be thrown:
94
+
95
+ <!-- prettier-ignore -->
96
+ ``` ts
97
+ const response = await client .inferencePipelines .data
98
+ .stream (' 182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e' , {
69
99
config: {
70
100
inputVariableNames: [' user_query' ],
71
101
outputColumnName: ' output' ,
@@ -82,56 +112,16 @@ async function main() {
82
112
timestamp: 1610000000 ,
83
113
},
84
114
],
85
- };
86
- const response: Openlayer .InferencePipelines .DataStreamResponse =
87
- await client .inferencePipelines .data .stream (' 182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e' , params );
88
- }
89
-
90
- main ();
91
- ```
92
-
93
- Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
94
-
95
- ## Handling errors
96
-
97
- When the library is unable to connect to the API,
98
- or if the API returns a non-success status code (i.e., 4xx or 5xx response),
99
- a subclass of ` APIError ` will be thrown:
100
-
101
- <!-- prettier-ignore -->
102
- ``` ts
103
- async function main() {
104
- const response = await client .inferencePipelines .data
105
- .stream (' 182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e' , {
106
- config: {
107
- inputVariableNames: [' user_query' ],
108
- outputColumnName: ' output' ,
109
- numOfTokenColumnName: ' tokens' ,
110
- costColumnName: ' cost' ,
111
- timestampColumnName: ' timestamp' ,
112
- },
113
- rows: [
114
- {
115
- user_query: ' what is the meaning of life?' ,
116
- output: ' 42' ,
117
- tokens: 7 ,
118
- cost: 0.02 ,
119
- timestamp: 1610000000 ,
120
- },
121
- ],
122
- })
123
- .catch (async (err ) => {
124
- if (err instanceof Openlayer .APIError ) {
125
- console .log (err .status ); // 400
126
- console .log (err .name ); // BadRequestError
127
- console .log (err .headers ); // {server: 'nginx', ...}
128
- } else {
129
- throw err ;
130
- }
131
- });
132
- }
133
-
134
- main ();
115
+ })
116
+ .catch (async (err ) => {
117
+ if (err instanceof Openlayer .APIError ) {
118
+ console .log (err .status ); // 400
119
+ console .log (err .name ); // BadRequestError
120
+ console .log (err .headers ); // {server: 'nginx', ...}
121
+ } else {
122
+ throw err ;
123
+ }
124
+ });
135
125
```
136
126
137
127
Error codes are as follows:
0 commit comments