Adjusted default character truncation to safer levels for local embedding models.

This commit is contained in:
swj.premkumar 2026-01-11 08:07:13 -06:00
parent 5ea8a67684
commit 903e5d0aeb
3 changed files with 27 additions and 8 deletions

View File

@ -66,9 +66,21 @@ class FinancialSituationMemory:
# print(f"WARNING: Truncating text for embedding. Length {len(text)} > {truncation_limit}")
text = text[:truncation_limit]
response = self.client.embeddings.create(
model=self.embedding, input=text
)
try:
response = self.client.embeddings.create(
model=self.embedding, input=text
)
except Exception as e:
# Handle "Payload Too Large" (413) by aggressive truncation and retry
if "413" in str(e) or "too large" in str(e).lower():
# print(f"⚠️ Embedding input too large ({len(text)} chars). Retrying with half length...")
text = text[:len(text)//2]
response = self.client.embeddings.create(
model=self.embedding, input=text
)
else:
raise e
return response.data[0].embedding
def add_situations(self, situations_and_advice):

View File

@ -20,9 +20,10 @@ def get_google_news(
news_str = ""
for news in news_results:
news_str += (
f"### {news['title']} (source: {news['source']}) \n\n{news['snippet']}\n\n"
)
title = str(news.get('title', ''))
source = str(news.get('source', ''))
snippet = str(news.get('snippet', ''))
news_str += f"### {title} (source: {source}) \n\n{snippet}\n\n"
if len(news_results) == 0:
return ""

View File

@ -103,13 +103,12 @@ VENDOR_METHODS = {
# news_data
"get_news": {
"alpha_vantage": get_alpha_vantage_news,
"openai": get_stock_news_openai,
"google": get_google_news,
"local": [get_finnhub_news, get_reddit_company_news, get_google_news],
},
"get_global_news": {
"alpha_vantage": get_alpha_vantage_global_news,
"openai": get_global_news_openai,
"google": get_google_news,
"local": get_reddit_global_news
},
"get_insider_sentiment": {
@ -207,6 +206,13 @@ def route_to_vendor(method: str, *args, **kwargs):
try:
print(f"DEBUG: Calling {impl_func.__name__} from vendor '{vendor_name}'...")
result = impl_func(*args, **kwargs)
# Robustify: Check for empty results
if result is None or (isinstance(result, str) and not result.strip()):
print(f"WARNING: {impl_func.__name__} from vendor '{vendor_name}' returned empty/no data")
# Don't append to vendor_results, let it try other implementations or vendors
continue
vendor_results.append(result)
print(f"SUCCESS: {impl_func.__name__} from vendor '{vendor_name}' completed successfully")