@singlestore/ai
Advanced tools
Comparing version
import { ChatCompletionMessageParam } from 'openai/resources/chat/completions'; | ||
import { OpenAI } from 'openai'; | ||
type ChatCompletionStream = AsyncIterable<string>; | ||
type ChatCompletionStream = AsyncGenerator<string>; | ||
type ChatCompletionMessage = ChatCompletionMessageParam; | ||
@@ -6,0 +6,0 @@ interface ChatCompletionCreateOptions<T = any> { |
@@ -134,27 +134,25 @@ "use strict"; | ||
})); | ||
const isStreamResponse = (_response) => !!(_options == null ? void 0 : _options.stream); | ||
if (isStreamResponse(response)) { | ||
function asyncIterableFromStream(stream) { | ||
return __asyncGenerator(this, null, function* () { | ||
var _a2; | ||
if (typeof response === "object" && response && "choices" in response) { | ||
return ((_b = response.choices[0]) == null ? void 0 : _b.message.content) || ""; | ||
} | ||
return function() { | ||
return __asyncGenerator(this, null, function* () { | ||
var _a2; | ||
try { | ||
for (var iter = __forAwait(response), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) { | ||
const chunk = temp.value; | ||
yield ((_a2 = chunk.choices[0]) == null ? void 0 : _a2.delta.content) || ""; | ||
} | ||
} catch (temp) { | ||
error = [temp]; | ||
} finally { | ||
try { | ||
for (var iter = __forAwait(stream), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) { | ||
const chunk = temp.value; | ||
yield ((_a2 = chunk.choices[0]) == null ? void 0 : _a2.delta.content) || ""; | ||
} | ||
} catch (temp) { | ||
error = [temp]; | ||
more && (temp = iter.return) && (yield new __await(temp.call(iter))); | ||
} finally { | ||
try { | ||
more && (temp = iter.return) && (yield new __await(temp.call(iter))); | ||
} finally { | ||
if (error) | ||
throw error[0]; | ||
} | ||
if (error) | ||
throw error[0]; | ||
} | ||
}); | ||
} | ||
return asyncIterableFromStream(response); | ||
} | ||
return ((_b = response.choices[0]) == null ? void 0 : _b.message.content) || ""; | ||
} | ||
}); | ||
}(); | ||
}); | ||
@@ -161,0 +159,0 @@ } |
{ | ||
"name": "@singlestore/ai", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
37233
-2.12%453
-0.88%