fix: ensure OpenAI backend URL is used from environment or config
This commit is contained in:
parent
6b03425e8c
commit
e3368c6b87
|
|
@ -3,12 +3,4 @@ FINNHUB_API_KEY="YOUR_FINNHUB_API_KEY"
|
||||||
|
|
||||||
# OpenAI API Key
|
# OpenAI API Key
|
||||||
OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
|
OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
|
||||||
|
|
||||||
# Data directory
|
|
||||||
DATA_DIR="/Users/yluo/Documents/Code/ScAI/FR1-data"
|
|
||||||
|
|
||||||
# LLM settings
|
|
||||||
LLM_PROVIDER="openai"
|
|
||||||
DEEP_THINK_LLM="o4-mini"
|
|
||||||
QUICK_THINK_LLM="gpt-4o-mini"
|
|
||||||
BACKEND_URL="https://api.openai.com/v1"
|
BACKEND_URL="https://api.openai.com/v1"
|
||||||
|
|
@ -7,3 +7,5 @@ eval_results/
|
||||||
eval_data/
|
eval_data/
|
||||||
*.egg-info/
|
*.egg-info/
|
||||||
.env
|
.env
|
||||||
|
.vscode/
|
||||||
|
results/
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ from rich import box
|
||||||
from rich.align import Align
|
from rich.align import Align
|
||||||
from rich.rule import Rule
|
from rich.rule import Rule
|
||||||
|
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
load_dotenv()
|
||||||
from tradingagents.graph.trading_graph import TradingAgentsGraph
|
from tradingagents.graph.trading_graph import TradingAgentsGraph
|
||||||
from tradingagents.default_config import DEFAULT_CONFIG
|
from tradingagents.default_config import DEFAULT_CONFIG
|
||||||
from cli.models import AnalystType
|
from cli.models import AnalystType
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
import chromadb
|
import chromadb
|
||||||
from chromadb.config import Settings
|
from chromadb.config import Settings
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
|
|
@ -5,11 +6,14 @@ from openai import OpenAI
|
||||||
|
|
||||||
class FinancialSituationMemory:
|
class FinancialSituationMemory:
|
||||||
def __init__(self, name, config):
|
def __init__(self, name, config):
|
||||||
if config["backend_url"] == "http://localhost:11434/v1":
|
backend_url = os.environ.get("BACKEND_URL", config.get("backend_url"))
|
||||||
|
api_key = os.environ.get("OPENAI_API_KEY", config.get("openai_api_key"))
|
||||||
|
|
||||||
|
if backend_url == "http://localhost:11434/v1":
|
||||||
self.embedding = "nomic-embed-text"
|
self.embedding = "nomic-embed-text"
|
||||||
else:
|
else:
|
||||||
self.embedding = "text-embedding-3-small"
|
self.embedding = "text-embedding-3-small"
|
||||||
self.client = OpenAI(base_url=config["backend_url"])
|
self.client = OpenAI(base_url=backend_url, api_key=api_key)
|
||||||
self.chroma_client = chromadb.Client(Settings(allow_reset=True))
|
self.chroma_client = chromadb.Client(Settings(allow_reset=True))
|
||||||
self.situation_collection = self.chroma_client.create_collection(name=name)
|
self.situation_collection = self.chroma_client.create_collection(name=name)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ DEFAULT_CONFIG = {
|
||||||
"llm_provider": "openai",
|
"llm_provider": "openai",
|
||||||
"deep_think_llm": "o4-mini",
|
"deep_think_llm": "o4-mini",
|
||||||
"quick_think_llm": "gpt-4o-mini",
|
"quick_think_llm": "gpt-4o-mini",
|
||||||
"backend_url": "https://api.openai.com/v1",
|
"backend_url": os.getenv("BACKEND_URL", "https://api.openai.com/v1"),
|
||||||
# Debate and discussion settings
|
# Debate and discussion settings
|
||||||
"max_debate_rounds": 1,
|
"max_debate_rounds": 1,
|
||||||
"max_risk_discuss_rounds": 1,
|
"max_risk_discuss_rounds": 1,
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,12 @@ class TradingAgentsGraph:
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.config = config or DEFAULT_CONFIG
|
self.config = config or DEFAULT_CONFIG
|
||||||
|
|
||||||
|
# Override config with environment variables if set
|
||||||
|
self.config["backend_url"] = os.environ.get("BACKEND_URL", self.config.get("backend_url"))
|
||||||
|
self.config["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY", self.config.get("OPENAI_API_KEY"))
|
||||||
|
self.config["deep_think_llm"] = os.environ.get("DEEP_THINK_LLM", self.config.get("deep_think_llm"))
|
||||||
|
self.config["quick_think_llm"] = os.environ.get("QUICK_THINK_LLM", self.config.get("quick_think_llm"))
|
||||||
|
|
||||||
# Update the interface's config
|
# Update the interface's config
|
||||||
set_config(self.config)
|
set_config(self.config)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue