refactor:

- changed method get_agent_tools for only get_tools on agent interface
- changed OllamaModelManager to correc semantic OllamaService

test:
- added test for service initialization
- added tests to list tools and create tools into  PDF agent
This commit is contained in:
2025-03-23 21:52:11 -03:00
parent 8851ad888c
commit 2aad4b8bf0
20 changed files with 1071 additions and 37 deletions

View File

@@ -0,0 +1,46 @@
import requests
from src.interfaces.models.modelInference import ModelManager
class OllamaService(ModelManager):
def __init__(self, base_url = "http://localhost:11434"):
self.base_url = base_url
def get_available_models(self):
try:
print(requests.__file__)
print(self.base_url)
response = requests.get(f"{self.base_url}/api/tags")
data = response.json()
return data.get('models', [])
except Exception as e:
print(f"Erro ao obter modelos: {e}")
return []
def get_model_details(self, model_name):
try:
# Obter detalhes completos do modelo via API
response = requests.post(
f"{self.base_url}/api/show",
json={"name": model_name}
)
model_details = response.json()
# O tamanho do contexto geralmente está disponível em model_details['parameters']['context_length']
# ou em outro campo similar dependendo do modelo
context_size = model_details.get('parameters', {}).get('context_length', 'Não disponível')
# Podemos adicionar outros detalhes relevantes
details = {
"name": model_name,
"context_size": context_size,
"model_type": model_details.get('modelfile', {}).get('parameter', 'Não disponível'),
"license": model_details.get('license', 'Não disponível')
}
return details
except Exception as e:
print(f"Error getting model details: {e}")
return {"name": model_name, "error": str(e)}