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

ai-driven

Package Overview
Dependencies
Maintainers
0
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ai-driven - npm Package Compare versions

Comparing version 0.0.2 to 0.1.1

2

example.ts

@@ -8,3 +8,3 @@ import Assistant from 'ai-driven';

// Example of using the translation function
const translatedText = await assistant.translateText('Bonjour le monde!');
const translatedText = await assistant.translateText('Bonjour le monde!', 'it');
console.log('Translated text:', translatedText);

@@ -11,0 +11,0 @@

{
"name": "ai-driven",
"version": "0.0.2",
"version": "0.1.1",
"license": "MIT",
"author": "Dimitry Ivanov <2@ivanoff.org.ua> # curl -A cv ivanoff.org.ua",
"description": "AI Assistant",
"description": "AI-Driven Assistant with zero dependencies",
"keywords": ["ai", "assistant"],

@@ -11,3 +11,3 @@ "main": "./dist/index.js",

"scripts": {
"build": "bun build ./src/index.ts --outdir ./dist && tsc"
"build": "bun build ./src/index.ts --outdir ./dist --minify && tsc"
},

@@ -14,0 +14,0 @@ "devDependencies": {

@@ -26,3 +26,3 @@ # ai-driven

1. Create a `.env` file in the root of your project.
2. Add your Claude API key and URL to the `.env` file:
2. Add your Claude API key (required) and URL with Model to the `.env` file:

@@ -32,2 +32,3 @@ ```

CLAUDE_API_URL=https://api.anthropic.com/v1/messages
CLAUDE_API_MODEL=claude-3-opus-20240229
```

@@ -47,3 +48,3 @@

// Translate text
const translatedText = await assistant.translateText('Hello, world!');
const translatedText = await assistant.translateText('Hello, world!', 'it');
console.log('Translated text:', translatedText);

@@ -76,16 +77,16 @@

1. `translateText(text: string): Promise<string>`
- Translates the given text to English.
1. `translateText(text: string, lang?: string, context?: string ): Promise<string>`
- Translates the given text to selected language (English by default).
2. `checkForOffensiveLanguage(text: string): Promise<number>`
- Checks the given text for offensive language and returns a score from 1 to 10.
- Checks the given text for offensive language and returns a score from 1 to 10, where 1 is very peaceful and 10 is extremely aggressive.
3. `checkForProfanity(text: string): Promise<number>`
- Checks the given text for profanity and returns a score from 1 to 10.
- Checks the given text for profanity and returns a score from 1 to 10, where 1 is very clean and 10 is extremely profane.
4. `checkImageForViolence(imageBuffer: Buffer): Promise<number>`
- Analyzes the given image for violent content and returns a score from 1 to 10.
- Analyzes the given image for violent content and returns a score from 1 to 10, where 1 is very peaceful and 10 is extremely violent.
5. `checkImageForPornography(imageBuffer: Buffer): Promise<number>`
- Analyzes the given image for pornographic content and returns a score from 1 to 10.
- Analyzes the given image for pornographic content and returns a score from 1 to 10, where 1 is not pornographic at all and 10 is extremely pornographic.

@@ -92,0 +93,0 @@ ## Note

class Assistant {
private apiKey: string;
private apiUrl: string;
private apiModel: string;
constructor() {
this.apiKey = process.env.CLAUDE_API_KEY || '';
this.apiUrl = process.env.CLAUDE_API_URL || '';
this.apiUrl = process.env.CLAUDE_API_URL || 'https://api.anthropic.com/v1/messages';
this.apiModel = process.env.CLAUDE_API_MODEL || 'claude-3-haiku-20240307';
}

@@ -15,6 +17,8 @@

'Content-Type': 'application/json',
'Authorization': `Bearer ${this.apiKey}`,
'x-api-key': this.apiKey,
'anthropic-version': '2023-06-01',
},
body: JSON.stringify({
model: 'claude-3-opus-20240229',
model: this.apiModel,
max_tokens: 1024,
messages: [{ role: 'user', content: message }],

@@ -25,11 +29,14 @@ }),

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
throw new Error(`HTTP error! status: ${response.status}, response: \n${JSON.stringify(await response.json(), null, 2)}`);
}
const data = await response.json();
return data.choices[0].message.content;
return data.content[0].text;
}
public async translateText(text: string): Promise<string> {
const message = `Translate the following text to English: "${text}"`;
public async translateText(text: string, lang?: string, context?: string): Promise<string> {
const l = lang || 'English'
const c = !context ? '' : `(context: ${context})`;
const message = `Translate the following text ${c} to ${l}: "${text}"`;
return this.sendToClaude(message);

@@ -39,11 +46,11 @@ }

public async checkForOffensiveLanguage(text: string): Promise<number> {
const message = `Rate the level of offensiveness in the following text on a scale from 1 to 10: "${text}"`;
const message = `Rate (response only digit) the offensiveness of the following message on a scale from 1 to 10, where 1 is very peaceful and 10 is extremely aggressive: "${text}"`;
const response = await this.sendToClaude(message);
return parseInt(response) || 1;
return parseInt(response);
}
public async checkForProfanity(text: string): Promise<number> {
const message = `Rate the level of profanity in the following text on a scale from 1 to 10: "${text}"`;
const message = `Rate (response only digit) the level of profanity in the following message on a scale from 1 to 10, where 1 is very clean and 10 is extremely profane: "${text}"`;
const response = await this.sendToClaude(message);
return parseInt(response) || 1;
return parseInt(response);
}

@@ -53,3 +60,3 @@

const base64Image = imageBuffer.toString('base64');
const message = `Rate the level of violence in this image on a scale from 1 to 10: [IMAGE]${base64Image}[/IMAGE]`;
const message = `Rate (response only digit) the level of violence in the following image on a scale from 1 to 10, where 1 is very peaceful and 10 is extremely violent: [IMAGE]${base64Image}[/IMAGE]`;
const response = await this.sendToClaude(message);

@@ -61,3 +68,3 @@ return parseInt(response) || 1;

const base64Image = imageBuffer.toString('base64');
const message = `Rate the level of pornographic content in this image on a scale from 1 to 10: [IMAGE]${base64Image}[/IMAGE]`;
const message = `Rate (response only digit) the level of pornographic content in the following image on a scale from 1 to 10, where 1 is not pornographic at all and 10 is extremely pornographic: [IMAGE]${base64Image}[/IMAGE]`;
const response = await this.sendToClaude(message);

@@ -64,0 +71,0 @@ return parseInt(response) || 1;

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