Add files via upload

This commit is contained in:
The Ghost of FOSS' Future 2024-08-22 20:36:49 +00:00 committed by GitHub
parent b5ba807c48
commit bf019c0f77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 135 additions and 149 deletions

39
LICENSE
View file

@ -1,19 +1,20 @@
The Samuel Public License Revision 5 (SPL-R5) The Sammy Public License Revision 5 Sub-Revision 1 (SPL-R5 SR1)
Copyright (c) 2024 Sneed Group Copyright (c) 2024 Sneed Group
This document grants permission, without charge, to any individual acquiring a copy of the software and its associated documentation files (hereinafter referred to as the "Software"). Such individuals are authorized to engage in activities related to the Software with certain restrictions (listed below), including, but not limited to, the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software. These permissions extend to persons to whom the Software is furnished, subject to compliance with the specified conditions outlined below. This document grants permission, without charge, to any individual acquiring a copy of the software and its associated documentation files (hereinafter referred to as the "Software"). Such individuals are authorized to engage in activities related to the Software with certain restrictions (listed below), including, but not limited to, the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software. These permissions extend to persons to whom the Software is furnished, subject to compliance with the specified conditions outlined below.
THE SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
In making contributions to the Software, contributors irrevocably assign, transfer, and convey all rights, titles, and interests in and to their contributions to the project owner(s). This assignment is absolute and encompasses all intellectual property rights, including, but not limited to, copyrights, patents, trademarks, and trade secrets. Contributors acknowledge and consent that they have no further claim, right, or interest in their contributions and agree to relinquish any moral rights associated with the contributed content. This assignment is effective upon the act of contributing to the Software, and contributors affirm that they have the authority to make such an assignment. However, contributors retain the right to modify their contributions. In making contributions to the Software, contributors irrevocably assign, transfer, and convey all rights, titles, and interests in and to their contributions to the project owner(s). This assignment is absolute and encompasses all intellectual property rights, including, but not limited to, copyrights, patents, trademarks, and trade secrets. Contributors acknowledge and consent that they have no further claim, right, or interest in their contributions and agree to relinquish any moral rights associated with the contributed content. This assignment is effective upon the act of contributing to the Software, and contributors affirm that they have the authority to make such an assignment. However, contributors retain the right to modify their contributions.
Furthermore, this document permits the reuse and redistribution of both executable binaries and source code, contingent upon the inclusion of the previously mentioned copyright notice and permission notice in all copies or substantial portions of the Software. It is imperative that you explicitly acknowledge and agree that the owner(s) retain ownership rights over the aforementioned source code. Furthermore, this document permits the reuse and redistribution of both executable binaries and source code, contingent upon the inclusion of the previously mentioned copyright notice and permission notice in all copies or substantial portions of the Software. It is imperative that you explicitly acknowledge and agree that the owner(s) retain ownership rights over the aforementioned source code.
Moreover, companies using the Software are encouraged to contribute upstream. Fortune 500 companies are required to make an annual contribution of at least 20,000 USD or an equivalent amount to support the project's sustainability unless no donation option is provided. Moreover, companies using the Software are encouraged to contribute upstream. Fortune 500 companies are required to make an annual contribution of at least 20,000 USD or an equivalent amount per project used to support the said projects' sustainability unless no donation option is provided. Also, all Fortune 500 companies using said projects are required to contibute their changes upstream as well.
Additionally, note that the use of AI-assisted tools, including but not limited to GitHub Copilot and ChatGPT, is expressly permitted in conjunction with this software. Users are encouraged to leverage these AI tools to enhance their experience in developing, modifying, and interacting with the Software. The permission granted herein extends to the integration and utilization of AI-generated content for coding and communication purposes. The owners(s) of the Software acknowledge and embrace the collaborative nature of AI-assisted development. Additionally, note that the use of AI-assisted tools, including but not limited to GitHub Copilot and ChatGPT, is expressly permitted in conjunction with this software. Users are encouraged to leverage these AI tools to enhance their experience in developing, modifying, and interacting with the Software. The permission granted herein extends to the integration and utilization of AI-generated content for coding and communication purposes. The owners(s) of the Software acknowledge and embrace the collaborative nature of AI-assisted development.
In addition, the owner of the code is granted the authority to update their copy of The Samuel Public License (SPL) to the latest revision. This update may be undertaken at the discretion of the owner to ensure alignment with any subsequent revisions made to The Samuel Public License. In addition, the owner of the code is granted the authority to update their copy of The Samuel Public License (SPL) to the latest revision. This update may be undertaken at the discretion of the owner to ensure alignment with any subsequent revisions made to The Samuel Public License.
The aforementioned copyright notice and this permission notice must be included in all copies or substantial portions of the Software. The aforementioned copyright notice and this permission notice must be included in all copies or substantial portions of the Software.

204
index.mjs
View file

