@magicul/react-chat-stream
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -102,3 +102,3 @@ "use strict"; | ||
var fetchAndUpdateAIResponse = function (message) { return __awaiter(void 0, void 0, void 0, function () { | ||
var charactersPerSecond, stream, initialMessage, response, _a, _b, _c, chunk, _i, chunk_1, char, e_1_1; | ||
var charactersPerSecond, stream, initialMessage, response, metadata, _a, _b, _c, chunk, _i, chunk_1, char, e_1_1; | ||
var _d, e_1, _e, _f; | ||
@@ -114,2 +114,3 @@ return __generator(this, function (_g) { | ||
response = ''; | ||
metadata = {}; | ||
_g.label = 2; | ||
@@ -131,2 +132,9 @@ case 2: | ||
} | ||
if (input.options.useMetadata) { | ||
try { | ||
metadata = JSON.parse(chunk.trim()); | ||
return [2 /*return*/, __assign(__assign({}, initialMessage), { content: response, metadata: metadata })]; | ||
} | ||
catch (_h) { } | ||
} | ||
_i = 0, chunk_1 = chunk; | ||
@@ -133,0 +141,0 @@ _g.label = 5; |
@@ -7,2 +7,3 @@ import useChatStream from './hooks/useChatStream'; | ||
content: string; | ||
metadata?: {}; | ||
id: string; | ||
@@ -17,2 +18,3 @@ }; | ||
fakeCharactersPerSecond?: number; | ||
useMetadata?: boolean; | ||
}; | ||
@@ -19,0 +21,0 @@ export type UseChatStreamEventHandlers = { |
{ | ||
"name": "@magicul/react-chat-stream", | ||
"description": "A React hook that lets you easily integrate your custom ChatGPT-like chat in React.", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"main": "dist/index.js", | ||
@@ -6,0 +6,0 @@ "types": "dist/index.d.ts", |
@@ -44,2 +44,3 @@ import { ChangeEvent, FormEvent, useState } from 'react'; | ||
let response = ''; | ||
let metadata = {}; | ||
@@ -53,2 +54,9 @@ for await (const chunk of decodeStreamToJson(stream)) { | ||
if (input.options.useMetadata) { | ||
try { | ||
metadata = JSON.parse(chunk.trim()); | ||
return { ...initialMessage, content: response, metadata: metadata }; | ||
} catch {} | ||
} | ||
// Stream characters one by one based on the characters per second that is set. | ||
@@ -55,0 +63,0 @@ for (const char of chunk) { |
@@ -10,2 +10,3 @@ import useChatStream from './hooks/useChatStream'; | ||
content: string; | ||
metadata?: {}; | ||
id: string, | ||
@@ -21,2 +22,3 @@ } | ||
fakeCharactersPerSecond?: number; | ||
useMetadata?: boolean; | ||
} | ||
@@ -23,0 +25,0 @@ |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48221
717