jankrepl / mildlyoverfitted

Paper implementations from scratch and machine learning tutorials
MIT License
340 stars 124 forks source link

Interesting error for OpenAI function calling example #27

Open ak2766 opened 6 months ago

ak2766 commented 6 months ago

I got quite intrigued after watching your YouTube video on OpenAI function calling and got your example.py code to play with. I wanted to see what it would do with an interesting ticker like HMNY. So I asked the following question and it barfed on start and end date. I thought I had unintentionally modified the code when I was perusing but a git diff and a git st both showed nothing had been modified:

# python example.py "If I bought 100 shares of HMNY stock on 2004-01-01, how much did I pay for them and how much are they worth today?"                                                    

2024-05-11 02:52:22,516 Calling get_price with symbol='HMNY' and date='2004-01-01'                                                                                                          
2024-05-11 02:52:25,216 Calling get_price with symbol='HMNY' and date='2024-05-11'                                                                                                          
2024-05-11 02:52:29,333                                                                                                                                                                     
1 Failed download:                                                                                                                                                                          
2024-05-11 02:52:29,333 ['HMNY']: Exception('%ticker%: Invalid input - start date cannot be after end date. startDate = 1715400000, endDate = 1715395945')                                  
Traceback (most recent call last):                                                                                                                                                          
  File "/root/source/mildlyoverfitted/mini_tutorials/openai_function_calling/example.py", line 105, in <module>
    output = str(get_price(**kwargs))                                                         
  File "/root/source/mildlyoverfitted/mini_tutorials/openai_function_calling/example.py", line 24, in get_price
    return history["Close"].iloc[0].item()                                                    
  File "/opt/openai-functions/lib/python3.10/site-packages/pandas/core/indexing.py", line 1191, in __getitem__
    return self._getitem_axis(maybe_callable, axis=axis)                                                                                                                                    
  File "/opt/openai-functions/lib/python3.10/site-packages/pandas/core/indexing.py", line 1752, in _getitem_axis
    self._validate_integer(key, axis)                                                         
  File "/opt/openai-functions/lib/python3.10/site-packages/pandas/core/indexing.py", line 1685, in _validate_integer
    raise IndexError("single positional indexer is out-of-bounds")                                                                                                                          
IndexError: single positional indexer is out-of-bounds

So, I asked a different question and this time it didn't crash:

# python example.py "If I bought 100 shares of HMNY stock on 2004-01-01, how much did I pay for them and how much were they worth on 2018-07-31?"
2024-05-11 04:13:56,098 Calling get_price with symbol='HMNY' and date='2004-01-01'
2024-05-11 04:14:03,959 Calling get_price with symbol='HMNY' and date='2018-07-31'
2024-05-11 04:14:05,468 Calling calculate with a=2275, b=100 and op='mul'
2024-05-11 04:14:06,388 Calling calculate with a=0.4959999918937683, b=100 and op='mul'
********************************************************************************
['user', 'system', 'assistant', 'function', 'assistant', 'function', 'assistant', 'function', 'assistant', 'function', 'assistant']
********************************************************************************
You paid $2,275 for 100 shares of HMNY stock on January 1, 2004. 

On July 31, 2018, each share of HMNY stock was worth $0.496. 

Therefore, your 100 shares of HMNY stock were worth $49.60 on July 31, 2018.

This rather puzzled me so later on, I asked the same question that failed before but this time no crash:

# python example.py "If I bought 100 shares of HMNY stock on 2004-01-01, how much did I pay for them and how much are they worth today?"
2024-05-11 04:14:59,328 Calling get_price with symbol='HMNY' and date='2004-01-01'
2024-05-11 04:15:01,679 Calling get_price with symbol='HMNY' and date='2024-05-11'
2024-05-11 04:15:03,448 Calling calculate with a=2275, b=100 and op='mul'
2024-05-11 04:15:04,363 Calling calculate with a=0.00019999999494757503, b=100 and op='mul'
********************************************************************************
['user', 'system', 'assistant', 'function', 'assistant', 'function', 'assistant', 'function', 'assistant', 'function', 'assistant']
********************************************************************************
If you bought 100 shares of HMNY stock on 2004-01-01, you would have paid $2,275 for them. 

As of today (2024-05-11), each share of HMNY stock is worth $0.0002. Therefore, your 100 shares would be worth $0.02.

It looks like OpenAI can be unstable at times...