From 1d22ddae58e48bd4016afbfa4469794a72596e3d Mon Sep 17 00:00:00 2001 From: Yuchen Zhang Date: Thu, 19 Jun 2025 20:03:47 +0800 Subject: [PATCH 1/4] Add support for deepseek official api --- cli/utils.py | 7 +++++++ requirements.txt | 1 + tradingagents/graph/trading_graph.py | 3 +++ 3 files changed, 11 insertions(+) diff --git a/cli/utils.py b/cli/utils.py index d3873360..5e054f3e 100644 --- a/cli/utils.py +++ b/cli/utils.py @@ -151,6 +151,9 @@ def select_shallow_thinking_agent(provider) -> str: ], "ollama": [ ("llama3.2 local", "llama3.2"), + ], + "deepseek": [ + ("DeepSeek V3 - a 685B-parameter, mixture-of-experts model", "deepseek-chat") ] } @@ -212,6 +215,10 @@ def select_deep_thinking_agent(provider) -> str: ], "ollama": [ ("qwen3", "qwen3"), + ], + "deepseek": [ + ("DeepSeek V3 - a 685B-parameter, mixture-of-experts model", "deepseek-chat"), + ("DeepSeek-R1 - latest iteration of the flagship chat model family from the DeepSeek team.", "deepseek-reasoner"), ] } diff --git a/requirements.txt b/requirements.txt index 1c7c2818..b157407a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,3 +22,4 @@ redis chainlit rich questionary +langchain_anthropic diff --git a/tradingagents/graph/trading_graph.py b/tradingagents/graph/trading_graph.py index eb06cf43..2541f9c4 100644 --- a/tradingagents/graph/trading_graph.py +++ b/tradingagents/graph/trading_graph.py @@ -67,6 +67,9 @@ class TradingAgentsGraph: elif self.config["llm_provider"].lower() == "google": self.deep_thinking_llm = ChatGoogleGenerativeAI(model=self.config["deep_think_llm"]) self.quick_thinking_llm = ChatGoogleGenerativeAI(model=self.config["quick_think_llm"]) + elif self.config["llm_provider"].lower() == 'deepseek': + self.deep_thinking_llm = ChatDeepSeek(model=self.config["deep_think_llm"]) + self.quick_thinking_llm = ChatDeepSeek(model=self.config["quick_think_llm"]) else: raise ValueError(f"Unsupported LLM provider: {self.config['llm_provider']}") From d7d7fc2a7d83bf861633f008294bbed7e438aed7 Mon Sep 17 00:00:00 2001 From: Yuchen Zhang Date: Thu, 19 Jun 2025 20:42:06 +0800 Subject: [PATCH 2/4] Modify embedding model and requirements.txt --- cli/utils.py | 3 ++- requirements.txt | 4 ++++ tradingagents/agents/utils/memory.py | 22 +++++++++++++++------- tradingagents/graph/trading_graph.py | 1 + 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/cli/utils.py b/cli/utils.py index 5e054f3e..217af9bf 100644 --- a/cli/utils.py +++ b/cli/utils.py @@ -252,7 +252,8 @@ def select_llm_provider() -> tuple[str, str]: ("Anthropic", "https://api.anthropic.com/"), ("Google", "https://generativelanguage.googleapis.com/v1"), ("Openrouter", "https://openrouter.ai/api/v1"), - ("Ollama", "http://localhost:11434/v1"), + ("Ollama", "http://localhost:11434/v1"), + ("DeepSeek", "https://api.deepseek.com/v1") ] choice = questionary.select( diff --git a/requirements.txt b/requirements.txt index b157407a..4d643427 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,3 +23,7 @@ chainlit rich questionary langchain_anthropic +langchain_deepseek +langchain_google_genai +openai +sentence-transformers \ No newline at end of file diff --git a/tradingagents/agents/utils/memory.py b/tradingagents/agents/utils/memory.py index f3415765..3a3c55ee 100644 --- a/tradingagents/agents/utils/memory.py +++ b/tradingagents/agents/utils/memory.py @@ -1,7 +1,9 @@ +import os + import chromadb from chromadb.config import Settings from openai import OpenAI - +from sentence_transformers import SentenceTransformer class FinancialSituationMemory: def __init__(self, name, config): @@ -9,17 +11,23 @@ class FinancialSituationMemory: self.embedding = "nomic-embed-text" else: self.embedding = "text-embedding-3-small" - self.client = OpenAI() self.chroma_client = chromadb.Client(Settings(allow_reset=True)) self.situation_collection = self.chroma_client.create_collection(name=name) def get_embedding(self, text): """Get OpenAI embedding for a text""" - - response = self.client.embeddings.create( - model=self.embedding, input=text - ) - return response.data[0].embedding + if os.environ.get("OPENAI_API_KEY"): + client = OpenAI() + response = client.embeddings.create( + model=self.embedding, input=text + ) + return response.data[0].embedding + else: + model = SentenceTransformer("all-MiniLM-L6-v2") + embeddings = model.encode(text, convert_to_numpy=True, precision='int8') + # 单文本返回一维数组,多文本返回二维数组 + return embeddings + def add_situations(self, situations_and_advice): """Add financial situations and their corresponding advice. Parameter is a list of tuples (situation, rec)""" diff --git a/tradingagents/graph/trading_graph.py b/tradingagents/graph/trading_graph.py index 2541f9c4..e4c5888a 100644 --- a/tradingagents/graph/trading_graph.py +++ b/tradingagents/graph/trading_graph.py @@ -6,6 +6,7 @@ import json from datetime import date from typing import Dict, Any, Tuple, List, Optional +from langchain_deepseek import ChatDeepSeek from langchain_openai import ChatOpenAI from langchain_anthropic import ChatAnthropic from langchain_google_genai import ChatGoogleGenerativeAI From 33ee0f9cb5176425141ab29b19c43bf1acc8325d Mon Sep 17 00:00:00 2001 From: Yuchen Zhang <74830865+Paikchu@users.noreply.github.com> Date: Thu, 19 Jun 2025 20:49:23 +0800 Subject: [PATCH 3/4] Update memory.py --- tradingagents/agents/utils/memory.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tradingagents/agents/utils/memory.py b/tradingagents/agents/utils/memory.py index 3a3c55ee..add31e78 100644 --- a/tradingagents/agents/utils/memory.py +++ b/tradingagents/agents/utils/memory.py @@ -25,7 +25,6 @@ class FinancialSituationMemory: else: model = SentenceTransformer("all-MiniLM-L6-v2") embeddings = model.encode(text, convert_to_numpy=True, precision='int8') - # 单文本返回一维数组,多文本返回二维数组 return embeddings From 0fff512094338e091edeb4a6a2eab7d8945ebb4a Mon Sep 17 00:00:00 2001 From: Yuchen Zhang <74830865+Paikchu@users.noreply.github.com> Date: Fri, 20 Jun 2025 11:20:17 +0800 Subject: [PATCH 4/4] Update memory.py modify embedding model params --- tradingagents/agents/utils/memory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tradingagents/agents/utils/memory.py b/tradingagents/agents/utils/memory.py index add31e78..e1428204 100644 --- a/tradingagents/agents/utils/memory.py +++ b/tradingagents/agents/utils/memory.py @@ -24,7 +24,7 @@ class FinancialSituationMemory: return response.data[0].embedding else: model = SentenceTransformer("all-MiniLM-L6-v2") - embeddings = model.encode(text, convert_to_numpy=True, precision='int8') + embeddings = model.encode(text, convert_to_numpy=True) return embeddings