diff --git a/.env.example b/.env.example index 3ffe9e79..f44eb25b 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/cli/utils.py b/cli/utils.py index 17444c9b..d56117d4 100644 --- a/cli/utils.py +++ b/cli/utils.py @@ -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"), ] } diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index f9ce42f9..65e2bbec 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -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 diff --git a/test_ollama_connection.py b/test_ollama_connection.py index 24e55bb2..16296c21 100644 --- a/test_ollama_connection.py +++ b/test_ollama_connection.py @@ -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() diff --git a/tradingagents/agents/utils/memory.py b/tradingagents/agents/utils/memory.py index f3415765..c2119145 100644 --- a/tradingagents/agents/utils/memory.py +++ b/tradingagents/agents/utils/memory.py @@ -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()