graphlit-client 1.0.20250615005 → 1.0.20250617001
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.
- package/dist/client.js +3 -2
- package/dist/streaming/providers.js +62 -9
- package/package.json +1 -1
package/dist/client.js
CHANGED
@@ -2392,8 +2392,9 @@ class Graphlit {
|
|
2392
2392
|
}
|
2393
2393
|
// Complete the conversation and get token count
|
2394
2394
|
let finalTokens;
|
2395
|
-
|
2396
|
-
|
2395
|
+
const trimmedMessage = fullMessage?.trim();
|
2396
|
+
if (trimmedMessage) {
|
2397
|
+
const completeResponse = await this.completeConversation(trimmedMessage, conversationId, correlationId);
|
2397
2398
|
// Extract token count from the response
|
2398
2399
|
finalTokens =
|
2399
2400
|
completeResponse.completeConversation?.message?.tokens ?? undefined;
|
@@ -11,6 +11,36 @@ function isValidJSON(str) {
|
|
11
11
|
return false;
|
12
12
|
}
|
13
13
|
}
|
14
|
+
/**
|
15
|
+
* Simplify schema for Groq by removing complex features that may cause issues
|
16
|
+
*/
|
17
|
+
function simplifySchemaForGroq(schema) {
|
18
|
+
if (typeof schema !== "object" || schema === null) {
|
19
|
+
return JSON.stringify(schema);
|
20
|
+
}
|
21
|
+
// Remove complex JSON Schema features that Groq might not support
|
22
|
+
const simplified = {
|
23
|
+
type: schema.type || "object",
|
24
|
+
properties: {},
|
25
|
+
required: schema.required || []
|
26
|
+
};
|
27
|
+
// Only keep basic properties and types
|
28
|
+
if (schema.properties) {
|
29
|
+
for (const [key, value] of Object.entries(schema.properties)) {
|
30
|
+
const prop = value;
|
31
|
+
simplified.properties[key] = {
|
32
|
+
type: prop.type || "string",
|
33
|
+
description: prop.description || "",
|
34
|
+
// Remove complex features like patterns, formats, etc.
|
35
|
+
};
|
36
|
+
// Keep enum if present (but simplified)
|
37
|
+
if (prop.enum && Array.isArray(prop.enum)) {
|
38
|
+
simplified.properties[key].enum = prop.enum;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
return JSON.stringify(simplified);
|
43
|
+
}
|
14
44
|
/**
|
15
45
|
* Clean schema for Google Gemini by removing unsupported fields
|
16
46
|
*/
|
@@ -1042,8 +1072,27 @@ onEvent, onComplete) {
|
|
1042
1072
|
export async function streamWithGroq(specification, messages, tools, groqClient, // Groq client instance (OpenAI-compatible)
|
1043
1073
|
onEvent, onComplete) {
|
1044
1074
|
try {
|
1075
|
+
const modelName = getModelName(specification);
|
1076
|
+
// Filter or simplify tools for Groq models that have issues
|
1077
|
+
let groqTools = tools;
|
1078
|
+
if (tools && tools.length > 0) {
|
1079
|
+
// LLaMA 3.3 70B seems to have tool calling issues - disable tools for this model
|
1080
|
+
if (modelName && (modelName.includes("llama-3.3") || modelName.includes("LLAMA_3_3"))) {
|
1081
|
+
if (process.env.DEBUG_GRAPHLIT_SDK_STREAMING) {
|
1082
|
+
console.log(`⚠️ [Groq] Disabling tools for ${modelName} due to known compatibility issues`);
|
1083
|
+
}
|
1084
|
+
groqTools = undefined;
|
1085
|
+
}
|
1086
|
+
else {
|
1087
|
+
// For other models, simplify complex schemas
|
1088
|
+
groqTools = tools.map(tool => ({
|
1089
|
+
...tool,
|
1090
|
+
schema: tool.schema ? simplifySchemaForGroq(JSON.parse(tool.schema)) : tool.schema
|
1091
|
+
}));
|
1092
|
+
}
|
1093
|
+
}
|
1045
1094
|
// Groq uses the same API as OpenAI, so we can reuse the OpenAI streaming logic
|
1046
|
-
return await streamWithOpenAI(specification, messages,
|
1095
|
+
return await streamWithOpenAI(specification, messages, groqTools, groqClient, onEvent, onComplete);
|
1047
1096
|
}
|
1048
1097
|
catch (error) {
|
1049
1098
|
// Handle Groq-specific errors
|
@@ -1324,9 +1373,12 @@ onEvent, onComplete) {
|
|
1324
1373
|
throw new Error("No messages found for Cohere streaming");
|
1325
1374
|
}
|
1326
1375
|
// Cohere v7 expects a single message and optional chatHistory
|
1327
|
-
// Extract
|
1328
|
-
const
|
1329
|
-
const
|
1376
|
+
// Extract system messages for preamble and filter them out of history
|
1377
|
+
const systemMessages = messages.filter(msg => msg.role === "SYSTEM");
|
1378
|
+
const nonSystemMessages = messages.filter(msg => msg.role !== "SYSTEM");
|
1379
|
+
// Extract the last non-system message as the current message
|
1380
|
+
const lastMessage = nonSystemMessages[nonSystemMessages.length - 1];
|
1381
|
+
const chatHistory = nonSystemMessages.slice(0, -1);
|
1330
1382
|
if (!lastMessage || !lastMessage.message) {
|
1331
1383
|
throw new Error("Last message must have message property for Cohere streaming");
|
1332
1384
|
}
|
@@ -1335,9 +1387,15 @@ onEvent, onComplete) {
|
|
1335
1387
|
model: modelName,
|
1336
1388
|
message: lastMessage.message, // Current message (singular)
|
1337
1389
|
};
|
1390
|
+
// Add system message as preamble if present
|
1391
|
+
if (systemMessages.length > 0) {
|
1392
|
+
// Combine all system messages into preamble
|
1393
|
+
streamConfig.preamble = systemMessages.map(msg => msg.message).join("\n\n");
|
1394
|
+
}
|
1338
1395
|
// Add chat history if there are previous messages
|
1339
1396
|
if (chatHistory.length > 0) {
|
1340
1397
|
// Build properly typed chat history using Cohere SDK Message types
|
1398
|
+
// Note: SYSTEM messages are already filtered out and handled as preamble
|
1341
1399
|
const cohereHistory = chatHistory.map((msg) => {
|
1342
1400
|
switch (msg.role) {
|
1343
1401
|
case "USER":
|
@@ -1358,11 +1416,6 @@ onEvent, onComplete) {
|
|
1358
1416
|
}));
|
1359
1417
|
}
|
1360
1418
|
return chatbotMsg;
|
1361
|
-
case "SYSTEM":
|
1362
|
-
return {
|
1363
|
-
role: "SYSTEM",
|
1364
|
-
message: msg.message,
|
1365
|
-
};
|
1366
1419
|
case "TOOL":
|
1367
1420
|
return {
|
1368
1421
|
role: "TOOL",
|