openlayer 0.0.0 → 0.0.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +412 -0
  3. package/_shims/MultipartBody.d.ts +9 -0
  4. package/_shims/MultipartBody.d.ts.map +1 -0
  5. package/_shims/MultipartBody.js +16 -0
  6. package/_shims/MultipartBody.js.map +1 -0
  7. package/_shims/MultipartBody.mjs +12 -0
  8. package/_shims/MultipartBody.mjs.map +1 -0
  9. package/_shims/README.md +46 -0
  10. package/_shims/auto/runtime-bun.d.ts +5 -0
  11. package/_shims/auto/runtime-bun.d.ts.map +1 -0
  12. package/_shims/auto/runtime-bun.js +21 -0
  13. package/_shims/auto/runtime-bun.js.map +1 -0
  14. package/_shims/auto/runtime-bun.mjs +2 -0
  15. package/_shims/auto/runtime-bun.mjs.map +1 -0
  16. package/_shims/auto/runtime-node.d.ts +5 -0
  17. package/_shims/auto/runtime-node.d.ts.map +1 -0
  18. package/_shims/auto/runtime-node.js +21 -0
  19. package/_shims/auto/runtime-node.js.map +1 -0
  20. package/_shims/auto/runtime-node.mjs +2 -0
  21. package/_shims/auto/runtime-node.mjs.map +1 -0
  22. package/_shims/auto/runtime.d.ts +5 -0
  23. package/_shims/auto/runtime.d.ts.map +1 -0
  24. package/_shims/auto/runtime.js +21 -0
  25. package/_shims/auto/runtime.js.map +1 -0
  26. package/_shims/auto/runtime.mjs +2 -0
  27. package/_shims/auto/runtime.mjs.map +1 -0
  28. package/_shims/auto/types-node.d.ts +5 -0
  29. package/_shims/auto/types-node.d.ts.map +1 -0
  30. package/_shims/auto/types-node.js +21 -0
  31. package/_shims/auto/types-node.js.map +1 -0
  32. package/_shims/auto/types-node.mjs +2 -0
  33. package/_shims/auto/types-node.mjs.map +1 -0
  34. package/_shims/auto/types.d.ts +101 -0
  35. package/_shims/auto/types.js +3 -0
  36. package/_shims/auto/types.mjs +3 -0
  37. package/_shims/bun-runtime.d.ts +6 -0
  38. package/_shims/bun-runtime.d.ts.map +1 -0
  39. package/_shims/bun-runtime.js +14 -0
  40. package/_shims/bun-runtime.js.map +1 -0
  41. package/_shims/bun-runtime.mjs +10 -0
  42. package/_shims/bun-runtime.mjs.map +1 -0
  43. package/_shims/index.d.ts +81 -0
  44. package/_shims/index.js +13 -0
  45. package/_shims/index.mjs +7 -0
  46. package/_shims/manual-types.d.ts +12 -0
  47. package/_shims/manual-types.js +3 -0
  48. package/_shims/manual-types.mjs +3 -0
  49. package/_shims/node-runtime.d.ts +3 -0
  50. package/_shims/node-runtime.d.ts.map +1 -0
  51. package/_shims/node-runtime.js +90 -0
  52. package/_shims/node-runtime.js.map +1 -0
  53. package/_shims/node-runtime.mjs +56 -0
  54. package/_shims/node-runtime.mjs.map +1 -0
  55. package/_shims/node-types.d.ts +42 -0
  56. package/_shims/node-types.js +3 -0
  57. package/_shims/node-types.mjs +3 -0
  58. package/_shims/registry.d.ts +37 -0
  59. package/_shims/registry.d.ts.map +1 -0
  60. package/_shims/registry.js +41 -0
  61. package/_shims/registry.js.map +1 -0
  62. package/_shims/registry.mjs +37 -0
  63. package/_shims/registry.mjs.map +1 -0
  64. package/_shims/web-runtime.d.ts +5 -0
  65. package/_shims/web-runtime.d.ts.map +1 -0
  66. package/_shims/web-runtime.js +78 -0
  67. package/_shims/web-runtime.js.map +1 -0
  68. package/_shims/web-runtime.mjs +71 -0
  69. package/_shims/web-runtime.mjs.map +1 -0
  70. package/_shims/web-types.d.ts +83 -0
  71. package/_shims/web-types.js +3 -0
  72. package/_shims/web-types.mjs +3 -0
  73. package/core.d.ts +237 -0
  74. package/core.d.ts.map +1 -0
  75. package/core.js +868 -0
  76. package/core.js.map +1 -0
  77. package/core.mjs +837 -0
  78. package/core.mjs.map +1 -0
  79. package/error.d.ts +53 -0
  80. package/error.d.ts.map +1 -0
  81. package/error.js +143 -0
  82. package/error.js.map +1 -0
  83. package/error.mjs +127 -0
  84. package/error.mjs.map +1 -0
  85. package/index.d.mts +114 -0
  86. package/index.d.ts +114 -0
  87. package/index.d.ts.map +1 -0
  88. package/index.js +119 -0
  89. package/index.js.map +1 -0
  90. package/index.mjs +91 -0
  91. package/index.mjs.map +1 -0
  92. package/lib/core/cli.d.ts +21 -0
  93. package/lib/core/cli.d.ts.map +1 -0
  94. package/lib/core/cli.js +90 -0
  95. package/lib/core/cli.js.map +1 -0
  96. package/lib/core/cli.mjs +65 -0
  97. package/lib/core/cli.mjs.map +1 -0
  98. package/lib/core/openai-monitor.d.ts +54 -0
  99. package/lib/core/openai-monitor.d.ts.map +1 -0
  100. package/lib/core/openai-monitor.js +376 -0
  101. package/lib/core/openai-monitor.js.map +1 -0
  102. package/lib/core/openai-monitor.mjs +371 -0
  103. package/lib/core/openai-monitor.mjs.map +1 -0
  104. package/package.json +102 -6
  105. package/resource.d.ts +6 -0
  106. package/resource.d.ts.map +1 -0
  107. package/resource.js +11 -0
  108. package/resource.js.map +1 -0
  109. package/resource.mjs +7 -0
  110. package/resource.mjs.map +1 -0
  111. package/resources/commits/commits.d.ts +11 -0
  112. package/resources/commits/commits.d.ts.map +1 -0
  113. package/resources/commits/commits.js +40 -0
  114. package/resources/commits/commits.js.map +1 -0
  115. package/resources/commits/commits.mjs +13 -0
  116. package/resources/commits/commits.mjs.map +1 -0
  117. package/resources/commits/index.d.ts +3 -0
  118. package/resources/commits/index.d.ts.map +1 -0
  119. package/resources/commits/index.js +9 -0
  120. package/resources/commits/index.js.map +1 -0
  121. package/resources/commits/index.mjs +4 -0
  122. package/resources/commits/index.mjs.map +1 -0
  123. package/resources/commits/test-results.d.ts +217 -0
  124. package/resources/commits/test-results.d.ts.map +1 -0
  125. package/resources/commits/test-results.js +18 -0
  126. package/resources/commits/test-results.js.map +1 -0
  127. package/resources/commits/test-results.mjs +14 -0
  128. package/resources/commits/test-results.mjs.map +1 -0
  129. package/resources/index.d.ts +4 -0
  130. package/resources/index.d.ts.map +1 -0
  131. package/resources/index.js +11 -0
  132. package/resources/index.js.map +1 -0
  133. package/resources/index.mjs +5 -0
  134. package/resources/index.mjs.map +1 -0
  135. package/resources/inference-pipelines/data.d.ts +228 -0
  136. package/resources/inference-pipelines/data.d.ts.map +1 -0
  137. package/resources/inference-pipelines/data.js +17 -0
  138. package/resources/inference-pipelines/data.js.map +1 -0
  139. package/resources/inference-pipelines/data.mjs +13 -0
  140. package/resources/inference-pipelines/data.mjs.map +1 -0
  141. package/resources/inference-pipelines/index.d.ts +4 -0
  142. package/resources/inference-pipelines/index.d.ts.map +1 -0
  143. package/resources/inference-pipelines/index.js +11 -0
  144. package/resources/inference-pipelines/index.js.map +1 -0
  145. package/resources/inference-pipelines/index.mjs +5 -0
  146. package/resources/inference-pipelines/index.mjs.map +1 -0
  147. package/resources/inference-pipelines/inference-pipelines.d.ts +16 -0
  148. package/resources/inference-pipelines/inference-pipelines.d.ts.map +1 -0
  149. package/resources/inference-pipelines/inference-pipelines.js +43 -0
  150. package/resources/inference-pipelines/inference-pipelines.js.map +1 -0
  151. package/resources/inference-pipelines/inference-pipelines.mjs +16 -0
  152. package/resources/inference-pipelines/inference-pipelines.mjs.map +1 -0
  153. package/resources/inference-pipelines/test-results.d.ts +217 -0
  154. package/resources/inference-pipelines/test-results.d.ts.map +1 -0
  155. package/resources/inference-pipelines/test-results.js +18 -0
  156. package/resources/inference-pipelines/test-results.js.map +1 -0
  157. package/resources/inference-pipelines/test-results.mjs +14 -0
  158. package/resources/inference-pipelines/test-results.mjs.map +1 -0
  159. package/resources/projects/commits.d.ts +171 -0
  160. package/resources/projects/commits.d.ts.map +1 -0
  161. package/resources/projects/commits.js +18 -0
  162. package/resources/projects/commits.js.map +1 -0
  163. package/resources/projects/commits.mjs +14 -0
  164. package/resources/projects/commits.mjs.map +1 -0
  165. package/resources/projects/index.d.ts +4 -0
  166. package/resources/projects/index.d.ts.map +1 -0
  167. package/resources/projects/index.js +11 -0
  168. package/resources/projects/index.js.map +1 -0
  169. package/resources/projects/index.mjs +5 -0
  170. package/resources/projects/index.mjs.map +1 -0
  171. package/resources/projects/inference-pipelines.d.ts +121 -0
  172. package/resources/projects/inference-pipelines.d.ts.map +1 -0
  173. package/resources/projects/inference-pipelines.js +18 -0
  174. package/resources/projects/inference-pipelines.js.map +1 -0
  175. package/resources/projects/inference-pipelines.mjs +14 -0
  176. package/resources/projects/inference-pipelines.mjs.map +1 -0
  177. package/resources/projects/projects.d.ts +172 -0
  178. package/resources/projects/projects.d.ts.map +1 -0
  179. package/resources/projects/projects.js +50 -0
  180. package/resources/projects/projects.js.map +1 -0
  181. package/resources/projects/projects.mjs +23 -0
  182. package/resources/projects/projects.mjs.map +1 -0
  183. package/shims/node.d.ts +29 -0
  184. package/shims/node.d.ts.map +1 -0
  185. package/shims/node.js +31 -0
  186. package/shims/node.js.map +1 -0
  187. package/shims/node.mjs +5 -0
  188. package/shims/node.mjs.map +1 -0
  189. package/shims/web.d.ts +26 -0
  190. package/shims/web.d.ts.map +1 -0
  191. package/shims/web.js +31 -0
  192. package/shims/web.js.map +1 -0
  193. package/shims/web.mjs +5 -0
  194. package/shims/web.mjs.map +1 -0
  195. package/src/_shims/MultipartBody.ts +9 -0
  196. package/src/_shims/README.md +46 -0
  197. package/src/_shims/auto/runtime-bun.ts +4 -0
  198. package/src/_shims/auto/runtime-node.ts +4 -0
  199. package/src/_shims/auto/runtime.ts +4 -0
  200. package/src/_shims/auto/types-node.ts +4 -0
  201. package/src/_shims/auto/types.d.ts +101 -0
  202. package/src/_shims/auto/types.js +3 -0
  203. package/src/_shims/auto/types.mjs +3 -0
  204. package/src/_shims/bun-runtime.ts +14 -0
  205. package/src/_shims/index.d.ts +81 -0
  206. package/src/_shims/index.js +13 -0
  207. package/src/_shims/index.mjs +7 -0
  208. package/src/_shims/manual-types.d.ts +12 -0
  209. package/src/_shims/manual-types.js +3 -0
  210. package/src/_shims/manual-types.mjs +3 -0
  211. package/src/_shims/node-runtime.ts +83 -0
  212. package/src/_shims/node-types.d.ts +42 -0
  213. package/src/_shims/node-types.js +3 -0
  214. package/src/_shims/node-types.mjs +3 -0
  215. package/src/_shims/registry.ts +67 -0
  216. package/src/_shims/web-runtime.ts +103 -0
  217. package/src/_shims/web-types.d.ts +83 -0
  218. package/src/_shims/web-types.js +3 -0
  219. package/src/_shims/web-types.mjs +3 -0
  220. package/src/core.ts +1146 -0
  221. package/src/error.ts +146 -0
  222. package/src/index.ts +199 -0
  223. package/src/lib/.keep +4 -0
  224. package/src/lib/core/cli.ts +96 -0
  225. package/src/lib/core/index.d.ts +2 -0
  226. package/src/lib/core/openai-monitor.ts +470 -0
  227. package/src/lib/index.d.ts +1 -0
  228. package/src/resource.ts +11 -0
  229. package/src/resources/commits/commits.ts +14 -0
  230. package/src/resources/commits/index.ts +4 -0
  231. package/src/resources/commits/test-results.ts +284 -0
  232. package/src/resources/index.ts +5 -0
  233. package/src/resources/inference-pipelines/data.ts +285 -0
  234. package/src/resources/inference-pipelines/index.ts +5 -0
  235. package/src/resources/inference-pipelines/inference-pipelines.ts +19 -0
  236. package/src/resources/inference-pipelines/test-results.ts +284 -0
  237. package/src/resources/projects/commits.ts +226 -0
  238. package/src/resources/projects/index.ts +9 -0
  239. package/src/resources/projects/inference-pipelines.ts +165 -0
  240. package/src/resources/projects/projects.ts +232 -0
  241. package/src/shims/node.ts +50 -0
  242. package/src/shims/web.ts +50 -0
  243. package/src/tsconfig.json +11 -0
  244. package/src/uploads.ts +248 -0
  245. package/src/version.ts +1 -0
  246. package/uploads.d.ts +75 -0
  247. package/uploads.d.ts.map +1 -0
  248. package/uploads.js +165 -0
  249. package/uploads.js.map +1 -0
  250. package/uploads.mjs +152 -0
  251. package/uploads.mjs.map +1 -0
  252. package/version.d.ts +2 -0
  253. package/version.d.ts.map +1 -0
  254. package/version.js +5 -0
  255. package/version.js.map +1 -0
  256. package/version.mjs +2 -0
  257. package/version.mjs.map +1 -0