@ -1,119 +1,95 @@
import readline from 'readline'; import { Ollama } from "@langchain/ollama";
import Ollama from 'ollama-js-client'; import { PuppeteerWebBaseLoader } from "@langchain/community/document_loaders/web/puppeteer";
import fs from 'fs'; import * as path from 'path'
import http from 'http';
import { URL } from 'url';
const debugMode = false
const __dirname = path.resolve();
let DEBUG_MODE = true; function llamaLoader(model="sparksammy/samantha-3.1", url="http://localhost:11434") {
return new Ollama({
async function ollamaInteraction() { baseUrl: url, // Default value
const rl = await readline.createInterface({ model: model, // Default value
input: process.stdin,
output: process.stdout,
});
function isUndefined(value) {
if (typeof value == undefined || value == null) {
return true;
} else {
return false;
}
}
function ifUndefinedReturnBlankStr(value) {
if (isUndefined(value)) {
return "";
} else {
return value;
}
}
function ifUndefinedReturnBlankFunction(value) {
if (isUndefined(value)) {
return Function();
} else {
return value;
}
}
function extractFunctionName(response) {
const match = response.match(/<functioncall>([^<]+)<\/functioncall>/);
return match ? match[1] : '';
}
function generateRandomString(length = 16) {
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return result;
}
// INTERNAL FUNCTIONS MAGIC BEGIN
let internalFunctions = {
jitsi: function() {
const id = generateRandomString();
const jitsiURL = `https://meet.jit.si/${id}`;
console.log(jitsiURL);
return jitsiURL;
},
search: function(q) {
q = q.replaceAll(" ", "+");
const searchURL = `https://www.google.com/search?q=${q}&sca_upv=1`;
console.log(searchURL);
return searchURL;
}
};
// END OF INTERNAL FUNCTIONS MAGIC
return new Promise(async (resolve) => {
rl.question("User: ", async (userInput) => {
rl.close();
const ollama = new Ollama({
model: "sneedgroup-llama3-agent",
url: "http://127.0.0.1:11434/api/",
}); // Ensure the model name is correct
const responsePreParse = await ollama.prompt(userInput);
const response = responsePreParse.response;
const functionName = extractFunctionName(response).replaceAll("\n", '');
const responseWithoutFunctionCall = await response.replace(/<functioncall>.*?<\/functioncall>/, '');
console.log(responseWithoutFunctionCall);
let contentToAppend = `<USER>: ${userInput}
<AI AGENT>: ${responseWithoutFunctionCall}`;
await fs.appendFile('journal.txt', contentToAppend, async (err) => {
if (err) {
await console.error(err);
} else {
await console.log('Content appended to journal file successfully!');
}
});
if (DEBUG_MODE) { console.log(`DEBUG: RUN ${functionName}`); }
// Call the function by name if it exists in internalFunctions
try {
if (DEBUG_MODE) { console.log(`DEBUG: ${functionName} => internalFunctions[${(functionName)})];`) }
internalFunctions[functionName]();
console.log("OK")
} catch (err) {
if (DEBUG_MODE) { console.log(`Error: ${err}`) }
}
resolve(); // Resolve the promise after processing
});
}); });
} }
(async () => { const ollama = llamaLoader()
while (true) {
try {
await ollamaInteraction();
} catch (error) { async function loadDoc(www) {
console.error('Error occurred:', error); try {
} const loader = new PuppeteerWebBaseLoader(String(www), {
launchOptions: {
headless: true,
},
gotoOptions: {
waitUntil: "domcontentloaded",
},
});
const docs = await loader.load();
return docs[0].pageContent;
} catch {
return ""
} }
})(); }
async function getReply(q, www='docChatterThing.testfile.invalid') {
let document
let query
if (www == "docChatterThing.testfile.invalid" || www == "") {
document = "Chatting."
} else {
document = await loadDoc(www)
}
query = String(`Context: ${document} Query: ${q}`)
if (debugMode) {
console.log(query) //Debug feature that prints out the user's query.
}
const stream = await ollama.stream(
query
);
const chunks = [];
for await (const chunk of stream) {
chunks.push(chunk);
}
return chunks.join("");
}
async function main(port) {
const hostname = '127.0.0.1';
const server = http.createServer((req, res) => {
res.statusCode = 200;
// Create URL object and parse query parameters
const urlObj = new URL(req.url, `http://${req.headers.host}`);
const queryParams = urlObj.searchParams;
// Get query parameters with default values if not provided
const q = queryParams.get('q') || "Create an error 500 message explaining that the user didn't input a query and optionally a URL.";
const www = queryParams.get('www') || "docChatterThing.testfile.invalid";
// Get reply and send response
getReply(q, www).then(answer => {
res.setHeader('Content-Type', 'text/plain');
res.end(String(answer));
}).catch(err => {
res.statusCode = 500;
res.end(`Internal Server Error: ${err.message}`);
});
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
}
main(8543)

View file

@ -1,16 +1,25 @@
{ {
"name": "sneedgroup-agent", "dependencies": {
"version": "1.0.0", "@langchain/community": "^0.2.28",
"description": "", "@langchain/ollama": "^0.0.4",
"main": "index.mjs", "cheerio": "^1.0.0",
"scripts": { "puppeteer": "^23.1.1"
"test": "echo \"Error: no test specified\" && exit 1" },
}, "name": "sneed-agent",
"author": "Samuel Lord", "version": "1.0.0",
"license": "SEE LICENSE IN LICENSE", "description": "Sneed Agent",
"dependencies": { "main": "index.mjs",
"ollama": "^0.5.0", "scripts": {
"ollama-js-client": "^1.0.1", "test": "echo \"Error: no test specified\" && exit 1"
"readline": "^1.3.0" },
} "repository": {
} "type": "git",
"url": "git+https://github.com/sneed-group/sneed-agent.git"
},
"author": "Sneed Group",
"license": "SEE LICENSE IN LICENSE",
"bugs": {
"url": "https://github.com/sneed-group/sneed-agent/issues"
},
"homepage": "https://github.com/sneed-group/sneed-agent#readme"
}