Skip to content

Commit

Permalink
remove extra logging for ollama
Browse files Browse the repository at this point in the history
  • Loading branch information
bigsk1 committed Jul 23, 2024
1 parent 63b502b commit b2d45ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 58 deletions.
36 changes: 4 additions & 32 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,27 @@ app.use(express.urlencoded({ limit: '50mb', extended: true }));

const OLLAMA_API_URL = process.env.OLLAMA_API_URL || 'http://host.docker.internal:11434';

console.log('OLLAMA_API_URL:', OLLAMA_API_URL);

// Logging middleware
app.use((req, res, next) => {
console.log(`${new Date().toISOString()} - ${req.method} ${req.url}`);
next();
});

// Ollama routes
app.get('/ollama/api/tags', async (req, res) => {
console.log('Received request for /ollama/api/tags');
try {
const response = await axios.get(`${OLLAMA_API_URL}/api/tags`);
console.log('Ollama response:', response.data);
res.json(response.data);
} catch (error) {
console.error('Error fetching Ollama tags:', error);
res.status(500).json({ error: 'Failed to fetch Ollama tags', details: error.message });
console.error('Error fetching Ollama tags:', error.message);
res.status(500).json({ error: 'Failed to fetch Ollama tags' });
}
});

app.post('/ollama/api/generate', async (req, res) => {
console.log('Received request for /ollama/api/generate');
try {
console.log(`Sending request to Ollama: ${OLLAMA_API_URL}/api/generate`);
const response = await axios.post(`${OLLAMA_API_URL}/api/generate`, req.body);
console.log('Received response from Ollama');
res.json(response.data);
} catch (error) {
console.error('Error generating Ollama response:', error);
res.status(500).json({ error: 'Failed to generate Ollama response', details: error.message });
console.error('Error generating Ollama response:', error.message);
res.status(500).json({ error: 'Failed to generate Ollama response' });
}
});

// Test route
app.get('/test-ollama', async (req, res) => {
console.log('Received request for /test-ollama');
try {
console.log(`Sending request to Ollama: ${OLLAMA_API_URL}/api/tags`);
const response = await axios.get(`${OLLAMA_API_URL}/api/tags`);
console.log('Received response from Ollama:', response.data);
res.json(response.data);
} catch (error) {
console.error('Error testing Ollama connection:', error);
res.status(500).json({ error: 'Failed to connect to Ollama', details: error.message });
}
});


const ANTHROPIC_MODEL = process.env.ANTHROPIC_MODEL || "claude-3-5-sonnet-20240620";

app.post('/api/anthropic', async (req, res) => {
Expand Down
29 changes: 3 additions & 26 deletions src/utils/aiServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ const chatWithAnthropic = async (prompt, context) => {

export const analyzeWithOllama = async (imageData, prompt, context, model = 'llava') => {
try {
console.log('Sending request to Ollama:', `${OLLAMA_API_URL}/api/generate`);
const requestBody = {
model: model,
prompt: `${context}\n\nHuman: ${prompt}\n\nAssistant:`,
Expand All @@ -105,29 +104,16 @@ export const analyzeWithOllama = async (imageData, prompt, context, model = 'lla
}

const response = await axios.post(`${OLLAMA_API_URL}/api/generate`, requestBody);

console.log('Ollama response:', response.data);
return response.data.response;
} catch (error) {
console.error('Error analyzing with Ollama:', error);
if (error.response) {
console.error('Error response:', error.response.data);
console.error('Error status:', error.response.status);
console.error('Error headers:', error.response.headers);
} else if (error.request) {
console.error('Error request:', error.request);
} else {
console.error('Error message:', error.message);
}
console.error('Error analyzing with Ollama:', error.message);
throw error;
}
};

export const getOllamaModels = async () => {
try {
console.log('Fetching Ollama models from:', `${OLLAMA_API_URL}/api/tags`);
const response = await axios.get(`${OLLAMA_API_URL}/api/tags`);
console.log('Ollama models response:', response.data);
if (Array.isArray(response.data.models)) {
return response.data.models;
} else if (typeof response.data.models === 'object') {
Expand All @@ -136,20 +122,11 @@ export const getOllamaModels = async () => {
...details
}));
} else {
console.error('Unexpected Ollama models response format:', response.data);
console.error('Unexpected Ollama models response format');
return [];
}
} catch (error) {
console.error('Error fetching Ollama models:', error);
if (error.response) {
console.error('Error response:', error.response.data);
console.error('Error status:', error.response.status);
console.error('Error headers:', error.response.headers);
} else if (error.request) {
console.error('Error request:', error.request);
} else {
console.error('Error message:', error.message);
}
console.error('Error fetching Ollama models:', error.message);
throw error;
}
};

0 comments on commit b2d45ef

Please sign in to comment.