new file: .vscode/launch.json
modified: custom_models/qwen/Modelfile new file: newver.js modified: package.json
This commit is contained in:
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Launch Program",
|
||||||
|
"skipFiles": ["<node_internals>/**"],
|
||||||
|
"program": "${workspaceFolder}\\newver.js"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#FROM qwen2.5:7b
|
FROM qwen2.5:7b
|
||||||
FROM qwen2.5:3b
|
#FROM qwen2.5:3b
|
||||||
|
|
||||||
SYSTEM """
|
SYSTEM """
|
||||||
Your name is Nyamma.
|
Your name is Nyamma.
|
||||||
|
|||||||
187
newver.js
Normal file
187
newver.js
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
const { Webhook } = require('discord-webhook-node');
|
||||||
|
const readline = require("readline");
|
||||||
|
const { Ollama } = require("ollama");
|
||||||
|
const fs = require('fs');
|
||||||
|
const util = require("util");
|
||||||
|
|
||||||
|
const modelName = "qwen-modded";
|
||||||
|
const sessionName = modelName//+ "_" + (Math.floor(new Date().getTime() / 1000)).toString();
|
||||||
|
|
||||||
|
const messageHistory = [];
|
||||||
|
|
||||||
|
const ollama = new Ollama({ host: "http://127.0.0.1:11434" });
|
||||||
|
const discordHook = new Webhook("https://discord.com/api/webhooks/1328616300544786444/oCwaJ1HQW_Hk0_BQB6lWfuLSikhGOzEJqaOr37MNb6lkICk0Bllk7izVPdmXHKm1JhAN");
|
||||||
|
|
||||||
|
function directAnswer(args) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function discordMessage(args) {
|
||||||
|
try {
|
||||||
|
discordHook.setUsername("@Nyamma");
|
||||||
|
discordHook.send(args.message.toString());
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
return "Message sent successfully!";
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRandomCharacter(args) {
|
||||||
|
return "miku"
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRandomQuote(args) {
|
||||||
|
return "Cerber is cute pass it on -twitch chat"
|
||||||
|
}
|
||||||
|
|
||||||
|
const availableFunctions = {
|
||||||
|
directAnswer: directAnswer,
|
||||||
|
sendMessage: discordMessage,
|
||||||
|
getRandomCharacter: getRandomCharacter,
|
||||||
|
getRandomQuote: getRandomQuote
|
||||||
|
}
|
||||||
|
|
||||||
|
const availableTools = [
|
||||||
|
{
|
||||||
|
type: 'function',
|
||||||
|
function: {
|
||||||
|
name: 'directAnswer',
|
||||||
|
description: 'When no tool is required, use this function to copy your answer.',
|
||||||
|
parameters: {
|
||||||
|
type: 'object',
|
||||||
|
required: ['answer'],
|
||||||
|
properties: {
|
||||||
|
answer: { type: 'string', description: 'Your answer' },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'function',
|
||||||
|
function: {
|
||||||
|
name: 'sendMessage',
|
||||||
|
description: 'Send a message via discord to @shironeko.',
|
||||||
|
parameters: {
|
||||||
|
type: 'object',
|
||||||
|
required: ['message'],
|
||||||
|
properties: {
|
||||||
|
message: { type: 'string', description: 'Message contents.' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'function',
|
||||||
|
function: {
|
||||||
|
name: 'getRandomCharacter',
|
||||||
|
description: 'Gets random anime characters from randomCharacter.org, max 1.',
|
||||||
|
parameters: {
|
||||||
|
type: 'object',
|
||||||
|
required: ['amount'],
|
||||||
|
properties: {
|
||||||
|
amount: { type: 'string', description: 'Amount of characters to generate.' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'function',
|
||||||
|
function: {
|
||||||
|
name: 'getRandomQuote',
|
||||||
|
description: 'Gets random quotes from randomQuotes.org, max 1.',
|
||||||
|
parameters: {
|
||||||
|
type: 'object',
|
||||||
|
required: ['amount'],
|
||||||
|
properties: {
|
||||||
|
amount: { type: 'string', description: 'Amount of quotes to get.' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
async function getUserInput() {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const rl = readline.createInterface({
|
||||||
|
input: process.stdin,
|
||||||
|
output: process.stdout
|
||||||
|
});
|
||||||
|
rl.question("User: ", (input) => {
|
||||||
|
rl.close();
|
||||||
|
resolve(input);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveSessionData(messages) {
|
||||||
|
const jsonData = JSON.stringify({ messageList: messages }, null, 2);
|
||||||
|
|
||||||
|
fs.writeFile(`sessions/${sessionName}.json`, jsonData, "utf8", (err) => {
|
||||||
|
if (err) {
|
||||||
|
console.error("Error writing to file:", err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleToolCall(toolCalls) {
|
||||||
|
for (const tool of toolCalls) {
|
||||||
|
const { name, arguments: args } = tool.function;
|
||||||
|
const functionToCall = availableFunctions[name];
|
||||||
|
|
||||||
|
if (!functionToCall) {
|
||||||
|
console.error(`Tool "${name}" not found.`);
|
||||||
|
messageHistory.push({ role: "tool", content: `Tool "${name}" not recognized.` });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const output = await functionToCall(args);
|
||||||
|
console.log(`Calling function: ${name}`);
|
||||||
|
console.log(`Arguments:`, args);
|
||||||
|
console.log(`Function output: ${output}`);
|
||||||
|
messageHistory.push({ role: "tool", content: output.toString() });
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error executing tool "${name}":`, error);
|
||||||
|
messageHistory.push({ role: "tool", content: `Error executing tool "${name}".` });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function askForTool(params) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runModel() {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
const userMessage = await getUserInput();
|
||||||
|
messageHistory.push({ role: "user", content: userMessage });
|
||||||
|
|
||||||
|
const response = await ollama.chat({
|
||||||
|
model: modelName,
|
||||||
|
messages: messageHistory,
|
||||||
|
tools: availableTools
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.message.tool_calls) {
|
||||||
|
await handleToolCall(response.message.tool_calls);
|
||||||
|
const followUp = await ollama.chat({
|
||||||
|
model: modelName,
|
||||||
|
messages: messageHistory
|
||||||
|
});
|
||||||
|
messageHistory.push(followUp.message);
|
||||||
|
console.log("Final response:", followUp.message.content);
|
||||||
|
} else {
|
||||||
|
messageHistory.push(response.message);
|
||||||
|
console.log("Final response:", response.message.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveSessionData(messageHistory);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("An error occurred:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runModel().catch((error) => {
|
||||||
|
console.error("Critical error in the main loop:", error);
|
||||||
|
});
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "ollama",
|
"name": "ollama",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"main": "index.js",
|
"main": "newver.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"start": "node main.js"
|
"start": "node newver.js"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
|||||||
Reference in New Issue
Block a user