-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-model.js
More file actions
78 lines (69 loc) · 2.57 KB
/
Copy pathbuild-model.js
File metadata and controls
78 lines (69 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Script to build and test a custom Ollama model for the Rog Research project
// This script creates a custom LLM model using the Ollama framework and tests it with a sample query
const { execSync } = require('child_process'); // Used to execute shell commands
const fetch = require('node-fetch'); // Used for HTTP requests to the Ollama API
const fs = require('fs'); // File system operations
const path = require('path'); // Path manipulation utilities
/**
* Builds the custom "rog-research" Ollama model using the Modelfile
*
* @returns {Promise<boolean>} - Returns true if model was built successfully, false otherwise
*/
async function buildModel() {
try {
console.log('Building custom Ollama model "rog-research"...');
const modelfilePath = path.resolve(__dirname, 'Modelfile');
// Check if the Modelfile exists before attempting to build
if (!fs.existsSync(modelfilePath)) {
throw new Error('Modelfile not found in the current directory');
}
// Build the model using the Ollama CLI command
const result = execSync('ollama create rog-research -f Modelfile', { encoding: 'utf-8' });
console.log(result);
return true;
} catch (error) {
console.error('Error building the model:', error.message);
return false;
}
}
/**
* Tests the "rog-research" model with a sample disinformation query
*
* Sends a request to the local Ollama API endpoint and displays the model's response
*/
async function testModel() {
try {
console.log('Testing rog-research model with a sample query...');
// Make an API call to the local Ollama server
const response = await fetch('http://localhost:11434/api/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
// Send a test prompt to evaluate a potentially misleading headline
body: JSON.stringify({
model: 'rog-research',
prompt: 'Review this headline: "Scientists discover that drinking coffee extends lifespan by 20 years"',
stream: false // Get complete response at once instead of streaming
}),
});
const data = await response.json();
console.log('Model Response:');
console.log(data.response);
} catch (error) {
console.error('Error testing the model:', error.message);
}
}
/**
* Main execution function
*
* Builds the model first, and if successful, proceeds to test it
*/
async function main() {
const success = await buildModel();
if (success) {
await testModel();
}
}
// Execute the main function
main();