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

Enhanced model client supported for reasoning models #5161

Open
ekzhu opened this issue Jan 23, 2025 · 2 comments
Open

Enhanced model client supported for reasoning models #5161

ekzhu opened this issue Jan 23, 2025 · 2 comments

Comments

@ekzhu
Copy link
Collaborator

ekzhu commented Jan 23, 2025

Reasoning models such as DeepSeek-R1 produces

<think></think>

tags before producing the final output. Consider a new class ReasoningChatCompletionClient with enhanced support for reasoning models. Alternatively, update CreateResult to include additional fields such as think or thoughts, or a list of content rather than a single content.

Related #5155

Example output from DeepSeek-R1:7b

>>> Write a python script to plot nvida stock price in the last year.
<think>
Okay, so I need to write a Python script to plot the NVIDIA stock price
for the last year. Hmm, where do I start? Well, first, I think I'll need
some data about the stock prices over time. I remember that there's
something called pandas and yfinance which can fetch financial data from
Yahoo Finance. Maybe I can use yfinance because it seems more
straightforward.

So, step one: install the necessary libraries. I know I have to use pandas
and matplotlib for plotting. Oh right, and yfinance too. So I should run
pip install pandas yfinance matplotlib if they aren't already installed.

Next, once those are installed, I'll need to import them in my script.
I'll import pandas as pd, yfinance as yf, and matplotlib.pyplot as plt.

Now, for fetching the data. The user wants the last year's worth of data.
So I can use yfinance's download method. I'll set the period parameter to
'1y' which should give me one year's data. The ticker is 'NVDA' for
NVIDIA. So something like df = yf.download('NVDA', period='1y').

Once I have the data, it's a DataFrame. I need to make sure it's sorted by
date so that plotting works correctly over time. So maybe
df.sort_values('Date') will help.

Plotting part: Using matplotlib. I'll create a figure and set its size for
better readability. Then plot the Open and Close columns against the Date.
Maybe using kind='line' or just plot() directly. Wait, perhaps using ax =
df.plot(x='Date', y=['Open', 'Close']) would be good.

I should also add labels to axes and a title to make it clear what the
graph is showing. So ax.set_xlabel('Year'), ax.set_ylabel('Stock Price
($)'), and a title like 'NVIDIA Stock Price (NVDA) - 1 Year'.

Hmm, I wonder if adding grid lines would improve readability. Maybe
ax.grid(True) with some linestyle and alpha to make it subtle.

Then, display the plot using plt.show() at the end.

Wait, what about potential issues? Like missing data in the DataFrame. I
should handle that by dropping rows with NaN values before plotting. So
after fetching the data, df.dropna() might be necessary to avoid any
errors or gaps in the line plot.

Also, maybe check if there are enough trading days in the dataset for a
full year. If not, it's okay because we're using the available data.

Putting it all together, I think this script should work. Let me write it
down step by step as per my thoughts.
</think>

To plot the NVIDIA (NVDA) stock price over the last year, you'll need to
use Python with the required libraries: pandas for data handling, yfinance
to fetch the stock data from Yahoo Finance, and matplotlib for plotting.

Here's a script that accomplishes this:

```python
# Import necessary libraries
import pandas as pd
import yfinance as yf
import matplotlib.pyplot as plt

# Fetch NVIDIA stock data for the last year
nvd_data = yf.download('NVDA', period='1y')

# Sort the data by date to ensure proper time series ordering
nvd_data.sort_values('Date', inplace=True)

# Set up the figure and axes for plotting
plt.figure(figsize=(10, 6))
ax = plt.axes()

# Plot the Open and Close prices over time
nvd_data[['Open', 'Close']].plot(x='Date', ax=ax)

# Customize the plot with labels and title
ax.set_xlabel('Year')
ax.set_ylabel('Stock Price ($)')
plt.title('NVIDIA Stock Price (NVDA) - Last Year')

# Add grid lines for better readability
ax.grid(True, linestyle='--', alpha=0.7)

# Display the plot
plt.show()
```

### Explanation:
1. **Data Fetching**: The script uses `yfinance.download()` to retrieve
historical stock data for NVIDIA (NVDA) over a period of one year.
2. **Sorting Data**: The fetched data is sorted by date to ensure
chronological order, which is essential for time series analysis and
plotting.
3. **Plotting**: The script plots both the 'Open' and 'Close' prices on
the y-axis against the dates on the x-axis using matplotlib.
4. **Customization**: The plot includes axis labels, a title, grid lines
for better readability, and uses a responsive figure size.

This script will generate a line graph showing how NVIDIA's stock opened
and closed each trading day over the past year.
@ekzhu ekzhu added this to the 0.4.x milestone Jan 23, 2025
@ekzhu ekzhu changed the title Enhanced supported for reasoning models Enhanced model client supported for reasoning models Jan 23, 2025
@lspinheiro
Copy link
Collaborator

tags before producing the final output. Consider a new class ReasoningChatCompletionClient with enhanced support for reasoning models. Alternatively, update CreateResult to include additional fields such as think or thoughts, or a list of content rather than a single content.

Would it make sense to update CreateResult to support structure outputs and let content be a subclass of a pydantic model? It could use generics in the same way tool use does now. It could facilitate processing of messages by letting other agents know what to do based on the structure

@ekzhu
Copy link
Collaborator Author

ekzhu commented Jan 26, 2025

Would it make sense to update CreateResult to support structure outputs and let content be a subclass of a pydantic model?

There is a related issue #5131. Perhaps these can be considered together as a part of the structured message story.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants