-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-ollama.ts
More file actions
185 lines (161 loc) · 5.99 KB
/
Copy pathtest-ollama.ts
File metadata and controls
185 lines (161 loc) · 5.99 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import { DebateOrchestratorImpl } from './src/orchestrator/DebateOrchestrator';
import { LocalModelProvider } from './src/providers/LocalModelProvider';
import { DEFAULT_CONFIG } from './src/models/DebateConfig';
import { formatStatement } from './src/utils/StatementFormatter';
import { RoundType } from './src/models/RoundType';
interface OllamaModel {
name: string;
size: number;
modified_at: string;
}
interface OllamaTagsResponse {
models: OllamaModel[];
}
/**
* Fetch available models from Ollama API
*/
async function getAvailableOllamaModels(baseUrl: string): Promise<string[]> {
try {
const response = await fetch(`${baseUrl}/api/tags`);
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const data = await response.json() as OllamaTagsResponse;
return data.models.map(m => m.name);
} catch (error) {
throw new Error(`Failed to fetch Ollama models: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
}
async function runOllamaDebate() {
console.log('🎯 Starting Ollama Debate Test\n');
const baseUrl = 'http://localhost:11434';
// Check if Ollama is running
console.log('Checking Ollama availability...');
try {
const response = await fetch(`${baseUrl}/api/tags`);
if (!response.ok) {
throw new Error('Ollama not responding');
}
} catch (error) {
console.error('❌ Ollama is not running or not accessible.');
console.error('\nTo fix this:');
console.error(' 1. Start Ollama: ollama serve');
console.error(' 2. Verify it\'s running: curl http://localhost:11434/api/tags');
process.exit(1);
}
// Fetch available models
console.log('Fetching available models...');
let availableModels: string[];
try {
availableModels = await getAvailableOllamaModels(baseUrl);
} catch (error) {
console.error('❌ Failed to fetch models from Ollama.');
console.error(error instanceof Error ? error.message : 'Unknown error');
process.exit(1);
}
if (availableModels.length === 0) {
console.error('❌ No models found in Ollama.');
console.error('\nTo fix this, pull at least one model:');
console.error(' ollama pull llama2');
console.error(' ollama pull mistral');
console.error('\nOr list available models: ollama list');
process.exit(1);
}
console.log(`✅ Found ${availableModels.length} model(s): ${availableModels.join(', ')}\n`);
// Select models for debate
let modelName1: string;
let modelName2: string;
if (availableModels.length === 1) {
console.log('ℹ️ Only one model available - using the same model for both sides');
modelName1 = availableModels[0];
modelName2 = availableModels[0];
} else {
// Use first two different models
modelName1 = availableModels[0];
modelName2 = availableModels[1];
console.log('ℹ️ Using two different models for the debate');
}
// Initialize model providers
const model1 = new LocalModelProvider({
baseUrl,
model: modelName1,
apiFormat: 'ollama',
maxTokens: 500,
temperature: 0.7,
timeout: 60000
});
const model2 = new LocalModelProvider({
baseUrl,
model: modelName2,
apiFormat: 'ollama',
maxTokens: 500,
temperature: 0.8, // Slightly different temperature for variety if same model
timeout: 60000
});
console.log('✅ Models initialized\n');
// Initialize orchestrator
const orchestrator = new DebateOrchestratorImpl();
const topic = 'Artificial intelligence will benefit humanity more than harm it';
console.log(`📋 Topic: ${topic}`);
console.log(`📋 Affirmative: ${model1.getModelName()}`);
console.log(`📋 Negative: ${model2.getModelName()}\n`);
// Initialize debate with shorter limits for testing
const config = {
...DEFAULT_CONFIG,
wordLimit: 150,
timeLimit: 60,
numCrossExamQuestions: 2,
showPreparation: false
};
let debate = orchestrator.initializeDebate(topic, config, model1, model2);
try {
// Preparation phase
if (config.showPreparation) {
console.log('🔍 Preparation Phase');
console.log('═'.repeat(80));
debate = await orchestrator.executePreparation(debate);
console.log('✅ Preparation complete\n');
} else {
// Still need to execute preparation even if not showing it
debate = await orchestrator.executePreparation(debate);
}
// Opening statements
console.log('📢 Opening Statements');
console.log('═'.repeat(80));
debate = await orchestrator.executeOpeningStatements(debate);
const openingRound = debate.rounds[debate.rounds.length - 1];
if (openingRound.affirmativeStatement) {
console.log(formatStatement(openingRound.affirmativeStatement, RoundType.OPENING));
}
if (openingRound.negativeStatement) {
console.log(formatStatement(openingRound.negativeStatement, RoundType.OPENING));
}
// Rebuttals
console.log('\n🔄 Rebuttals');
console.log('═'.repeat(80));
debate = await orchestrator.executeRebuttals(debate);
const rebuttalRound = debate.rounds[debate.rounds.length - 1];
if (rebuttalRound.affirmativeStatement) {
console.log(formatStatement(rebuttalRound.affirmativeStatement, RoundType.REBUTTAL));
}
if (rebuttalRound.negativeStatement) {
console.log(formatStatement(rebuttalRound.negativeStatement, RoundType.REBUTTAL));
}
// Closing statements
console.log('\n🎬 Closing Statements');
console.log('═'.repeat(80));
debate = await orchestrator.executeClosingStatements(debate);
const closingRound = debate.rounds[debate.rounds.length - 1];
if (closingRound.affirmativeStatement) {
console.log(formatStatement(closingRound.affirmativeStatement, RoundType.CLOSING));
}
if (closingRound.negativeStatement) {
console.log(formatStatement(closingRound.negativeStatement, RoundType.CLOSING));
}
console.log('\n✅ Debate completed successfully!');
} catch (error) {
console.error('\n❌ Error during debate:', error);
process.exit(1);
}
}
runOllamaDebate();