modified: .vscode/launch.json
modified: custom_models/qwen/Modelfile modified: newver.js new file: nodemon.json modified: package-lock.json modified: package.json
This commit is contained in:
106
newver.js
106
newver.js
@@ -1,21 +1,17 @@
|
||||
const { Webhook } = require('discord-webhook-node');
|
||||
const readline = require("readline");
|
||||
const { Ollama } = require("ollama");
|
||||
const clc = require("cli-color");
|
||||
const fs = require('fs');
|
||||
const util = require("util");
|
||||
|
||||
const modelName = "qwen-modded";
|
||||
const sessionName = modelName//+ "_" + (Math.floor(new Date().getTime() / 1000)).toString();
|
||||
const modelName = "qwen2.5:7b";
|
||||
const sessionName = modelName.replace(".", "").replace(":", "")//+ "_" + (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");
|
||||
@@ -31,31 +27,17 @@ function getRandomCharacter(args) {
|
||||
}
|
||||
|
||||
function getRandomQuote(args) {
|
||||
return "Cerber is cute pass it on -twitch chat"
|
||||
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: {
|
||||
@@ -123,6 +105,7 @@ function saveSessionData(messages) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async function handleToolCall(toolCalls) {
|
||||
for (const tool of toolCalls) {
|
||||
const { name, arguments: args } = tool.function;
|
||||
@@ -133,53 +116,74 @@ async function handleToolCall(toolCalls) {
|
||||
messageHistory.push({ role: "tool", content: `Tool "${name}" not recognized.` });
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
const output = await functionToCall(args);
|
||||
// Execute the tool function
|
||||
console.log(`Calling function: ${name}`);
|
||||
console.log(`Arguments:`, args);
|
||||
|
||||
const output = await functionToCall(args);
|
||||
console.log(`Function output: ${output}`);
|
||||
messageHistory.push({ role: "tool", content: output.toString() });
|
||||
|
||||
// Update message history with tool output
|
||||
messageHistory.push({ role: "tool", content: `${name}: ${output}` });
|
||||
|
||||
} catch (error) {
|
||||
console.error(`Error executing tool "${name}":`, error);
|
||||
messageHistory.push({ role: "tool", content: `Error executing tool "${name}".` });
|
||||
}
|
||||
}
|
||||
|
||||
// Process follow-up responses from the model after all tool calls are executed
|
||||
const followUp = await ollama.chat({
|
||||
model: modelName,
|
||||
messages: messageHistory,
|
||||
tools: availableTools
|
||||
});
|
||||
|
||||
// Add follow-up message to the history
|
||||
messageHistory.push(followUp.message);
|
||||
|
||||
|
||||
// Handle additional tool calls, if any
|
||||
if (followUp.message.tool_calls) {
|
||||
await handleToolCall(followUp.message.tool_calls);
|
||||
} else {
|
||||
console.log("Final response:", followUp.message.content);
|
||||
}
|
||||
}
|
||||
|
||||
async function askForTool(params) {
|
||||
|
||||
async function getResponse() {
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
async function runModel() {
|
||||
while (true) {
|
||||
try {
|
||||
const userMessage = await getUserInput();
|
||||
messageHistory.push({ role: "user", content: userMessage });
|
||||
//while (true) {
|
||||
try {
|
||||
//const userMessage = await getUserInput();
|
||||
const userMessage = "please get a random character, a random quote, and then send both to discord";
|
||||
messageHistory.push({ role: "user", content: userMessage });
|
||||
|
||||
const response = await ollama.chat({
|
||||
model: modelName,
|
||||
messages: messageHistory,
|
||||
tools: availableTools
|
||||
});
|
||||
const response = await ollama.chat({
|
||||
model: modelName,
|
||||
messages: messageHistory,
|
||||
tools: availableTools
|
||||
});
|
||||
messageHistory.push(response.message);
|
||||
|
||||
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);
|
||||
if (response.message.tool_calls) {
|
||||
await handleToolCall(response.message.tool_calls);
|
||||
} else {
|
||||
console.log("Final response:", response.message.content);
|
||||
}
|
||||
|
||||
saveSessionData(messageHistory);
|
||||
} catch (error) {
|
||||
console.error("An error occurred:", error);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
runModel().catch((error) => {
|
||||
|
||||
Reference in New Issue
Block a user