Skip to content

Commit

Permalink
feat: safeDecordeURIComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
samestrin committed Jul 19, 2024
1 parent d4119d8 commit 7b68a16
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Star on GitHub](https://img.shields.io/github/stars/samestrin/llm-interface?style=social)](https://github.com/samestrin/llm-interface/stargazers) [![Fork on GitHub](https://img.shields.io/github/forks/samestrin/llm-interface?style=social)](https://github.com/samestrin/llm-interface/network/members) [![Watch on GitHub](https://img.shields.io/github/watchers/samestrin/llm-interface?style=social)](https://github.com/samestrin/llm-interface/watchers)

![Version 2.0.143](https://img.shields.io/badge/Version-2.0.143-blue) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Built with Node.js](https://img.shields.io/badge/Built%20with-Node.js-green)](https://nodejs.org/)
![Version 2.0.144](https://img.shields.io/badge/Version-2.0.144-blue) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Built with Node.js](https://img.shields.io/badge/Built%20with-Node.js-green)](https://nodejs.org/)

## Introduction

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "llm-interface",
"version": "2.0.143",
"version": "2.0.144",
"main": "src/index.js",
"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.",
"type": "commonjs",
Expand Down
23 changes: 21 additions & 2 deletions src/interfaces/groq.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const BaseInterface = require('./baseInterface.js');
const { groqApiKey } = require('../utils/loadApiKeysFromEnv.js');
const { getConfig, loadProviderConfig } = require('../utils/configManager.js');

const log = require('loglevel');
const interfaceName = 'groq';

loadProviderConfig(interfaceName);
Expand All @@ -22,11 +22,30 @@ class Groq extends BaseInterface {

recoverError(error) {
if (error.response?.data?.error?.failed_generation) {
return decodeURIComponent(error.response?.data?.error?.failed_generation);
return this.unescapeString(
error.response?.data?.error?.failed_generation,
);
}

return null;
}
/**
* Unescapes common escape sequences in a string.
* @param {string} str - The string with escape sequences.
* @returns {string} - The unescaped string.
*/
unescapeString(str) {
return str
.replace(/\\n/g, '\n')
.replace(/\\t/g, '\t')
.replace(/\\r/g, '\r')
.replace(/\\f/g, '\f')
.replace(/\\b/g, '\b')
.replace(/\\v/g, '\v')
.replace(/\\'/g, "'")
.replace(/\\"/g, '"')
.replace(/\\\\/g, '\\');
}
}

module.exports = Groq;

0 comments on commit 7b68a16

Please sign in to comment.