Skip to content

Commit

Permalink
Merge pull request #24 from Barqawiz/test-scripts
Browse files Browse the repository at this point in the history
Test scripts, security fixes and release version
  • Loading branch information
Barqawiz authored Jun 19, 2023
2 parents d0235e8 + 84db2b3 commit 404cbd7
Show file tree
Hide file tree
Showing 26 changed files with 258 additions and 35 deletions.
2 changes: 1 addition & 1 deletion IntelliNode/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
node_modules
.idea
dist
test/
test/integration/
2 changes: 1 addition & 1 deletion IntelliNode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ ProxyHelper.getInstance().setAzureOpenai(resourceName);
- **The function layer** provides abstract functionality that extends based on the app's use cases. For example, an easy-to-use chatbot or marketing content generation utilities.

# License
Apache 2.0 License
Apache License

Copyright 2023 Github.com/Barqawiz/IntelliNode

Expand Down
7 changes: 5 additions & 2 deletions IntelliNode/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"name": "intellinode",
"version": "0.0.38",
"version": "1.0.0",
"description": "Access various AI models, such as ChatGPT, Diffusion, Cohere, Google, and others",
"main": "index.js",
"keywords": ["AI", "ChatGPT", "GPT4", "stable diffusion", "openai", "huggingface", "language models", "image generation", "speech synthesis", "semantic search"],
"author": "Ahmad Albarqawi",
"license": "Apache 2.0",
"license": "Apache",
"repository": {
"type": "git",
"url": "git+https://github.com/Barqawiz/IntelliNode.git"
},
"scripts": {
"test": "node test/unit/testRunner"
},
"homepage": "https://intellinode.ai",
"dependencies": {
"axios": "^1.3.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('dotenv').config();
const assert = require('assert');
const OpenAIWrapper = require('../wrappers/OpenAIWrapper');
const proxyHelper = require('../utils/ProxyHelper').getInstance();
const OpenAIWrapper = require('../../wrappers/OpenAIWrapper');
const proxyHelper = require('../../utils/ProxyHelper').getInstance();
let openAI = null;

async function testLanguageModel() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require("dotenv").config();
const assert = require("assert");
const { Chatbot, SupportedChatModels } = require("../function/Chatbot");
const { ChatGPTInput, ChatGPTMessage } = require("../model/input/ChatModelInput");
const { Chatbot, SupportedChatModels } = require("../../function/Chatbot");
const { ChatGPTInput, ChatGPTMessage } = require("../../model/input/ChatModelInput");

const apiKey = process.env.OPENAI_API_KEY;
const bot = new Chatbot(apiKey, SupportedChatModels.OPENAI);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require('dotenv').config();
const assert = require('assert');
const CohereAIWrapper = require('../wrappers/CohereAIWrapper');
const CohereAIWrapper = require('../../wrappers/CohereAIWrapper');

const cohere = new CohereAIWrapper(process.env.COHERE_API_KEY);

Expand Down
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require('dotenv').config();
const GoogleAIWrapper = require('../wrappers/GoogleAIWrapper');
const GoogleAIWrapper = require('../../wrappers/GoogleAIWrapper');

const googleAI = new GoogleAIWrapper(process.env.GOOGLE_API_KEY);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require('dotenv').config();
const HuggingWrapper = require('../wrappers/HuggingWrapper');
const HuggingWrapper = require('../../wrappers/HuggingWrapper');

const huggingWrapper = new HuggingWrapper(process.env.HUGGING_API_KEY);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const LanguageModelInput = require("../model/input/LanguageModelInput");
const LanguageModelInput = require("../../model/input/LanguageModelInput");

function testOpenAIInputs() {
const input = new LanguageModelInput({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('dotenv').config();
const assert = require('assert');
const OpenAIWrapper = require('../wrappers/OpenAIWrapper');
const proxyHelper = require('../utils/ProxyHelper').getInstance();
const OpenAIWrapper = require('../../wrappers/OpenAIWrapper');
const proxyHelper = require('../../utils/ProxyHelper').getInstance();

const openAI = new OpenAIWrapper(process.env.OPENAI_API_KEY);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('dotenv').config();
const assert = require('assert');
const { RemoteEmbedModel, SupportedEmbedModels } = require('../controller/RemoteEmbedModel');
const EmbedInput = require('../model/input/EmbedInput');
const { RemoteEmbedModel, SupportedEmbedModels } = require('../../controller/RemoteEmbedModel');
const EmbedInput = require('../../model/input/EmbedInput');

const openaiApiKey = process.env.OPENAI_API_KEY;
const cohereApiKey = process.env.COHERE_API_KEY;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = require("assert");
const { RemoteImageModel } = require("../controller/RemoteImageModel");
const ImageModelInput = require("../model/input/ImageModelInput");
const { RemoteImageModel } = require("../../controller/RemoteImageModel");
const ImageModelInput = require("../../model/input/ImageModelInput");

require("dotenv").config();
const openaiKey = process.env.OPENAI_API_KEY;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('dotenv').config();
const assert = require('assert');
const { RemoteLanguageModel, SupportedLangModels } = require('../controller/RemoteLanguageModel');
const LanguageModelInput = require('../model/input/LanguageModelInput');
const { RemoteLanguageModel, SupportedLangModels } = require('../../controller/RemoteLanguageModel');
const LanguageModelInput = require('../../model/input/LanguageModelInput');

const openaiApiKey = process.env.OPENAI_API_KEY;
const cohereApiKey = process.env.COHERE_API_KEY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const fs = require('fs');
require('dotenv').config();
const assert = require('assert');
const { RemoteSpeechModel, SupportedSpeechModels } = require('../controller/RemoteSpeechModel');
const Text2SpeechInput = require('../model/input/Text2SpeechInput');
const AudioHelper = require('../utils/AudioHelper');
const Text2SpeechInput = require('../../model/input/Text2SpeechInput');
const AudioHelper = require('../../utils/AudioHelper');

const remoteSpeechModel = new RemoteSpeechModel(process.env.GOOGLE_API_KEY, SupportedSpeechModels.GOOGLE);
const audioHelper = new AudioHelper();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('dotenv').config();
const assert = require('assert');
const SemanticSearch = require('../function/SemanticSearch');
const { SupportedEmbedModels } = require('../controller/RemoteEmbedModel');
const SemanticSearch = require('../../function/SemanticSearch');
const { SupportedEmbedModels } = require('../../controller/RemoteEmbedModel');

const openaiApiKey = process.env.OPENAI_API_KEY;
const cohereApiKey = process.env.COHERE_API_KEY;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require("dotenv").config();
const StabilityAIWrapper = require("../wrappers/StabilityAIWrapper");
const ImageModelInput = require("../model/input/ImageModelInput");
const StabilityAIWrapper = require("../../wrappers/StabilityAIWrapper");
const ImageModelInput = require("../../model/input/ImageModelInput");
const fs = require('fs');
const stabilityAI = new StabilityAIWrapper(process.env.STABILITY_API_KEY);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('dotenv').config();
const assert = require('assert');
const { TextAnalyzer } = require('../function/TextAnalyzer');
const { SupportedLangModels } = require('../controller/RemoteLanguageModel');
const { TextAnalyzer } = require('../../function/TextAnalyzer');
const { SupportedLangModels } = require('../../controller/RemoteLanguageModel');

const openaiApiKey = process.env.OPENAI_API_KEY;
const cohereApiKey = process.env.COHERE_API_KEY;
Expand Down
40 changes: 40 additions & 0 deletions IntelliNode/test/unit/CohereAIWrapper.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const assert = require('assert');
const CohereAIWrapper = require('../../wrappers/CohereAIWrapper');
const config = require('../../utils/Config2').getInstance();

function testCohereAIWrapper() {
const apiKey = 'your-api-key';
const cohereAIWrapper = new CohereAIWrapper(apiKey);

assert.strictEqual(cohereAIWrapper.API_KEY, apiKey, 'API key should be set');
assert.ok(cohereAIWrapper.httpClient, 'httpClient should be created');

// Test httpClient configuration
const expectedBaseURL = config.getProperty('url.cohere.base');
const expectedCohereVersion = config.getProperty('url.cohere.version');
const expectedContentType = 'application/json';
const expectedAuthHeader = `Bearer ${apiKey}`;

assert.strictEqual(
cohereAIWrapper.httpClient.defaults.baseURL,
expectedBaseURL,
'httpClient baseURL should be set correctly'
);
assert.strictEqual(
cohereAIWrapper.httpClient.defaults.headers['Content-Type'],
expectedContentType,
'httpClient Content-Type header should be set correctly'
);
assert.strictEqual(
cohereAIWrapper.httpClient.defaults.headers['Authorization'],
expectedAuthHeader,
'httpClient Authorization header should be set correctly'
);
assert.strictEqual(
cohereAIWrapper.httpClient.defaults.headers['Cohere-Version'],
expectedCohereVersion,
'httpClient Cohere-Version header should be set correctly'
);
}

module.exports = testCohereAIWrapper;
62 changes: 62 additions & 0 deletions IntelliNode/test/unit/GoogleAIWrapper.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const assert = require('assert');
const GoogleAIWrapper = require('../../wrappers/GoogleAIWrapper');
const config = require('../../utils/Config2').getInstance();

function testGoogleAIWrapper() {
const apiKey = 'your-api-key';
const googleAIWrapper = new GoogleAIWrapper(apiKey);

assert.strictEqual(googleAIWrapper.API_KEY, apiKey, 'API key should be set');
assert.ok(googleAIWrapper.httpClient, 'httpClient should be created');

// Test httpClient configuration
const expectedBaseURL = config
.getProperty('url.google.base')
.replace('{1}', config.getProperty('url.google.speech.prefix'));
const expectedContentType = 'application/json; charset=utf-8';

assert.strictEqual(
googleAIWrapper.httpClient.defaults.baseURL,
expectedBaseURL,
'httpClient baseURL should be set correctly'
);
assert.strictEqual(
googleAIWrapper.httpClient.defaults.headers['Content-Type'],
expectedContentType,
'httpClient Content-Type header should be set correctly'
);
assert.strictEqual(
googleAIWrapper.httpClient.defaults.headers['X-Goog-Api-Key'],
apiKey,
'httpClient X-Goog-Api-Key header should be set correctly'
);

// Test getSynthesizeInput() method
const params = {
text: 'Hello world',
languageCode: 'en-US',
name: 'en-US-Wavenet-A',
ssmlGender: 'MALE',
};
const expectedModelInput = JSON.stringify({
input: {
text: params.text,
},
voice: {
languageCode: params.languageCode,
name: params.name,
ssmlGender: params.ssmlGender,
},
audioConfig: {
audioEncoding: 'MP3',
},
});

assert.strictEqual(
googleAIWrapper.getSynthesizeInput(params),
expectedModelInput,
'getSynthesizeInput() should return the correct model input as a JSON string'
);
}

module.exports = testGoogleAIWrapper;
34 changes: 34 additions & 0 deletions IntelliNode/test/unit/HuggingWrapper.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const assert = require('assert');
const HuggingWrapper = require('../../wrappers/HuggingWrapper');
const config = require('../../utils/Config2').getInstance();

function testHuggingWrapper() {
const apiKey = 'your-api-key';
const huggingWrapper = new HuggingWrapper(apiKey);

assert.strictEqual(huggingWrapper.API_KEY, apiKey, 'API key should be set');
assert.ok(huggingWrapper.httpClient, 'httpClient should be created');

// Test httpClient configuration
const expectedBaseURL = config.getProperty('url.huggingface.base');
const expectedContentType = 'application/json';
const expectedAuthHeader = `Bearer ${apiKey}`;

assert.strictEqual(
huggingWrapper.httpClient.defaults.baseURL,
expectedBaseURL,
'httpClient baseURL should be set correctly'
);
assert.strictEqual(
huggingWrapper.httpClient.defaults.headers['Content-Type'],
expectedContentType,
'httpClient Content-Type header should be set correctly'
);
assert.strictEqual(
huggingWrapper.httpClient.defaults.headers['Authorization'],
expectedAuthHeader,
'httpClient Authorization header should be set correctly'
);
}

module.exports = testHuggingWrapper;
36 changes: 36 additions & 0 deletions IntelliNode/test/unit/OpenAIWrapper.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const assert = require('assert');
const OpenAIWrapper = require('../../wrappers/OpenAIWrapper');
const ProxyHelper = require('../../utils/ProxyHelper');
const config = require('../../utils/Config2').getInstance();

function testOpenAIWrapper() {
const apiKey = 'your-api-key';
const proxyHelper = ProxyHelper.getInstance();
const openAIWrapper = new OpenAIWrapper(apiKey);

assert.strictEqual(openAIWrapper.API_KEY, apiKey, 'API key should be set');
assert.ok(openAIWrapper.httpClient, 'httpClient should be created');

// Test httpClient configuration
const expectedBaseURL = proxyHelper.getOpenaiURL();
const expectedContentType = 'application/json';
const expectedAuthHeader = `Bearer ${apiKey}`;

assert.strictEqual(
openAIWrapper.httpClient.defaults.baseURL,
expectedBaseURL,
'httpClient baseURL should be set correctly'
);
assert.strictEqual(
openAIWrapper.httpClient.defaults.headers['Content-Type'],
expectedContentType,
'httpClient Content-Type header should be set correctly'
);
assert.strictEqual(
openAIWrapper.httpClient.defaults.headers['Authorization'],
expectedAuthHeader,
'httpClient Authorization header should be set correctly'
);
}

module.exports = testOpenAIWrapper;
28 changes: 28 additions & 0 deletions IntelliNode/test/unit/StabilityAIWrapper.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const assert = require('assert');
const StabilityAIWrapper = require('../../wrappers/StabilityAIWrapper');
const config = require('../../utils/Config2').getInstance();

function testStabilityAIWrapper() {
const apiKey = 'your-api-key';
const stabilityAIWrapper = new StabilityAIWrapper(apiKey);

assert.strictEqual(stabilityAIWrapper.API_KEY, apiKey, 'API key should be set');
assert.ok(stabilityAIWrapper.httpClient, 'httpClient should be created');

// Test httpClient configuration
const expectedBaseURL = config.getProperty('url.stability.base');
const expectedAuthHeader = `Bearer ${apiKey}`;

assert.strictEqual(
stabilityAIWrapper.httpClient.defaults.baseURL,
expectedBaseURL,
'httpClient baseURL should be set correctly'
);
assert.strictEqual(
stabilityAIWrapper.httpClient.defaults.headers['Authorization'],
expectedAuthHeader,
'httpClient Authorization header should be set correctly'
);
}

module.exports = testStabilityAIWrapper;
Loading

0 comments on commit 404cbd7

Please sign in to comment.