Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@magicul/react-chat-stream

Package Overview
Dependencies
Maintainers
0
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@magicul/react-chat-stream - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

10

dist/hooks/useChatStream.js

@@ -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 = {

2

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc