Skip to content

Commit

Permalink
Merge pull request #41 from Barqawiz/candidate-1.3.5
Browse files Browse the repository at this point in the history
Candidate 1.3.7

- add support for llama-code and llama-python.
- upgrade the semantic search to support huge data memory search using `SemanticSearchPaging`.
- update the documentation.
  • Loading branch information
Barqawiz authored Aug 27, 2023
2 parents 6695270 + 2075362 commit 6fa6dfc
Show file tree
Hide file tree
Showing 16 changed files with 860 additions and 677 deletions.
9 changes: 6 additions & 3 deletions IntelliNode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
IntelliNode is the ultimate tool to integrate with the latest language models and deep learning frameworks using **javascript**. The library provides intuitive functions for sending input to models like ChatGPT, WaveNet and Stable diffusion, and receiving generated text, speech, or images. With just a few lines of code, you can easily access the power of cutting-edge AI models to enhance your projects.

# Latest Updates
- Update the chatbot to support Llama v2. 🦙
- Update the chatbot to support Llama v2 chat and code. 🦙
- Add Gen function, the fastest way to generate text, speech, web pages or images. :bullettrain_side:
- Update stable diffusion to use XL model engine.
- Add support for hugging face inference.
- Update chatGPT to support function calls, empowering automation.
- Generate prompt using LLM.
- Add support for huge data memory semantic search using `SemanticSearchPaging`.

Join the [discord server](https://discord.gg/VYgCh2p3Ww) for the latest updates and community support.

# Examples
## Functions
Expand Down Expand Up @@ -177,10 +179,11 @@ ProxyHelper.getInstance().setAzureOpenai(resourceName);
Check the code to access the chatbot through a proxy: [proxy chatbot](https://github.com/Barqawiz/IntelliNode/blob/main/samples/command_sample/test_chatbot_proxy.js)

# :closed_book: Documentation
- [IntelliNode Wiki](https://github.com/Barqawiz/IntelliNode/wiki): Check the wiki page for indepeth instructions and practical use cases.
- [IntelliNode Wiki](https://github.com/Barqawiz/IntelliNode/wiki): Check the wiki page for indepth instructions and practical use cases.
- [Showcase](https://show.intellinode.ai/): Experience the potential of Intellinode in action, and use your keys to generate content and html pages.
- [Samples](https://github.com/Barqawiz/IntelliNode/tree/main/samples/command_sample): Explore a code sample with detailed setup documentation to get started with Intellinode.
- [Model Evaluation](https://github.com/Barqawiz/IntelliNode/wiki/Model-Evaluation): Demonstrate a swift approach to compare the performance of multiple models against designated target answers.
- [Articles](https://www.intellinode.ai/articles): Tutorials and articles about intelliNode and data science topics.

# Pillars
- **The wrapper layer** provides low-level access to the latest AI models
Expand Down
8 changes: 7 additions & 1 deletion IntelliNode/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@
"13b": "13b-chat",
"70b-chat": "70b-chat",
"13b-chat": "13b-chat",
"34b-code": "34b-code",
"34b-python": "34b-python",
"13b-code-instruct": "13b-code-instruct",
"70b-chat-version": "2d19859030ff705a87c746f7e96eea03aefb71f166725aee39692f1476566d48",
"13b-chat-version": "d5da4236b006f967ceb7da037be9cfc3924b20d21fed88e1e94f19d56e2d3111"
"13b-chat-version": "d5da4236b006f967ceb7da037be9cfc3924b20d21fed88e1e94f19d56e2d3111",
"34b-code-version": "0666717e5ead8557dff55ee8f11924b5c0309f5f1ca52f64bb8eec405fdb38a7",
"34b-python-version": "9048743d22a7b19cd0abb018066809ea6af4f2b4717bef9aad3c5ae21ceac00d",
"13b-code-instruct-version":"da5676342de1a5a335b848383af297f592b816b950a43d251a0a9edd0113604b"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions IntelliNode/function/SemanticSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SemanticSearch {
}

async getTopMatches(pivotItem, searchArray, numberOfMatches) {

if (numberOfMatches > searchArray.length) {
throw new Error('numberOfMatches should not be greater than the searchArray');
}
Expand Down
37 changes: 37 additions & 0 deletions IntelliNode/function/SemanticSearchPaging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { SemanticSearch } = require('./SemanticSearch'); // assuming path

class SemanticSearchPaging extends SemanticSearch {
constructor(keyValue, provider, pivotItem, numberOfMatches) {
super(keyValue, provider);
this.pivotItem = pivotItem;
this.numberOfMatches = numberOfMatches;
this.textAndMatches = []; // To store { text: '...', similarity: 0.9 } results
this.topMatches = [];
}

async addNewData(newSearchItems) {
// get the best matches for new items
const newMatches = await super.getTopMatches(this.pivotItem, newSearchItems, newSearchItems.length);

// map the matches format
const newMatchesWithText = newMatches.map(match => ({
text: newSearchItems[match.index],
score: match.similarity,
}));

// combine with old top matches and sort
this.topMatches = [...this.topMatches, ...newMatchesWithText]
.sort((a, b) => b.score - a.score)
.slice(0, this.numberOfMatches);
}

getCurrentTopMatches() {
return this.topMatches;
}

clean() {
this.topMatches = [];
}
}

module.exports = { SemanticSearchPaging };
4 changes: 3 additions & 1 deletion IntelliNode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { RemoteEmbedModel, SupportedEmbedModels } = require('./controller/RemoteE
// functions
const { Chatbot, SupportedChatModels } = require('./function/Chatbot');
const { SemanticSearch } = require('./function/SemanticSearch');
const { SemanticSearchPaging } = require('./function/SemanticSearchPaging');
const { TextAnalyzer } = require('./function/TextAnalyzer');
const { Gen } = require('./function/Gen');

Expand Down Expand Up @@ -72,5 +73,6 @@ module.exports = {
AWSEndpointWrapper,
Prompt,
LLamaSageInput,
LLMEvaluation
LLMEvaluation,
SemanticSearchPaging
};
18 changes: 14 additions & 4 deletions IntelliNode/model/input/ChatModelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ class LLamaReplicateInput extends ChatLLamaInput {
options.model = options.model || config.getProperty('models.replicate.llama.13b');
options.version = options.version;
super(systemMessage, options);
this.top_k = options.top_k || null;
this.top_p = options.top_p || null;
this.min_new_tokens = options.min_new_tokens || null;
this.system_prompt = options.system_prompt || null;
this.repetition_penalty = options.repetition_penalty || null;
}

getChatInput() {
Expand All @@ -183,21 +188,26 @@ class LLamaReplicateInput extends ChatLLamaInput {
this.version = config.getProperty(`models.replicate.llama.${this.model}-version`);
}

return {
var myData = {
model: this.model,
inputData: {
version: this.version,
input: {
prompt: this.prompt,
system_prompt: this.system_prompt,
max_new_tokens: this.max_new_tokens,
temperature: this.temperature,
top_p: this.top_p,
repetition_penalty: this.repetition_penalty,
debug: this.debug
}
}
};

if (this.top_k) myData.inputData.input.top_k = this.top_k;
if (this.top_p) myData.inputData.input.top_p = this.top_p;
if (this.system_prompt) myData.inputData.input.system_prompt = this.system_prompt;
if (this.min_new_tokens) myData.inputData.input.min_new_tokens = this.min_new_tokens;
if (this.repetition_penalty) myData.inputData.input.repetition_penalty = this.repetition_penalty;

return myData;
}
}

Expand Down
4 changes: 2 additions & 2 deletions IntelliNode/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "intellinode",
"version": "1.3.4",
"version": "1.3.7",
"description": "Access various AI models, such as ChatGPT, Llama, Diffusion, Cohere, WaveNet, and others",
"main": "index.js",
"keywords": [
Expand All @@ -17,7 +17,7 @@
"prompt",
"automation"
],
"author": "Intellinode",
"author": "IntelliNode",
"license": "Apache",
"repository": {
"type": "git",
Expand Down
39 changes: 19 additions & 20 deletions IntelliNode/test/integration/Chatbot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,25 +121,6 @@ async function testReplicateLLamaCase1() {
}
}


async function testReplicateLLamaCase2() {
try {
console.log('\nLLama test case 2: \n')
const input = new LLamaReplicateInput("you are helpful assistant!");
input.addUserMessage("Explain the plot of the Inception movie");
input.addAssistantMessage("The plot of the movie Inception follows a skilled thief who enters people's dreams to steal their secrets and is tasked with implanting an idea into a target's mind to alter their future actions.");
input.addUserMessage("Explain the plot of the dark night movie");

const responses = await replicateBot.chat(input);

responses.forEach((response) => console.log("- " + response));

assert(responses.length > 0, "testReplicateLLamaCase1 response length should be greater than 0");
} catch (error) {
console.error("Test case failed with exception:", error.message);
}
}

async function testSageMakerLLamaCase() {
try {
console.log('\nLLama sagemaker test case 1: \n')
Expand All @@ -161,6 +142,23 @@ async function testSageMakerLLamaCase() {

}

async function testReplicateLLamaCase3() {
try {
console.log('\nLLama test case 3: \n')
const input = new LLamaReplicateInput("you are helpful coding assistant!",
{model: '34b-code'});
input.addUserMessage("how to develop micro service using node js");

const responses = await replicateBot.chat(input);

responses.forEach((response) => console.log("- " + response));

assert(responses.length > 0, "testReplicateLLamaCase1 response length should be greater than 0");
} catch (error) {
console.error("Test case failed with exception:", error.message);
}
}

(async () => {
console.log('### Openai model ###')
await testOpenaiChatGPTCase1();
Expand All @@ -170,8 +168,9 @@ async function testSageMakerLLamaCase() {
console.log('### Replicate llama model ###')
await testReplicateLLamaCase1();
await testReplicateLLamaCase2();
await testReplicateLLamaCase3();

console.log('### SageMaker llama model ###')
await testSageMakerLLamaCase();
//await testSageMakerLLamaCase();

})();
44 changes: 44 additions & 0 deletions IntelliNode/test/integration/LLamav2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,51 @@ async function testReplicateWrapperLLama() {
}
}


async function testReplicateLLamaCoder() {
try {

const modelName = config.getProperty('models.replicate.llama.34b-python');
const version = config.getProperty('models.replicate.llama.34b-python-version');
const inputData = { version: version,
input: { prompt: '# function that adds 2 number inputs.',
max_new_tokens: 128,
top_k: 50,
top_p: 0.9,
temperature: 0.1,
min_new_tokens: -1,
debug: false,
stop_sequences: '<end>'} };

const prediction = await replicateWrapper.predict(modelName, inputData);

// check for the response every second
const poll = setInterval(async () => {
const status = await replicateWrapper.getPredictionStatus(prediction.id);

console.log('the current status: ', status.status)

if (status.status === 'succeeded' || status.status === 'failed') {
clearInterval(poll); // stop polling if prediction has completed or failed

if (status.status === 'succeeded') {
console.log('LLama Predict Result:', status.output.join(''));
} else {
console.error('LLama Prediction Failed:', status.error);
}
}
}, 1000);

} catch (error) {
console.error('LLama Error:', error);
}
}

(async () => {
// test LLama v2 from Replicate host
await testReplicateWrapperLLama();

// test LLama v2 coder
await testReplicateLLamaCoder();

})();
38 changes: 38 additions & 0 deletions IntelliNode/test/integration/SemanticSearchPaging.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require('dotenv').config();
const assert = require('assert');
const { SemanticSearchPaging } = require('../../function/SemanticSearchPaging');
const { SupportedEmbedModels } = require('../../controller/RemoteEmbedModel');

const openaiApiKey = process.env.OPENAI_API_KEY;
const cohereApiKey = process.env.COHERE_API_KEY;

const pivotItem = 'Hello from IntelliNode';

const openaiSemanticSearch = new SemanticSearchPaging(openaiApiKey,
SupportedEmbedModels.OPENAI,
pivotItem, 2);
const cohereSemanticSearch = new SemanticSearchPaging(cohereApiKey,
SupportedEmbedModels.COHERE,
pivotItem, 2);

async function addToSessionAndTest(semanticSearch, newSearchItems) {

await semanticSearch.addNewData( newSearchItems);
const results = semanticSearch.getCurrentTopMatches();

console.log('Semantic Search Session Results:', results);
assert(results.length <= semanticSearch.numberOfMatches, 'Test passed');
}

(async () => {

// semantic search with openai embedding
await addToSessionAndTest(openaiSemanticSearch, ['Greetings from IntelliNode!', 'Saluti da IntelliNode!']);
await addToSessionAndTest(openaiSemanticSearch, ['Hola desde IntelliNode!', 'Bonjour de IntelliNode!']);

openaiSemanticSearch.clean();

// semantic search with cohere embedding
await addToSessionAndTest(cohereSemanticSearch, ['Greetings from IntelliNode!', 'Bonjour de IntelliNode!']);
await addToSessionAndTest(cohereSemanticSearch, ['Hola desde IntelliNode!', 'Saluti da IntelliNode!']);
})();
2 changes: 1 addition & 1 deletion IntelliNode/wrappers/ReplicateWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ReplicateWrapper {
});
}

async predict(modelVersion, inputData) {
async predict(modelTag, inputData) {
const url = config.getProperty('url.replicate.predictions');
const data = inputData;

Expand Down
17 changes: 10 additions & 7 deletions samples/command_sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The Llama model is made available by several hosting services, and Replicate is

## Samples Execution

1. E-commerce sample to generate products description and images:
1. E-commerce sample to product descriptions description and images:
`node ecommerce_tool.js`

2. Language model using openai and cohere:
Expand All @@ -46,22 +46,25 @@ The Llama model is made available by several hosting services, and Replicate is
7. Semantic search:
`node test_semantic_search.js`

8. Text analyzer (summary & sentiment analysis):
8. Semantic search pagination to work with huge data:
`node test_semantic_search.js`

9. Text analyzer (summary & sentiment analysis):
`node test_text_analyzer.js`

9. Huggingface simplified inference access:
10. Huggingface simplified inference access:
`node test_hugging_face.js`

10. Azure openai sample
11. Azure openai sample
`node test_azure_chatbot.js <resource_name> <deployment_name>`

11. Automation sample using the chatbot function call:
12. Automation sample using the chatbot code call, it works by providing the model with your function details, and it decides to execute the code based on the user conversation:
`node automate_s3_bucket.js`

12. Llama V2 chatbot:
13. Llama V2 chatbot:
`node test_llama_chatbot.js`

13. LLM evaluator to compare models like chatGPT, Cohere, and Llama:
14. LLM evaluator to compare models like chatGPT, Cohere, and Llama:
`node test_llm_evaluation.test.js`


Expand Down
Loading

0 comments on commit 6fa6dfc

Please sign in to comment.