vectorvault
Advanced tools
Comparing version 1.2.3 to 1.2.4
93
index.js
@@ -519,56 +519,79 @@ export default class VectorVault { | ||
// Method to run a flow with streaming response | ||
async runFlowStream(params, onEvent) { | ||
async runFlowStream(flowName, message, history = '', callbacks = {}) { | ||
const url = `${this.baseUrl}/flow-stream`; | ||
const data = { | ||
vault: this.vault, | ||
flow_id: '', // The name or ID of the flow | ||
message: '', // The user's message | ||
history: '', // Conversation history if any | ||
...params // Override defaults with provided params | ||
email: this.email, | ||
flow_id: flowName, | ||
message, | ||
history | ||
}; | ||
// Make the authenticated request | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: 'POST', | ||
body: JSON.stringify(data) | ||
method: 'POST', | ||
body: JSON.stringify(data) | ||
}); | ||
// Handle the streaming response | ||
const reader = response.body.getReader(); | ||
const decoder = new TextDecoder('utf-8'); | ||
const decoder = new TextDecoder(); | ||
let fullResponse = ''; | ||
let logs = []; | ||
let currentEventType = null; | ||
let currentData = ''; | ||
const processAccumulatedData = () => { | ||
if (currentEventType && currentData) { | ||
onEvent(currentEventType, currentData); | ||
currentData = ''; | ||
// Process the stream | ||
while (true) { | ||
const { value, done } = await reader.read(); | ||
if (done) break; | ||
const chunk = decoder.decode(value); | ||
const lines = chunk.split('\n'); | ||
for (const line of lines) { | ||
if (line.startsWith('event: ')) { | ||
// Process any previously accumulated data | ||
if (currentData) { | ||
processEventData(currentEventType, currentData, callbacks); | ||
} | ||
currentEventType = line.slice(7).trim(); | ||
currentData = ''; | ||
} else if (line.startsWith('data: ')) { | ||
currentData += line.slice(6); | ||
} | ||
} | ||
} | ||
}; | ||
while (true) { | ||
const { done, value } = await reader.read(); | ||
if (done) break; | ||
// Process any remaining data | ||
if (currentData) { | ||
processEventData(currentEventType, currentData, callbacks); | ||
} | ||
const chunk = decoder.decode(value, { stream: true }); | ||
const lines = chunk.split('\n'); | ||
return { response: fullResponse, logs }; | ||
for (const line of lines) { | ||
if (line.startsWith('event: ')) { | ||
// Process any previously accumulated data | ||
processAccumulatedData(); | ||
currentEventType = line.slice(7).trim(); | ||
} else if (line.startsWith('data: ')) { | ||
currentData += line.slice(6); | ||
function processEventData(eventType, data, callbacks) { | ||
try { | ||
const parsedData = JSON.parse(data); | ||
if (eventType === 'log') { | ||
logs.push(parsedData); | ||
if (callbacks.onLog) callbacks.onLog(parsedData); | ||
} else if (eventType === 'message') { | ||
fullResponse += parsedData; | ||
if (callbacks.onMessage) callbacks.onMessage(parsedData); | ||
} | ||
} catch (e) { | ||
console.error('Error parsing data:', e); | ||
// If parsing fails, treat it as plain text | ||
if (eventType === 'log') { | ||
logs.push(data); | ||
if (callbacks.onLog) callbacks.onLog(data); | ||
} else if (eventType === 'message') { | ||
fullResponse += data; | ||
if (callbacks.onMessage) callbacks.onMessage(data); | ||
} | ||
} | ||
} | ||
} | ||
// Process any remaining data | ||
processAccumulatedData(); | ||
} | ||
// Method to log out the user | ||
@@ -575,0 +598,0 @@ logout() { |
{ | ||
"name": "vectorvault", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "VectorVault API - JavaScript Client: Streamline your front-end development with the powerful combination of OpenAI's API and VectorVault's Cloud Vector Database. This JavaScript client provides seamless integration for building advanced RAG (Retrieve and Generate) applications. Whether you're working with JavaScript, HTML, or other web technologies, our API simplifies the process of fetching RAG responses through API POST requests. This package is the key to unlocking quick and efficient development for AI-powered web applications, ensuring a secure and robust connection to the VectorVault ecosystem. Start crafting exceptional RAG apps with minimal effort and maximum efficiency.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
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
53984
8
1262
8