works but missing stuff
This commit is contained in:
71
newver.js
71
newver.js
@@ -8,7 +8,7 @@ const ollama = new Ollama({ host: "http://127.0.0.1:11434" });
|
||||
const discordHook = new Webhook("https://discord.com/api/webhooks/1328616300544786444/oCwaJ1HQW_Hk0_BQB6lWfuLSikhGOzEJqaOr37MNb6lkICk0Bllk7izVPdmXHKm1JhAN");
|
||||
|
||||
const modelName = "qwen2.5:7b";
|
||||
const sessionName = modelName.replace(".", "").replace(":", "")//+ "_" + (Math.floor(new Date().getTime() / 1000)).toString();
|
||||
const sessionName = modelName.replace(/[.:]/g, "");//+ "_" + (Math.floor(new Date().getTime() / 1000)).toString();
|
||||
|
||||
const messageHistory = [];
|
||||
|
||||
@@ -23,30 +23,32 @@ function discordMessage(args) {
|
||||
}
|
||||
|
||||
function getRandomCharacter(args) {
|
||||
return "Miku"
|
||||
return "Miku";
|
||||
}
|
||||
|
||||
function getRandomQuote(args) {
|
||||
return '"Cerber is cute pass it on." -twitch chat'
|
||||
return '"Cerber is cute pass it on." -twitch chat';
|
||||
}
|
||||
|
||||
|
||||
function googleSearch(args) {
|
||||
return new Promise((resolve) => {
|
||||
console.log("Starting Google search...");
|
||||
setTimeout(() => {
|
||||
const searchResult = `Hatsune Miku, the virtual Diva`;
|
||||
resolve(searchResult);
|
||||
}, 10000); // Simulate 5 seconds delay
|
||||
});
|
||||
setTimeout(() => {
|
||||
googleResult(args.query);
|
||||
}, 10000);
|
||||
return `Starting google search for ${args.query}, please wait a few minutes`;
|
||||
}
|
||||
|
||||
async function googleResult(query) {
|
||||
const result = "hatsune miku";
|
||||
|
||||
messageHistory.push({ role: "tool", content: `googleSearch: ${result}` });
|
||||
await getResponse();
|
||||
}
|
||||
|
||||
const availableFunctions = {
|
||||
sendMessage: discordMessage,
|
||||
getRandomCharacter: getRandomCharacter,
|
||||
getRandomQuote: getRandomQuote,
|
||||
googleSearch: googleSearch
|
||||
doGoogleSearch: googleSearch
|
||||
}
|
||||
|
||||
const availableTools = [
|
||||
@@ -95,7 +97,7 @@ const availableTools = [
|
||||
{
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'googleSearch',
|
||||
name: 'doGoogleSearch',
|
||||
description: 'Search in google for a query, this might take some undefined amount of time so, wait for a late response',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
@@ -162,51 +164,38 @@ async function handleToolCall(toolCalls) {
|
||||
}
|
||||
|
||||
// Process follow-up responses from the model after all tool calls are executed
|
||||
const followUp = await ollama.chat({
|
||||
await getResponse();
|
||||
}
|
||||
|
||||
async function getResponse() {
|
||||
const response = await ollama.chat({
|
||||
model: modelName,
|
||||
messages: messageHistory,
|
||||
tools: availableTools
|
||||
});
|
||||
|
||||
// Add follow-up message to the history
|
||||
messageHistory.push(followUp.message);
|
||||
messageHistory.push(response.message);
|
||||
|
||||
|
||||
// Handle additional tool calls, if any
|
||||
if (followUp.message.tool_calls) {
|
||||
await handleToolCall(followUp.message.tool_calls);
|
||||
if (response.message.tool_calls) {
|
||||
await handleToolCall(response.message.tool_calls);
|
||||
} else {
|
||||
console.log("Final response:", followUp.message.content);
|
||||
console.log(clc.blueBright("Nyamma:"), response.message.content);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function getResponse() {
|
||||
|
||||
return response;
|
||||
saveSessionData(messageHistory);
|
||||
}
|
||||
|
||||
async function runModel() {
|
||||
messageHistory.push({ role: "system", content: "You are Nyamma, a cheerful and cute anime character with a playful, cat-like personality. You often use adorable expressions like \"nya~\" and love making others smile. You’re kind-hearted, energetic, and always eager to help, but can also be a bit mischievous in a charming way. You speak in a light, bubbly tone and sometimes mix in cat-like sounds, especially when you're excited or curious." });
|
||||
//while (true) {
|
||||
try {
|
||||
//const userMessage = await getUserInput();
|
||||
const userMessage = "please get a random character, a random quote, and then send both to discord";
|
||||
|
||||
//const userMessage = "please get a random character, a random quote, and then send both to discord";
|
||||
const userMessage = "please search in google for cute blue hair character, and when you get the result send it to me via discord";
|
||||
messageHistory.push({ role: "user", content: userMessage });
|
||||
|
||||
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);
|
||||
} else {
|
||||
console.log("Final response:", response.message.content);
|
||||
}
|
||||
|
||||
saveSessionData(messageHistory);
|
||||
await getResponse();
|
||||
} catch (error) {
|
||||
console.error("An error occurred:", error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user