Spaces:
Sleeping
Sleeping
File size: 7,040 Bytes
e968f96 338773f a84e18a e968f96 338773f e968f96 a84e18a e968f96 a84e18a e968f96 a84e18a e968f96 a84e18a e968f96 a84e18a e968f96 64dd87a b5250c3 1d7954e 64dd87a b5250c3 1d7954e b5250c3 1d7954e b5250c3 1d7954e b5250c3 9ef3c92 |
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
import streamlit as st
markdown=f"""
Start Here: https://autogen-studio.com/autogen-studio-ui
# Installation and Running Autogen:
1. create a directory: mkdir autogen
2. Go there and create a startup script. C:\\\\Users\\\\aaron\\\\autogen>notepad setkey.bat
3. Add three lines for the key(s) and launch:
- set OPENAI_API_ORG=[your org key] https://platform.openai.com/settings/organization/general
- set OPENAI_API_KEY=[your openai key] https://platform.openai.com/api-keys
- autogenstudio ui
4. pip install autogenstudio
5. run your startup script setkey.bat
6. Browse to localhost http://localhost:8081/
# Sample Output:

# Note that the code generated is shown for the solution.



```python
userproxy ( to primary_assistant )
What is the stock price of UNH today and the data. List top three change days this year and show stock on those dates.
primary_assistant ( to userproxy )
To retrieve the current stock price of UnitedHealth Group Incorporated (UNH) and to list the top three change days this year with the stock prices on those dates, we will need to use a financial data API. One such API is provided by Alpha Vantage. We will need to:
Use the Alpha Vantage API to get the current stock price of UNH.
Use the same API to get the daily time series data for UNH for this year.
Analyze the daily time series data to find the top three days with the largest price changes.
Output the current stock price and the stock prices on the top three change days.
First, we need to install the alpha_vantage Python package if it's not already installed. Then we can write a Python script to perform the above tasks. Please execute the following shell command to install the alpha_vantage package:
hide
pip install alpha_vantage --quiet
After the installation is complete, let me know, and I will provide the Python code to retrieve and analyze the stock data.
userproxy ( to primary_assistant )
exitcode: 1 (execution failed)
Code output:
.\ : File C:\Users\aaron.autogenstudio\files\user\198fb9b77fb10d10bae092e
ea5789295\f0858f85-f619-46df-aea9-541ac845fcc4\20240521_05-45-22\ cannot
be loaded. The file C:\Users\aaron.autogenstudio\files\user\198fb9b77fb10d10bae092eea5789295\f0858f85-f619-46df-aea9-5
41ac845fcc4\20240521_05-45-22\ is not digitally signed. You cannot run
this script on the current system. For more information about running scripts and setting execution policy, see
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
.\
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
primary_assistant ( to userproxy )
It seems that there was an issue with the execution of the shell command due to the PowerShell execution policy on your system. PowerShell is preventing the execution of scripts that are not digitally signed.
Let's try a different approach by using Python directly to install the alpha_vantage package. Please execute the following Python code to install the package:
hide
# filename: install_alpha_vantage.py
import subprocess
import sys
def install_package(package):
subprocess.check_call([sys.executable, "-m", "pip", "install", package, "--quiet"])
install_package("alpha_vantage")
Save the above code to a file named install_alpha_vantage.py and run it. This should install the alpha_vantage package without encountering the PowerShell execution policy issue. After running the code, let me know if the installation was successful.
userproxy ( to primary_assistant )
exitcode: 0 (execution succeeded)
Code output:
primary_assistant ( to userproxy )
Great, the alpha_vantage package has been successfully installed. Now, we can proceed with the Python code to retrieve the current stock price of UNH and the top three change days this year.
Please note that to use the Alpha Vantage API, you will need an API key. If you don't have one, you can obtain it for free by signing up on the Alpha Vantage website.
Once you have the API key, execute the following Python code to get the stock data:
hide
# filename: get_stock_data.py
from alpha_vantage.timeseries import TimeSeries
import datetime
# Replace 'YOUR_API_KEY' with your actual Alpha Vantage API key
API_KEY = 'YOUR_API_KEY'
def get_stock_data(symbol):
ts = TimeSeries(key=API_KEY, output_format='pandas')
data, meta_data = ts.get_daily(symbol=symbol, outputsize='full')
# Filter data for the current year
current_year = datetime.datetime.now().year
data['year'] = data.index.year
data = data[data['year'] == current_year]
# Calculate the daily changes
data['change'] = data['4. close'].diff().abs()
# Sort by the largest changes and take the top 3
top_changes = data.nlargest(3, 'change')
# Get the most recent stock price
latest_price = data.iloc[0]['4. close']
return latest_price, top_changes
# Replace 'UNH' with the symbol of the stock you are interested in
symbol = 'UNH'
latest_price, top_changes = get_stock_data(symbol)
print(f"Current stock price of {symbol}: ${latest_price:.2f}")
print("\nTop three change days this year:")
print(top_changes[['4. close', 'change']])
Make sure to replace 'YOUR_API_KEY' with your actual Alpha Vantage API key. Save the code to a file named get_stock_data.py and run it to get the stock information for UNH.
Please let me know the output after running the code.
userproxy ( to primary_assistant )
exitcode: 0 (execution succeeded)
Code output:
Current stock price of UNH: $517.23
Top three change days this year:
4. close change
date
2024-04-01 489.70 31.56
2024-04-15 445.63 23.26
2024-01-24 513.23 19.83
primary_assistant ( to userproxy )
The output indicates the following:
The current stock price of UnitedHealth Group Incorporated (UNH) is $517.23.
The top three days with the largest price changes this year are:
April 1, 2024, with a closing price of $489.70 and a change of $31.56.
April 15, 2024, with a closing price of $445.63 and a change of $23.26.
January 24, 2024, with a closing price of $513.23 and a change of $19.83.
These are the days when UNH stock experienced the most significant price changes in the current year up to the present date.
If you need further assistance or have any other questions, feel free to ask. Otherwise, if you're satisfied with the assistance, please let me know, and we can conclude this session.
TERMINATE
Results (3 files)```
"""
st.markdown(markdown) |