@@ -0,0 +1,376 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const openai_1 = __importDefault(require("openai"));
7
+ const OpenAIPricing = {
8
+ 'babbage-002': {
9
+ input: 0.0004,
10
+ output: 0.0004,
11
+ },
12
+ 'davinci-002': {
13
+ input: 0.002,
14
+ output: 0.002,
15
+ },
16
+ 'gpt-3.5-turbo': {
17
+ input: 0.0005,
18
+ output: 0.0015,
19
+ },
20
+ 'gpt-3.5-turbo-0125': {
21
+ input: 0.0005,
22
+ output: 0.0015,
23
+ },
24
+ 'gpt-3.5-turbo-0301': {
25
+ input: 0.0015,
26
+ output: 0.002,
27
+ },
28
+ 'gpt-3.5-turbo-0613': {
29
+ input: 0.0015,
30
+ output: 0.002,
31
+ },
32
+ 'gpt-3.5-turbo-1106': {
33
+ input: 0.001,
34
+ output: 0.002,
35
+ },
36
+ 'gpt-3.5-turbo-16k-0613': {
37
+ input: 0.003,
38
+ output: 0.004,
39
+ },
40
+ 'gpt-3.5-turbo-instruct': {
41
+ input: 0.0015,
42
+ output: 0.002,
43
+ },
44
+ 'gpt-4': {
45
+ input: 0.03,
46
+ output: 0.06,
47
+ },
48
+ 'gpt-4-0125-preview': {
49
+ input: 0.01,
50
+ output: 0.03,
51
+ },
52
+ 'gpt-4-0314': {
53
+ input: 0.03,
54
+ output: 0.06,
55
+ },
56
+ 'gpt-4-0613': {
57
+ input: 0.03,
58
+ output: 0.06,
59
+ },
60
+ 'gpt-4-1106-preview': {
61
+ input: 0.01,
62
+ output: 0.03,
63
+ },
64
+ 'gpt-4-1106-vision-preview': {
65
+ input: 0.01,
66
+ output: 0.03,
67
+ },
68
+ 'gpt-4-32k': {
69
+ input: 0.06,
70
+ output: 0.12,
71
+ },
72
+ 'gpt-4-32k-0314': {
73
+ input: 0.06,
74
+ output: 0.12,
75
+ },
76
+ 'gpt-4-32k-0613': {
77
+ input: 0.03,
78
+ output: 0.06,
79
+ },
80
+ };
81
+ class OpenAIMonitor {
82
+ /**
83
+ * Constructs an OpenAIMonitor instance.
84
+ * @param {OpenAIMonitorConstructorProps} props - The configuration properties for the OpenAI and Openlayer clients.
85
+ */
86
+ constructor({ openAiApiKey, openlayerClient, openlayerInferencePipelineId, }) {
87
+ this.defaultConfig = {
88
+ costColumnName: 'cost',
89
+ inferenceIdColumnName: 'id',
90
+ latencyColumnName: 'latency',
91
+ numOfTokenColumnName: 'tokens',
92
+ outputColumnName: 'output',
93
+ timestampColumnName: 'timestamp',
94
+ };
95
+ this.cost = (model, inputTokens, outputTokens) => {
96
+ const pricing = OpenAIPricing[model];
97
+ const inputCost = typeof pricing === 'undefined' ? undefined : (inputTokens / 1000) * pricing.input;
98
+ const outputCost = typeof pricing === 'undefined' ? undefined : (outputTokens / 1000) * pricing.output;
99
+ return typeof pricing === 'undefined' ? undefined : (inputCost ?? 0) + (outputCost ?? 0);
100
+ };
101
+ this.chatCompletionPrompt = (fromMessages) => fromMessages.map(({ content, role }, i) => ({
102
+ content: role === 'user' ? `{{ message_${i} }}`
103
+ : content === null || typeof content === 'undefined' ? ''
104
+ : content,
105
+ role,
106
+ }));
107
+ this.threadPrompt = async (fromMessages) => {
108
+ const messages = [];
109
+ for await (const page of fromMessages.iterPages()) {
110
+ messages.push(...page.getPaginatedItems());
111
+ }
112
+ return messages
113
+ .map(({ content, role }) => content.map((item) => ({
114
+ content: (() => {
115
+ switch (item.type) {
116
+ case 'image_file':
117
+ return item.image_file.file_id;
118
+ case 'text':
119
+ return item.text.value;
120
+ default:
121
+ return '';
122
+ }
123
+ })(),
124
+ role,
125
+ })))
126
+ .flat();
127
+ };
128
+ this.inputVariables = (fromPrompt, andMessages) => {
129
+ const inputVariableNames = fromPrompt
130
+ .filter(({ role }) => role === 'user')
131
+ .map(({ content }) => String(content).replace(/{{\s*|\s*}}/g, ''));
132
+ const inputVariables = andMessages
133
+ .filter(({ role }) => role === 'user')
134
+ .map(({ content }) => content);
135
+ const inputVariablesMap = inputVariableNames.reduce((acc, name, i) => ({ ...acc, [name]: inputVariables[i] }), {});
136
+ return { inputVariableNames, inputVariables, inputVariablesMap };
137
+ };
138
+ /**
139
+ * Creates a chat completion using the OpenAI client and streams the result to Openlayer.
140
+ * @param {ChatCompletionCreateParams} body - The parameters for creating a chat completion.
141
+ * @param {RequestOptions} [options] - Optional request options.
142
+ * @param {Openlayer.RequestOptions<any> | undefined} [additionalLogs] - Optional metadata logs to include with the request sent to Openlayer.
143
+ * @returns {Promise<ChatCompletion | Stream<ChatCompletionChunk>>} Promise of a ChatCompletion or a Stream
144
+ * @throws {Error} Throws errors from the OpenAI client.
145
+ */
146
+ this.createChatCompletion = async (body, options, additionalLogs) => {
147
+ // Start a timer to measure latency
148
+ const startTime = Date.now();
149
+ // Accumulate output for streamed responses
150
+ let streamedOutput = '';
151
+ const response = await this.openAIClient.chat.completions.create(body, options);
152
+ if (this.openlayerInferencePipelineId.length > 0) {
153
+ try {
154
+ const prompt = this.chatCompletionPrompt(body.messages);
155
+ const { inputVariableNames, inputVariablesMap } = this.inputVariables(prompt, body.messages);
156
+ const config = {
157
+ ...this.defaultConfig,
158
+ inputVariableNames,
159
+ prompt,
160
+ };
161
+ if (body.stream) {
162
+ const streamedResponse = response;
163
+ for await (const chunk of streamedResponse) {
164
+ const [choice] = chunk.choices;
165
+ // Process each chunk - for example, accumulate input data
166
+ const chunkOutput = choice?.delta.content ?? '';
167
+ streamedOutput += chunkOutput;
168
+ }
169
+ const endTime = Date.now();
170
+ const latency = endTime - startTime;
171
+ this.openlayerClient.inferencePipelines.data.stream(this.openlayerInferencePipelineId, {
172
+ config,
173
+ rows: [
174
+ {
175
+ latency,
176
+ output: streamedOutput,
177
+ timestamp: startTime,
178
+ ...inputVariablesMap,
179
+ ...additionalLogs,
180
+ },
181
+ ],
182
+ });
183
+ }
184
+ else {
185
+ const nonStreamedResponse = response;
186
+ // Handle regular (non-streamed) response
187
+ const endTime = Date.now();
188
+ const latency = endTime - startTime;
189
+ const [choice] = nonStreamedResponse.choices;
190
+ const output = choice?.message.content;
191
+ const tokens = nonStreamedResponse.usage?.total_tokens ?? 0;
192
+ const inputTokens = nonStreamedResponse.usage?.prompt_tokens ?? 0;
193
+ const outputTokens = nonStreamedResponse.usage?.completion_tokens ?? 0;
194
+ const cost = this.cost(nonStreamedResponse.model, inputTokens, outputTokens);
195
+ if (typeof output === 'string') {
196
+ this.openlayerClient.inferencePipelines.data.stream(this.openlayerInferencePipelineId, {
197
+ config,
198
+ rows: [
199
+ {
200
+ cost,
201
+ latency,
202
+ model: nonStreamedResponse.model,
203
+ output,
204
+ timestamp: startTime,
205
+ tokens,
206
+ ...inputVariablesMap,
207
+ ...additionalLogs,
208
+ },
209
+ ],
210
+ });
211
+ }
212
+ else {
213
+ console.error('No output received from OpenAI.');
214
+ }
215
+ }
216
+ }
217
+ catch (error) {
218
+ console.error(error);
219
+ }
220
+ }
221
+ return response;
222
+ };
223
+ /**
224
+ * Creates a completion using the OpenAI client and streams the result to Openlayer.
225
+ * @param {CompletionCreateParams} body - The parameters for creating a completion.
226
+ * @param {RequestOptions} [options] - Optional request options.
227
+ * @param {Openlayer.RequestOptions<any> | undefined} [additionalLogs] - Optional metadata logs to include with the request sent to Openlayer.
228
+ * @returns {Promise<Completion | Stream<Completion>>} Promise that resolves to a Completion or a Stream.
229
+ * @throws {Error} Throws errors from the OpenAI client.
230
+ */
231
+ this.createCompletion = async (body, options, additionalLogs) => {
232
+ if (!body.prompt) {
233
+ console.error('No prompt provided.');
234
+ }
235
+ // Start a timer to measure latency
236
+ const startTime = Date.now();
237
+ // Accumulate output and tokens data for streamed responses
238
+ let streamedModel = body.model;
239
+ let streamedOutput = '';
240
+ let streamedTokens = 0;
241
+ let streamedInputTokens = 0;
242
+ let streamedOutputTokens = 0;
243
+ const response = await this.openAIClient.completions.create(body, options);
244
+ if (this.openlayerInferencePipelineId.length > 0) {
245
+ try {
246
+ const config = {
247
+ ...this.defaultConfig,
248
+ inputVariableNames: ['input'],
249
+ };
250
+ if (body.stream) {
251
+ const streamedResponse = response;
252
+ for await (const chunk of streamedResponse) {
253
+ const [choice] = chunk.choices;
254
+ // Process each chunk - for example, accumulate input data
255
+ streamedModel = chunk.model;
256
+ streamedOutput += choice?.text.trim();
257
+ streamedTokens += chunk.usage?.total_tokens ?? 0;
258
+ streamedInputTokens += chunk.usage?.prompt_tokens ?? 0;
259
+ streamedOutputTokens += chunk.usage?.completion_tokens ?? 0;
260
+ }
261
+ const endTime = Date.now();
262
+ const latency = endTime - startTime;
263
+ const cost = this.cost(streamedModel, streamedInputTokens, streamedOutputTokens);
264
+ this.openlayerClient.inferencePipelines.data.stream(this.openlayerInferencePipelineId, {
265
+ config,
266
+ rows: [
267
+ {
268
+ cost,
269
+ input: body.prompt,
270
+ latency,
271
+ output: streamedOutput,
272
+ timestamp: startTime,
273
+ tokens: streamedTokens,
274
+ ...additionalLogs,
275
+ },
276
+ ],
277
+ });
278
+ }
279
+ else {
280
+ const nonStreamedResponse = response;
281
+ const [choice] = nonStreamedResponse.choices;
282
+ // Handle regular (non-streamed) response
283
+ const endTime = Date.now();
284
+ const latency = endTime - startTime;
285
+ const tokens = nonStreamedResponse.usage?.total_tokens ?? 0;
286
+ const inputTokens = nonStreamedResponse.usage?.prompt_tokens ?? 0;
287
+ const outputTokens = nonStreamedResponse.usage?.completion_tokens ?? 0;
288
+ const cost = this.cost(nonStreamedResponse.model, inputTokens, outputTokens);
289
+ this.openlayerClient.inferencePipelines.data.stream(this.openlayerInferencePipelineId, {
290
+ config,
291
+ rows: [
292
+ {
293
+ cost,
294
+ input: body.prompt,
295
+ latency,
296
+ output: choice?.text ?? '',
297
+ timestamp: startTime,
298
+ tokens,
299
+ ...additionalLogs,
300
+ },
301
+ ],
302
+ });
303
+ }
304
+ }
305
+ catch (error) {
306
+ console.error(error);
307
+ }
308
+ }
309
+ return response;
310
+ };
311
+ this.openlayerInferencePipelineId = openlayerInferencePipelineId;
312
+ this.openlayerClient = openlayerClient;
313
+ this.openAIClient = new openai_1.default({
314
+ apiKey: openAiApiKey,
315
+ dangerouslyAllowBrowser: true,
316
+ });
317
+ }
318
+ /**
319
+ * Monitor a run from an OpenAI assistant.
320
+ * Once the run is completed, the thread data is published to Openlayer,
321
+ * along with the latency, cost, and number of tokens used.
322
+ * @param {Run} run - The run created by the OpenAI assistant.
323
+ * @param {Openlayer.RequestOptions<any> | undefined} [additionalLogs] - Optional metadata logs to include with the request sent to Openlayer.
324
+ * @returns {Promise<void>} A promise that resolves when the run data has been successfully published to Openlayer.
325
+ */
326
+ async monitorThreadRun(run, additionalLogs) {
327
+ if (run.status !== 'completed' || this.openlayerInferencePipelineId.length === 0) {
328
+ return;
329
+ }
330
+ try {
331
+ const { assistant_id, completed_at, created_at, model, thread_id,
332
+ // @ts-ignore
333
+ usage, } = run;
334
+ // @ts-ignore
335
+ const { completion_tokens, prompt_tokens, total_tokens } = typeof usage === 'undefined' || typeof usage !== 'object' || usage === null ? {} : usage;
336
+ const cost = this.cost(model, prompt_tokens, completion_tokens);
337
+ const latency = completed_at === null || created_at === null || isNaN(completed_at) || isNaN(created_at) ?
338
+ undefined
339
+ : (completed_at - created_at) * 1000;
340
+ const messages = await this.openAIClient.beta.threads.messages.list(thread_id, { order: 'asc' });
341
+ const populatedPrompt = await this.threadPrompt(messages);
342
+ const prompt = this.chatCompletionPrompt(populatedPrompt);
343
+ const { inputVariableNames, inputVariablesMap } = this.inputVariables(prompt, populatedPrompt);
344
+ const config = {
345
+ ...this.defaultConfig,
346
+ inputVariableNames,
347
+ prompt: prompt.slice(0, prompt.length - 1),
348
+ };
349
+ const output = prompt[prompt.length - 1]?.content;
350
+ const resolvedOutput = typeof output === 'string' ? output
351
+ : typeof output === 'undefined' || output === null ? ''
352
+ : `${output}`;
353
+ this.openlayerClient.inferencePipelines.data.stream(this.openlayerInferencePipelineId, {
354
+ config,
355
+ rows: [
356
+ {
357
+ cost,
358
+ latency,
359
+ openai_assistant_id: assistant_id,
360
+ openai_thread_id: thread_id,
361
+ output: resolvedOutput,
362
+ timestamp: run.created_at,
363
+ tokens: total_tokens,
364
+ ...inputVariablesMap,
365
+ ...additionalLogs,
366
+ },
367
+ ],
368
+ });
369
+ }
370
+ catch (error) {
371
+ console.error('Error logging thread run:', error);
372
+ }
373
+ }
374
+ }
375
+ exports.default = OpenAIMonitor;
376
+ //# sourceMappingURL=openai-monitor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-monitor.js","sourceRoot":"","sources":["../../src/lib/core/openai-monitor.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AA0B5B,MAAM,aAAa,GAA+B;IAChD,aAAa,EAAE;QACb,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,MAAM;KACf;IACD,aAAa,EAAE;QACb,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE,KAAK;KACd;IACD,eAAe,EAAE;QACf,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,MAAM;KACf;IACD,oBAAoB,EAAE;QACpB,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,MAAM;KACf;IACD,oBAAoB,EAAE;QACpB,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,KAAK;KACd;IACD,oBAAoB,EAAE;QACpB,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,KAAK;KACd;IACD,oBAAoB,EAAE;QACpB,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE,KAAK;KACd;IACD,wBAAwB,EAAE;QACxB,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE,KAAK;KACd;IACD,wBAAwB,EAAE;QACxB,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,KAAK;KACd;IACD,OAAO,EAAE;QACP,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,IAAI;KACb;IACD,oBAAoB,EAAE;QACpB,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,IAAI;KACb;IACD,YAAY,EAAE;QACZ,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,IAAI;KACb;IACD,YAAY,EAAE;QACZ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