Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR #134

Open
MarianoAntezana opened this issue Mar 7, 2025 · 1 comment
Open

ERROR #134

MarianoAntezana opened this issue Mar 7, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@MarianoAntezana
Copy link

Seems that the code is not working, I have put everysingle API key for not having errors, but its not working. Also im sure i Have installed poetry well, but is there any way to debug it?

thank you!

Image

@MarianoAntezana MarianoAntezana added the bug Something isn't working label Mar 7, 2025
@Varun786223
Copy link

Varun786223 commented Mar 7, 2025

bug.txt

@MarianoAntezana @yashar1908 @virattt

Hi Mariano, thanks for flagging this—sorry to hear it’s not working despite your API keys being set! I dug into the output you shared, and it looks like the tool’s hitting an error in parse_hedge_fund_response() (likely from issue #141), defaulting to "HOLD" with 0 quantity and confidence. Since Poetry’s installed and keys are in place, the issue might be an invalid API response or a network glitch—tricky to pin down with the current setup.

I tested Yashar’s fix with various cases (bad JSON, None, empty strings), and it’s solid—no bugs there. It catches errors and returns None, which triggers the "HOLD" fallback in the portfolio logic. The problem seems to be upstream—maybe the API’s sending junk—or we need better debugging. Current print() logs aren’t cutting it for tracking this down.

I’d like to contribute a tweak to help: switching to logging with file output, adding a response validity check, and passing error context to the portfolio output. Here’s my proposal:
`import json
import logging

logger = logging.getLogger(name)
logging.basicConfig(filename='portfolio_debug.log', level=logging.ERROR)

def parse_hedge_fund_response(response):
"""Parses a JSON string and returns a dictionary.

Args:
    response: A JSON-formatted string to parse.

Returns:
    dict: Parsed JSON data, or None if parsing fails.
"""
if not response or not isinstance(response, (str, bytes, bytearray)):
    logger.error("Invalid or empty response: %s (type: %s)", str(response)[:50], type(response).__name__)
    return None
try:
    return json.loads(response)
except json.JSONDecodeError as e:
    logger.error("JSON decoding failed: %s | Response (truncated): %s", e, str(response)[:50])
    return None
except TypeError as e:
    logger.error("Invalid response type, expected string/bytes, got %s: %s", type(response).__name__, e)
    return None
except Exception as e:
    logger.error("Unexpected error parsing response: %s", e)
    return None

def update_portfolio(data):
"""Updates portfolio based on parsed data.

Args:
    data: Parsed JSON or None from parse_hedge_fund_response.

Returns:
    dict: Portfolio action, quantity, and confidence.
"""
if data is None:
    logger.error("Portfolio update failed due to invalid data, defaulting to HOLD")
    return {"action": "HOLD", "quantity": 0, "confidence": 0.0, "reasoning": "Error in portfolio management, defaulting to hold"}
return {"action": data.get("action", "HOLD"), "quantity": data.get("quantity", 0), "confidence": data.get("confidence", 0.0)}`

Logs go to portfolio_debug.log—Mariano, check that file after running to see the error.
Adds a pre-check to catch invalid inputs early.
Includes a reasoning field for clearer output.
Yashar, your foundation’s strong—this builds on it. Virattt, thoughts on a PR with this? I’d be happy to draft it, maybe with a test case (e.g., a bad API mock), to nail this down. Mariano, try running with this change and share the log—should point us to the API issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants