当前位置:   article > 正文

微软最强AutoGen入门与示例twoagent.py运行

autogen

AutoGen目前正火热

AutoGen是一个让LLM(大语言模型)相互聊天过程中解决任务的框架,可定制、可对话,并允许人类无缝参与。
直接上干货,了解AutoGen,并能运行。

AutoGen主要资源

参考博客:https://blog.csdn.net/techforward/article/details/133863795,了解主要介绍,下面直接给出所需步骤。

  1. 代码地址 https://github.com/microsoft/autogen.git
  2. 帮助文档:https://microsoft.github.io/autogen/docs/Getting-Started

运行环境搭建

  1. pip install pyautogen
  2. 修改autogen\test下的twoagent.py文件
  3. 代码修改如下:
#注释原代码config_list = 所在行
#config_list = config_list_from_json(env_or_file="OAI_CONFIG_LIST")
#加入如下语句,注意api_key后面的key为你要用的openai的key,默认是14天有效的那个。后面*号是因为太长了省略了,这个一定要用有效的,重要的东西重复一遍。
config_list = [{'model': 'gpt-3.5-turbo', 'api_key': 'eyJhbGciOiJSUzI1NiIsInR5c***'},]
  • 1
  • 2
  • 3
  • 4

如图所示:
在这里插入图片描述

运行代码

前提安装好python3.8以上版本。在AutoGen目录下执行:

  1. pip install pyautogen
  2. python test/twoagent.py
  3. 正常会输出如下内容:
user_proxy (to assistant):

Plot a chart of NVDA and TESLA stock price change YTD.

--------------------------------------------------------------------------------
assistant (to user_proxy):

To plot the chart of NVDA and TESLA stock price change Year-to-Date (YTD), we need to first collect the historical stock prices for both NVDA and TESLA. There are various APIs and libraries available to fetch stock prices. In this case, I will use the yfinance library to retrieve the stock prices.

Here is the Python code to accomplish this:

```python
# filename: stock_price_chart.py

import yfinance as yf
import matplotlib.pyplot as plt

# Define the ticker symbols for NVDA and TSLA
nvda = yf.Ticker("NVDA")
tsla = yf.Ticker("TSLA")

# Get the historical stock prices for YTD
nvda_hist = nvda.history(period="YTD")
tsla_hist = tsla.history(period="YTD")

# Plotting the stock price changes
fig, ax = plt.subplots()
ax.plot(nvda_hist.index, nvda_hist["Close"], label="NVDA")
ax.plot(tsla_hist.index, tsla_hist["Close"], label="TESLA")
ax.set_title("YTD Stock Price Change")
ax.set_xlabel("Date")
ax.set_ylabel("Stock Price")
ax.legend()

# Display the chart
plt.show()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

Please make sure you have the following libraries installed:

  • yfinance
  • matplotlib

You can install the libraries using pip:

pip install yfinance matplotlib
  • 1

Save the code in a file named stock_price_chart.py, then execute it. The code will retrieve the historical stock prices for NVDA and TESLA for the current year and plot a chart showing the stock price changes.

Let me know if you need any further assistance!


Provide feedback to assistant. Press enter to skip and use auto-reply, or type ‘exit’ to end the conversation:
以上为输出内容;

  1. 直接回车结束代码
  2. 在目录下新建一个文件名称为:stock_price_chart.py
  3. 执行:pip install yfinance matplotlib
  4. 执行:python stock_price_chart.py
  5. 输出如下:可拉长显示,这样横坐标日期就没有重叠了。
    股价对比图
    总结:如果想尝试更多功能,可以继续运行里面的范例,最好的4的token,方便使用。

参考如下:

[1]: https://github.com/microsoft/autogen
[2]: https://microsoft.github.io/autogen/docs/Getting-Started

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/815877
推荐阅读
相关标签
  

闽ICP备14008679号