Fix issues

This commit is contained in:
Iyeoluwa Akinrinola
2025-05-12 16:10:45 +01:00
parent 47e02c9352
commit 7c61e98340
5 changed files with 122 additions and 23 deletions
+33
View File
@@ -3,6 +3,7 @@ Service for model management and interaction.
"""
import requests
import json
from typing import List, Dict, Any, Optional
from ai_service.config import config
@@ -68,6 +69,21 @@ class ModelService:
}
models.append(model_data)
# Debug log
print(f"Model service models: {models}")
# Ensure we're returning a non-empty list
if not models:
# Return a default model if none are found
return [{
'id': 'llama3.1',
'name': 'Llama 3 (8B)',
'description': 'Meta Llama 3 8B model via Ollama',
'provider': 'ollama',
'max_tokens': 8192,
'is_default': True
}]
return models
def get_model_info(self, model_id: str) -> Optional[Dict[str, Any]]:
@@ -106,8 +122,17 @@ class ModelService:
Returns:
Generated response.
"""
# Debug configuration information
print(f"ModelService configuration:")
print(f" - Ollama API URL: {self.ollama_api_url}")
print(f" - OpenWebUI URL: {self.openwebui_url}")
print(f" - Default model: {self.default_model}")
print(f" - Requested model: {model_id}")
print(f" - Using RAG: {use_rag}")
if model_id not in self.AVAILABLE_MODELS:
model_id = self.default_model
print(f" - Model not found, using default: {model_id}")
# Ensure we're using a valid model
# (model_id is already validated above)
@@ -158,6 +183,11 @@ class ModelService:
if self.openwebui_api_key:
headers["Authorization"] = f"Bearer {self.openwebui_api_key}"
# Debug logs
print(f"Sending RAG request to OpenWebUI at: {self.openwebui_url}/api/chat/completions")
print(f"OpenWebUI request: {json.dumps(openwebui_request, indent=2)}")
print(f"Headers: {headers}")
# OpenWebUI API endpoint is /api/chat/completions
response = requests.post(
f"{self.openwebui_url}/api/chat/completions",
@@ -213,6 +243,9 @@ class ModelService:
headers = {"Content-Type": "application/json"}
# Direct Ollama API call
print(f"Sending request to Ollama API at: {self.ollama_api_url}/api/chat")
print(f"Request JSON: {json.dumps(request_json, indent=2)}")
response = requests.post(
f"{self.ollama_api_url}/api/chat",
headers={"Content-Type": "application/json"},