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

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***'},]

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

运行代码

前提安装好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()

Please make sure you have the following libraries installed:

  • yfinance
  • matplotlib

You can install the libraries using pip:

pip install yfinance matplotlib

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

以下是使用FFmpeg.AutoGen库在C#中进行录像和录音的基本示例代码: ```csharp using System; using FFmpeg.AutoGen; namespace FFmpegRecordingExample { class Program { static void Main(string[] args) { // Initialize FFmpeg library ffmpeg.av_register_all(); // Open video and audio devices AVFormatContext* videoInputContext = null; AVFormatContext* audioInputContext = null; if (ffmpeg.avformat_open_input(&videoInputContext, "video_device_path", null, null) != 0) { Console.WriteLine("Failed to open video device"); return; } if (ffmpeg.avformat_open_input(&audioInputContext, "audio_device_path", null, null) != 0) { Console.WriteLine("Failed to open audio device"); return; } // Create output file context AVFormatContext* outputContext = null; if (ffmpeg.avformat_alloc_output_context2(&outputContext, null, null, "output_file_path") < 0) { Console.WriteLine("Failed to create output file"); return; } // Create video and audio streams AVStream* videoStream = ffmpeg.avformat_new_stream(outputContext, null); AVStream* audioStream = ffmpeg.avformat_new_stream(outputContext, null); // Set video and audio codec parameters AVCodecContext* videoCodecContext = videoStream->codec; AVCodecContext* audioCodecContext = audioStream->codec; // Set codec parameters according to your requirements // Open video and audio codecs AVCodec* videoCodec = ffmpeg.avcodec_find_encoder(videoCodecContext->codec_id); AVCodec* audioCodec = ffmpeg.avcodec_find_encoder(audioCodecContext->codec_id); if (ffmpeg.avcodec_open2(videoCodecContext, videoCodec, null) < 0) { Console.WriteLine("Failed to open video codec"); return; } if (ffmpeg.avcodec_open2(audioCodecContext, audioCodec, null) < 0) { Console.WriteLine("Failed to open audio codec"); return; } // Read frames from video and audio devices AVPacket* videoPacket = ffmpeg.av_packet_alloc(); AVPacket* audioPacket = ffmpeg.av_packet_alloc(); while (true) { if (ffmpeg.av_read_frame(videoInputContext, videoPacket) < 0) { Console.WriteLine("Failed to read video frame"); break; } // Process and encode video frame ffmpeg.av_packet_unref(videoPacket); } while (true) { if (ffmpeg.av_read_frame(audioInputContext, audioPacket) < 0) { Console.WriteLine("Failed to read audio frame"); break; } // Process and encode audio frame ffmpeg.av_packet_unref(audioPacket); } // Write encoded packets to output file ffmpeg.av_interleaved_write_frame(outputContext, videoPacket); ffmpeg.av_interleaved_write_frame(outputContext, audioPacket); // Release resources ffmpeg.avformat_close_input(&videoInputContext); ffmpeg.avformat_close_input(&audioInputContext); ffmpeg.avcodec_close(videoCodecContext); ffmpeg.avcodec_close(audioCodecContext); ffmpeg.avformat_free_context(outputContext); } } } ``` 请注意,这只是一个基本示例,实际使用时可能需要根据您的具体需求进行更多的参数设置和错误处理。还可以根据需要进行编解码、处理和保存等操作。 在示例代码中,您需要将"video_device_path"替换为实际的视频设备路径,将"audio_device_path"替换为实际的音频设备路径,将"output_file_path"替换为实际的输出文件路径。 希望这个示例能对您有所帮助!如果您有任何更具体的问题,请随时提问。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值