added tests for local embeddings model
This commit is contained in:
parent
5064e8dfbb
commit
83c86aee61
|
|
@ -3,6 +3,7 @@ LLM_PROVIDER="ollama"
|
|||
LLM_BACKEND_URL="http://localhost:11434/v1" # For Ollama running in the same container, /v1 added for OpenAI compatibility
|
||||
LLM_DEEP_THINK_MODEL="qwen3:0.6b"
|
||||
LLM_QUICK_THINK_MODEL="qwen3:0.6b"
|
||||
LLM_EMBEDDING_MODEL="nomic-embed-text"
|
||||
OPENAI_API_KEY="ollama-key" # Optional, if you want to use OpenAI models or ollama models with OpenAI API compatibility
|
||||
|
||||
# Agent Configuration
|
||||
|
|
|
|||
|
|
@ -151,7 +151,8 @@ def select_shallow_thinking_agent(provider) -> str:
|
|||
],
|
||||
"ollama": [
|
||||
("llama3.2 local", "llama3.2"),
|
||||
("qwen3 local", "qwen3:0.6b"),
|
||||
("qwen3 small local", "qwen3:0.6b"),
|
||||
("deepseek-r1 local", "deepseek-r1:1.5b"),
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -212,7 +213,9 @@ def select_deep_thinking_agent(provider) -> str:
|
|||
("Deepseek - latest iteration of the flagship chat model family from the DeepSeek team.", "deepseek/deepseek-chat-v3-0324:free"),
|
||||
],
|
||||
"ollama": [
|
||||
("qwen3", "qwen3"),
|
||||
("qwen3 local", "qwen3"),
|
||||
("qwen3 small local", "qwen3:0.6b"),
|
||||
("deepseek-r1 local", "deepseek-r1:1.5b"),
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,12 @@ MODEL_TO_PULL=${LLM_DEEP_THINK_MODEL:-"qwen3:0.6b"}
|
|||
echo "Pulling Ollama model: $MODEL_TO_PULL..."
|
||||
ollama pull "$MODEL_TO_PULL"
|
||||
echo "Model $MODEL_TO_PULL pulled."
|
||||
|
||||
echo "Pulling embeddings model..."
|
||||
ollama pull nomic-embed-text
|
||||
echo "Embeddings model pulled."
|
||||
# List models to verify the pull
|
||||
echo "Listing available models..."
|
||||
ollama list # List models for verification
|
||||
|
||||
# Test the connection before running the main application
|
||||
|
|
|
|||
|
|
@ -13,11 +13,13 @@ def test_ollama_connection():
|
|||
|
||||
# Get configuration from environment
|
||||
backend_url = os.environ.get("LLM_BACKEND_URL", "http://localhost:11434/v1")
|
||||
model = os.environ.get("LLM_DEEP_THINK_MODEL", "qwen2.5")
|
||||
model = os.environ.get("LLM_DEEP_THINK_MODEL", "qwen3:0.6b")
|
||||
embedding_model = os.environ.get("LLM_EMBEDDING_MODEL", "nomic-embed-text")
|
||||
|
||||
print(f"Testing Ollama connection:")
|
||||
print(f" Backend URL: {backend_url}")
|
||||
print(f" Model: {model}")
|
||||
print(f" Embedding Model: {embedding_model}")
|
||||
|
||||
# Test 1: Check if Ollama API is responding
|
||||
try:
|
||||
|
|
@ -37,7 +39,7 @@ def test_ollama_connection():
|
|||
models = response.json().get("models", [])
|
||||
model_names = [m.get("name", "") for m in models]
|
||||
|
||||
if model in model_names:
|
||||
if any(name.startswith(model) for name in model_names):
|
||||
print(f"✅ Model '{model}' is available")
|
||||
else:
|
||||
print(f"❌ Model '{model}' not found. Available models: {model_names}")
|
||||
|
|
@ -60,6 +62,41 @@ def test_ollama_connection():
|
|||
except Exception as e:
|
||||
print(f"❌ OpenAI-compatible API test failed: {e}")
|
||||
return False
|
||||
|
||||
# Test 4: Check if the embedding model is available
|
||||
try:
|
||||
response = requests.get(f"{api_url}/api/tags", timeout=10)
|
||||
models = response.json().get("models", [])
|
||||
model_names = [m.get("name") for m in models if m.get("name")]
|
||||
|
||||
# Check if any of the available models starts with the embedding model name
|
||||
if any(name.startswith(embedding_model) for name in model_names):
|
||||
print(f"✅ Embedding Model '{embedding_model}' is available")
|
||||
else:
|
||||
print(f"❌ Embedding Model '{embedding_model}' not found. Available models: {model_names}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ Failed to check embedding model availability: {e}")
|
||||
return False
|
||||
|
||||
# Test 5: Test OpenAI-compatible embedding API
|
||||
try:
|
||||
client = OpenAI(base_url=backend_url, api_key="dummy")
|
||||
response = client.embeddings.create(
|
||||
model=embedding_model,
|
||||
input="This is a test sentence.",
|
||||
encoding_format="float"
|
||||
)
|
||||
if response.data and len(response.data) > 0 and response.data[0].embedding:
|
||||
print("✅ OpenAI-compatible embedding API is working")
|
||||
print(f" Successfully generated embedding of dimension: {len(response.data[0].embedding)}")
|
||||
return True
|
||||
else:
|
||||
print("❌ Embedding API test failed: No embedding data in response")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ OpenAI-compatible embedding API test failed: {e}")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = test_ollama_connection()
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ class FinancialSituationMemory:
|
|||
def __init__(self, name, config):
|
||||
if config["backend_url"] == "http://localhost:11434/v1":
|
||||
self.embedding = "nomic-embed-text"
|
||||
self.client = OpenAI(base_url=config["backend_url"])
|
||||
else:
|
||||
self.embedding = "text-embedding-3-small"
|
||||
self.client = OpenAI()
|
||||
|
|
|
|||
Loading…
Reference in New Issue