相信很多人已經開始使用autgen
我們也來試試到底有多神
(圖片出自: https://github.com/microsoft/autogen/ )
首先先config OpenAI chatgpt model & api key
import autogen config_list=[ |
接下來建立機器人
llm_config = {
"request_timeout": 600, "seed": 42, "config_list": config_list, "temperature": 0, } # create a UserProxyAgent instance named "user_proxy" |
然後就交給機器人囉
以下是運行的解結果log,可以看到
user_proxy(第一隻機器人)跟第二隻機器人說,"Plot a chart of 'TSMC','TSLA' and 'MSFT' stock price current YTD."
coder,也就是第二個機器人在收到命令後,將他理解的文句,說一邊,並且提出方法,使用"yfinance" 去撈資料,也一併將如何繪製時間與股價的代碼也列出來給我們
user_proxy (to coder): Plot a chart of 'TSMC','TSLA' and 'MSFT' stock price current YTD.
--------------------------------------------------------------------------------
coder (to user_proxy): To plot a chart of 'TSMC', 'TSLA', and 'MSFT' stock prices for the current year to date (YTD),
we can use the `yfinance` library in Python.
This library allows us to download stock data from Yahoo Finance, which we can then plot.
Here is the Python code to do this:
```python # filename: stock_price_plot.py
import yfinance as yf import matplotlib.pyplot as plt import datetime
# Get today's date today = datetime.date.today()
# Get the start of the year start_of_year = datetime.date(today.year, 1, 1)
# Download stock data
tsmc = yf.download('TSM', start=start_of_year, end=today)
tsla = yf.download('TSLA', start=start_of_year, end=today)
msft = yf.download('MSFT', start=start_of_year, end=today)
# Plot data plt.figure(figsize=(14, 7)) plt.plot(tsmc['Close'], label='TSMC')
plt.plot(tsla['Close'], label='TESLA') plt.plot(msft['Close'], label='MICROSOFT')
plt.title('Stock Prices YTD') plt.xlabel('Date') plt.ylabel('Price (USD)')
plt.legend()
plt.grid(True)
plt.show()
|
運行結果如下,非常令人滿意,
除了繪圖時間與股價圖之外、另外也幫我們將python 程式代碼+圖表也一併存檔下來,貼心
但是我們可能沒有注意到
這樣的使用autogen其實也使用到chatgpt 4 的服務,服務不是免費的,列出費用給大家參考
若各位節的費用太高,可以改試試gat 3.5 turbo費用會小一點點
但是小弟試運行才發現,coder提供的程式碼,有一個研究的缺點,就是我們得自行提供股價與時間的資料,並請依照他的檔名存成stock_data.csv
可是我們事情怎麼會知道,要怎麼跟他溝通,並讓她知道股價資料放哪哩?!!
user_proxy (to coder): Plot a chart of 'TSMC','TSLA' and 'MSFT' stock price current YTD. -------------------------------------------------------------------------------- To plot a chart of the stock prices for 'TSMC', 'TSLA', and 'MSFT' year-to-date (YTD), we can use the `pandas` and `matplotlib` libraries in Python. Here's the code: ```python # Define the stock symbols # Read the stock data from a CSV file (replace 'stock_data.csv' with the actual file name) # Filter the data for the specified symbols and YTD dates # Pivot the data to have symbols as columns and dates as rows # Plot the chart |
剛剛的嘗試發現使用gpt3.5 turbo的費用確實小很多,大約gpt 4 $0.11 vs gpt 3.5 turbo <$0.01
可是卻只做一半,沒有如期完成可以囉,真的讓人有一點點理解,gpt 4 高收費的理由
end
留言列表