Socket
Socket
Sign inDemoInstall

llm-interface

Package Overview
Dependencies
Maintainers
0
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

llm-interface - npm Package Compare versions

Comparing version 2.0.142 to 2.0.143

2

package.json
{
"name": "llm-interface",
"version": "2.0.142",
"version": "2.0.143",
"main": "src/index.js",

@@ -5,0 +5,0 @@ "description": "A simple, unified NPM-based interface for interacting with multiple Large Language Model (LLM) APIs, including OpenAI, AI21 Studio, Anthropic, Cloudflare AI, Cohere, Fireworks AI, Google Gemini, Goose AI, Groq, Hugging Face, Mistral AI, Perplexity, Reka AI, watsonx.ai, and LLaMA.cpp.",

@@ -81,4 +81,4 @@ /**

function extractCodeFromResponse(json, attemptRepair) {
// Define regex to match ```javascript block and capture the code inside
const codeBlockRegex = /```javascript\s*([\s\S]*?)\s*```/i;
// Define regex to match ``` block and capture the code inside
const codeBlockRegex = /```([^`]+)\n([\s\S]*?)```/g;

@@ -97,4 +97,5 @@ if (typeof json === 'string' && attemptRepair) {

}
json = json.trim();
}
json = json.trim();
return json;

@@ -116,4 +117,8 @@ }

if (typeof json === 'string' && attemptRepair && regex.test(json)) {
json = extractCodeFromResponse(json);
if (typeof json === 'string') {
if (regex.test(json)) {
json = extractCodeFromResponse(json, true);
} else {
json = findFirstJsonObject(json);
}
}

@@ -131,3 +136,3 @@

return reparsed;
} catch (importError) {
} catch (error) {
return original;

@@ -141,2 +146,38 @@ }

function findFirstJsonObject(inputString) {
let stack = [];
let jsonStartIndex = -1;
let jsonString = '';
for (let i = 0; i < inputString.length; i++) {
const char = inputString[i];
if (char === '{') {
if (stack.length === 0) {
jsonStartIndex = i; // Mark the start of the JSON object
}
stack.push(char);
} else if (char === '}') {
stack.pop();
if (stack.length === 0) {
jsonString = inputString.substring(jsonStartIndex, i + 1);
break;
}
}
}
if (jsonString) {
try {
const jsonObject = JSON.parse(jsonString.replace(/(\w+):/g, '"$1":')); // Adding quotes around keys
return jsonObject;
} catch (error) {
console.error('Error parsing JSON:', error);
}
} else {
console.error('No JSON object found in the input string.');
}
return null;
}
/**

@@ -143,0 +184,0 @@ * Returns a promise that resolves after a specified delay in milliseconds.

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