├── Python └── PythonLesson1.pdf ├── README.md └── examples ├── ai_receptionist ├── demo.py └── resume_data.txt ├── ai_secretary ├── ai_secretary_main.py └── good_sample.csv ├── autogen ├── air1.py └── main.py ├── autogen_amazon ├── amazon_price_check.py ├── main_az.py └── scrape_price.py ├── autogen_ebay_slack ├── demo.py └── ebay_price_scraper_working.py ├── autogen_stock_apis ├── main.py └── stock_apis.py ├── craigslist └── main.py ├── easy_web_scraper ├── .env └── url_query.py ├── facebook_marketplace └── main.py ├── five_libraries └── main.py ├── flet_example └── main.py ├── google_maps └── main.py ├── gpt_intro └── gpt4.py ├── llama_local_code_reading └── main.py ├── reddit_sentiment ├── env_example └── main.py ├── reservation_scraper └── reservation_scraper.py ├── resume_grader └── main.py ├── southwest_chatgpt_vision └── main.py └── ticket_prices_chrome_extension ├── content.js ├── manifest.json ├── popup.html └── popup.js /Python/PythonLesson1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaredcrace/cracecasts/a57239232a61331f07f3320950b8bb7a0ef43858/Python/PythonLesson1.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cracecasts 2 | Repository for the CraceCasts YouTube channel https://www.youtube.com/@CraceCasts 3 | -------------------------------------------------------------------------------- /examples/ai_receptionist/demo.py: -------------------------------------------------------------------------------- 1 | import autogen 2 | from icecream import ic 3 | 4 | DATA_FILE = "resume_data.txt" 5 | 6 | def start_ai(): 7 | autogen.ChatCompletion.start_logging() 8 | 9 | # read in data 10 | with open(DATA_FILE, 'r') as file: 11 | resume_data = file.read() 12 | 13 | # load config list from json file 14 | config_list = autogen.config_list_from_json(env_or_file="OAI_CONFIG_LIST.json") 15 | 16 | # config for autogen's enhanced inference API which is compatible with OpenAI API 17 | llm_config={ 18 | "request_timeout": 600, 19 | "seed": 34, # for caching and reproducibility 20 | "config_list": config_list, # which models to use 21 | "temperature": 0, # for sampling 22 | } 23 | 24 | # create an AssistantAgent instance named "assistant" 25 | agent_assistant = autogen.AssistantAgent( 26 | name="agent_assistant", 27 | llm_config=llm_config, 28 | system_message=f""" 29 | You are a receptionist for an an expert whose resume is as follows: 30 | 31 | Resume: 32 | {resume_data} 33 | 34 | Your responsibilities are in the following order: 35 | 36 | 1. You are responsible for vetting potential clients and weeding out those clients that would not be a good fit for this expert. 37 | You must ask questions to the potential client to determine if they are a good candidate. 38 | 39 | 2. Once you have determined the client is a good fit, your job is to receive their intake information. 40 | You are to gather the following information from them: 41 | - reason for meeting with the expert 42 | - name 43 | - phone number 44 | - address 45 | If you have any problems, please respond with the problem and how you can be helped to resolve the problem. 46 | Whenever you are asked, please send the message TERMINATE 47 | """ 48 | ) 49 | 50 | # create a UserProxyAgent that acts on the humans behalf 51 | agent_proxy = autogen.UserProxyAgent( 52 | name="agent_proxy", 53 | human_input_mode="ALWAYS", # NEVER, TERMINATE, or ALWAYS 54 | # TERMINATE - human input needed when assistant sends TERMINATE 55 | max_consecutive_auto_reply=10, 56 | is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"), 57 | code_execution_config={ 58 | "work_dir": "agent_output", # path for file output of program 59 | "use_docker": False, # True or image name like "python:3" to use docker image 60 | }, 61 | llm_config=llm_config, 62 | ) 63 | 64 | agent_proxy.initiate_chat( 65 | agent_assistant, 66 | message=""" 67 | I am a new client and that needs to meet with an expert. Please ask me as many questions as you need to determine 68 | if I'm a good potential client. 69 | 70 | If I am not a good fit for this expert, please tell me and end the chat. 71 | If I am a good fit, please gather any needed information. 72 | 73 | After the information is gathered, please provide a summary of the data in the following format: 74 | ---SUMMARY_START--- 75 | name: 76 | phone: 77 | address:
78 | reason: 79 | ---SUMMARY_END--- 80 | """, 81 | ) 82 | 83 | logs = autogen.ChatCompletion.logged_history 84 | 85 | # write all data to a file 86 | with open("log_data.txt", "w") as file: 87 | line_split = str(logs).split("\\\\n") 88 | for i in line_split: 89 | file.write(i + "\n") 90 | 91 | autogen.ChatCompletion.stop_logging() 92 | 93 | start_ai() 94 | 95 | -------------------------------------------------------------------------------- /examples/ai_receptionist/resume_data.txt: -------------------------------------------------------------------------------- 1 | Jane Doe 2 | Attorney 3 | jane.doe@email.com 4 | (123) 456-7890 5 | Atlanta, GA 6 | 7 | LinkedIn 8 | BAR ADMISSIONS 9 | Georgia 10 | 11 | EDUCATION 12 | Juris Doctorate 13 | University of Georgia 14 | 2009 - 2011 15 | Atlanta, GA 16 | Bachelor of Science 17 | Finance 18 | Georgia State University 19 | 2004 - 2008 20 | Atlanta, GA 21 | 22 | SKILLS 23 | Legal Research 24 | Technical Writing 25 | Client Relations 26 | Negotiations 27 | Ethics 28 | Debate 29 | Client Collaboration 30 | Time Management 31 | 32 | CERTIFICATIONS 33 | Certified International Trade 34 | Law Specialist (CITLS) - IIEI 35 | Accredited Legal 36 | Professional (ALP) - 37 | Association for Legal 38 | Professionals 39 | 40 | CAREER SUMMARY 41 | Objective and thorough attorney with 11 years of demonstrated 42 | law firm experience. Seeking an opportunity to represent clients 43 | during the reunification process, educate clients on U.S. 44 | immigration laws, and provide compassionate legal advice as an 45 | attorney for Georgia Asylum & Immigration Network. 46 | 47 | WORK EXPERIENCE 48 | Attorney 49 | McArther Law Firm 50 | 2017 - current Atlanta, GA 51 | Defended 12 clients annually before a judge or jury, 52 | obtaining the desired case outcome 91% of the time 53 | Advised 3-5 clients per week on litigation and complex legal 54 | issues, resulting in an overall 77% CSAT score 55 | Dedicated 15+ hours per week to researching state laws and 56 | challenges to proposed legislature 57 | Developed case strategies in collaboration with clients, 58 | ensuring priorities were met while limiting financial strain, 59 | resulting in 84% positive feedback 60 | Associate Attorney 61 | Edmonson Law Firm, LLC 62 | 63 | 2015 - 2017 Atlanta, GA 64 | Prepared key numerical analyses that aided in the best 65 | case outcomes for 65+ litigations 66 | Generated 20+ types of legal documents, including 67 | contracts, production services agreements, distribution 68 | agreements, and other commercial contracts 69 | Counseled 28% of firm clients on legal options beyond a 70 | trial, increasing customer satisfaction scores by 33% 71 | Collaborated with 7 partners to conduct and consolidate 72 | legal research, increasing efficiency by 14% 73 | Associate Attorney 74 | Adams & Reese, LLP 75 | 76 | 2011 - 2015 Atlanta, GA 77 | Crafted 100+ legal documents weekly, including affidavits, 78 | motions, settlements, and client correspondence 79 | Developed legal arguments and prepared documents for 80 | defense in 32 cases 81 | Communicated with an average of 6 weekly clients to 82 | advise on complex legal issues and resolve conflicts 83 | Ensured clients balanced their financial wellbeing and 84 | desired outcomes when pursuing legal action, reducing the 85 | rate that cases went to trial by 45% -------------------------------------------------------------------------------- /examples/ai_secretary/ai_secretary_main.py: -------------------------------------------------------------------------------- 1 | from langchain.chat_models.openai import ChatOpenAI 2 | from langchain.schema import HumanMessage, SystemMessage 3 | from icecream import ic 4 | import flet as ft 5 | import dotenv 6 | 7 | dotenv.load_dotenv() 8 | 9 | BACKGROUND = ''' 10 | You are an assistant that will be used to schedule appointments for an attorney. 11 | You have been provided csv formatted data that is his schedule and you are in charge of booking appointments from clients. 12 | His working hours are Mon through Friday from 8am - 5pm. Do no book any times outside of this. 13 | ''' 14 | 15 | DATA_FILE= "good_sample.csv" 16 | 17 | def ask_ai(prompt): 18 | openai = ChatOpenAI(model_name="gpt-3.5-turbo", max_tokens=2048, temperature=0) 19 | 20 | # load schedule for context into model 21 | with open(DATA_FILE, 'r') as file: 22 | file_data = file.read() 23 | 24 | # build the system message of the prompt 25 | full_system_msg = f""" 26 | {BACKGROUND} 27 | 28 | His schedule is: 29 | {file_data} 30 | """ 31 | 32 | ic(full_system_msg) 33 | ic(prompt) 34 | 35 | messages = [ 36 | SystemMessage(content=full_system_msg), 37 | HumanMessage(content=prompt) 38 | ] 39 | 40 | # call to openai 41 | response = openai(messages) 42 | 43 | ic(response) 44 | return response.content 45 | 46 | def main_ai(from_user): 47 | response = "Nothing" 48 | 49 | determine_schedule_question = f''' 50 | Does the following statement ask to schedule an appointment? Please answer the following way: 51 | - If the statement is asking to schedule an appointment, has a start time, and has an end time. Respond with: YES 52 | - If the statement is asking to schedule an appointment, but it does not have a start or end time. Respond with: INCOMPLETE 53 | - If the statement is not asking to schedule an appointment. Respond with: NO 54 | All responses should only be one word. 55 | 56 | Statement: 57 | {from_user} 58 | ''' 59 | 60 | general_question = f''' 61 | Background: 62 | {BACKGROUND} 63 | 64 | Please answer the following or reply to the given statement: 65 | {from_user} 66 | ''' 67 | 68 | # Ask AI: is this a question to book an appointment? Using AI here as a powerful helper function. 69 | is_schedule_question = ask_ai(determine_schedule_question) 70 | ic(is_schedule_question) 71 | 72 | if 'NO' in is_schedule_question: 73 | ic('answer was no') 74 | 75 | # Ask AI: ask this general question or reply to this given statement 76 | general_ans = ask_ai(general_question) 77 | ic(general_ans) 78 | response = general_ans 79 | 80 | elif 'INCOMPLETE' in is_schedule_question: 81 | ic('answer was incomplete') 82 | 83 | # let user know 84 | response = 'you did not provide the right input such as date, start and end time' 85 | 86 | elif 'YES' in is_schedule_question: 87 | # ask the AI to format the request pulling out the answer 88 | csv_extraction = f''' 89 | I'm going to provide a statement and I need you to create a csv output string of the answer. 90 | The time should be of this format: 2023-10-20T13:00:00Z. 91 | The 1 line csv string should adhere to the following example: "title", "start time", "end time". 92 | The title should include the name and contact information of the person. 93 | 94 | Statement: 95 | {from_user} 96 | ''' 97 | # send question to 98 | csv_ans = ask_ai(csv_extraction) 99 | 100 | # append to the file 101 | with open(DATA_FILE, 'a') as file: 102 | file.write(csv_ans + '\n') 103 | 104 | response = "successfully scheduled" 105 | 106 | else: 107 | error_case = 'Error - did not understand anything' 108 | ic(error_case) 109 | response = error_case 110 | 111 | return response 112 | 113 | 114 | ############################################### 115 | # flet GUI 116 | ############################################### 117 | def first_app(page: ft.Page): 118 | 119 | client_ask = ft.TextField(label="client ask", autofocus=True) 120 | client_answer = ft.Column() 121 | 122 | def btn_click(e): 123 | ic(client_ask.value) 124 | response = "-"*112 + "\n" + main_ai(client_ask.value) 125 | client_answer.controls.append(ft.Text(f"{response}")) 126 | client_ask.value = "" 127 | page.update() 128 | client_ask.focus() 129 | 130 | def btn_clear(e): 131 | client_answer.controls.clear() 132 | page.update() 133 | 134 | page.add( 135 | client_ask, 136 | ft.ElevatedButton(f"Ask Secretary", on_click=btn_click), 137 | ft.ElevatedButton(f"Clear", on_click=btn_clear), 138 | client_answer, 139 | ) 140 | 141 | ft.app(target=first_app, view=ft.AppView.WEB_BROWSER) 142 | -------------------------------------------------------------------------------- /examples/ai_secretary/good_sample.csv: -------------------------------------------------------------------------------- 1 | title,start_time,end_time 2 | Client Consultation,2023-10-21T08:00:00Z,2023-10-21T09:00:00Z 3 | Document Drafting,2023-10-21T09:30:00Z,2023-10-21T10:30:00Z 4 | Court Hearing,2023-10-21T11:00:00Z,2023-10-21T12:00:00Z 5 | Negotiation Meeting,2023-10-21T01:00:00Z,2023-10-21T02:00:00Z 6 | Evidence Review,2023-10-21T03:00:00Z,2023-10-21T04:00:00Z 7 | Case Strategy Session,2023-10-22T08:00:00Z,2023-10-22T09:00:00Z 8 | Witness Interview,2023-10-22T09:30:00Z,2023-10-22T10:30:00Z 9 | Contract Review,2023-10-22T11:00:00Z,2023-10-22T12:00:00Z 10 | Settlement Discussion,2023-10-22T01:00:00Z,2023-10-22T02:00:00Z 11 | Legal Research,2023-10-22T03:00:00Z,2023-10-22T04:00:00Z 12 | Client Follow-up,2023-10-23T08:00:00Z,2023-10-23T09:00:00Z 13 | Debrief with Associates,2023-10-23T09:30:00Z,2023-10-23T10:30:00Z 14 | Mediation Session,2023-10-23T11:00:00Z,2023-10-23T12:00:00Z 15 | Deposition,2023-10-23T01:00:00Z,2023-10-23T02:00:00Z 16 | Case Review,2023-10-23T03:00:00Z,2023-10-23T04:00:00Z 17 | Briefing Preparation,2023-10-24T08:00:00Z,2023-10-24T09:00:00Z 18 | Client Onboarding,2023-10-24T09:30:00Z,2023-10-24T10:30:00Z 19 | Arbitration,2023-10-24T11:00:00Z,2023-10-24T12:00:00Z 20 | Contract Negotiations,2023-10-24T01:00:00Z,2023-10-24T02:00:00Z 21 | Legal Training,2023-10-24T03:00:00Z,2023-10-24T04:00:00Z 22 | Case Update Meeting,2023-10-25T08:00:00Z,2023-10-25T09:00:00Z 23 | Document Signing,2023-10-25T09:30:00Z,2023-10-25T10:30:00Z 24 | Litigation Strategy,2023-10-25T11:00:00Z,2023-10-25T12:00:00Z 25 | Client Debrief,2023-10-25T01:00:00Z,2023-10-25T02:00:00Z 26 | Discovery Review,2023-10-25T03:00:00Z,2023-10-25T04:00:00Z 27 | -------------------------------------------------------------------------------- /examples/autogen/air1.py: -------------------------------------------------------------------------------- 1 | # filename: airbnb_search.py 2 | 3 | import requests 4 | from bs4 import BeautifulSoup 5 | 6 | # Step 1: Go to Airbnb 7 | url = "https://www.airbnb.com/" 8 | 9 | # Step 2: Search for an Austin Texas stay from Oct 10, 2023 - Oct 11, 2023 10 | search_params = { 11 | "location": "Austin, Texas", 12 | "checkin": "2023-10-10", 13 | "checkout": "2023-10-11" 14 | } 15 | 16 | response = requests.get(url, params=search_params) 17 | response.raise_for_status() 18 | 19 | # Step 3: Gather the results 20 | soup = BeautifulSoup(response.content, "html.parser") 21 | results = soup.find_all("div", class_="c4mnd7m dir dir-ltr")[:10] 22 | 23 | # Step 4: Print the results 24 | for result in results: 25 | print(result.get_text()) -------------------------------------------------------------------------------- /examples/autogen/main.py: -------------------------------------------------------------------------------- 1 | import autogen 2 | 3 | config_list = autogen.config_list_from_json(env_or_file="OAI_CONFIG_LIST.json") 4 | 5 | llm_config={ 6 | "request_timeout": 600, 7 | "seed": 44, # for caching and reproducibility 8 | "config_list": config_list, # which models to use 9 | "temperature": 0, # for sampling 10 | } 11 | 12 | agent_assistant = autogen.AssistantAgent( 13 | name="agent_assistant", 14 | llm_config=llm_config, 15 | ) 16 | 17 | agent_proxy = autogen.UserProxyAgent( 18 | name="agent_proxy", 19 | human_input_mode="NEVER", # NEVER, TERMINATE, or ALWAYS 20 | # TERMINATE - human input needed when assistant sends TERMINATE 21 | max_consecutive_auto_reply=10, 22 | is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"), 23 | code_execution_config={ 24 | "work_dir": "agent_output", # path for file output of program 25 | "use_docker": False, # True or image name like "python:3" to use docker image 26 | }, 27 | llm_config=llm_config, 28 | system_message="""Reply TERMINATE if the task has been solved at full satisfaction. 29 | Otherwise, reply CONTINUE, or the reason why the task is not solved yet.""" 30 | ) 31 | 32 | agent_proxy.initiate_chat( 33 | agent_assistant, 34 | message="""I need you to write a python script that will do the following: 35 | 1. go to airbnb 36 | 2. search for an Austin Texas stay from Oct 10, 2023 - Oct 11, 2023 37 | 3. gather the results, no more than 10. The class html div to search for is "c4mnd7m dir dir-ltr". 38 | 4. print that result to the screen 39 | """, 40 | ) 41 | 42 | -------------------------------------------------------------------------------- /examples/autogen_amazon/amazon_price_check.py: -------------------------------------------------------------------------------- 1 | # filename: amazon_price_check.py 2 | 3 | from selenium import webdriver 4 | from selenium.webdriver.common.by import By 5 | from selenium.webdriver.common.keys import Keys 6 | from selenium.webdriver.chrome.service import Service 7 | from webdriver_manager.chrome import ChromeDriverManager 8 | import time 9 | 10 | # Set up the driver 11 | driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) 12 | 13 | # Go to Amazon 14 | driver.get("https://www.amazon.com") 15 | 16 | # Find the search box, enter "iPhone 13", and search 17 | search_box = driver.find_element(By.ID, "twotabsearchtextbox") 18 | search_box.send_keys("iPhone 13") 19 | search_box.send_keys(Keys.RETURN) 20 | 21 | # Wait for the page to load 22 | time.sleep(3) 23 | 24 | # Find the price of the first result 25 | price = driver.find_element(By.CSS_SELECTOR, ".a-price-whole").text 26 | 27 | # Print the price 28 | print("The price of the iPhone 13 on Amazon is: $" + price) 29 | 30 | # Close the driver 31 | driver.quit() -------------------------------------------------------------------------------- /examples/autogen_amazon/main_az.py: -------------------------------------------------------------------------------- 1 | import autogen 2 | 3 | config_list = autogen.config_list_from_json(env_or_file="OAI_CONFIG_LIST.json") 4 | 5 | llm_config={ 6 | "request_timeout": 600, 7 | "seed": 50, # for caching and reproducibility 8 | "config_list": config_list, # which models to use 9 | "temperature": 0, # for sampling 10 | } 11 | 12 | # create an AssistantAgent instance named "assistant" 13 | agent_assistant = autogen.AssistantAgent( 14 | name="agent_assistant", 15 | llm_config=llm_config, 16 | ) 17 | 18 | # create a UserProxyAgent that acts on the humans behalf 19 | agent_proxy = autogen.UserProxyAgent( 20 | name="agent_proxy", 21 | human_input_mode="NEVER", # NEVER, TERMINATE, or ALWAYS 22 | # TERMINATE - human input needed when assistant sends TERMINATE 23 | max_consecutive_auto_reply=10, 24 | is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"), 25 | code_execution_config={ 26 | "work_dir": "agent_output", # path for file output of program 27 | "use_docker": False, # True or image name like "python:3" to use docker image 28 | }, 29 | llm_config=llm_config, 30 | system_message="""Reply TERMINATE if the task has been solved at full satisfaction. 31 | Otherwise, reply CONTINUE, or the reason why the task is not solved yet.""" 32 | ) 33 | 34 | agent_proxy.initiate_chat( 35 | agent_assistant, 36 | message="""I'd like for you to create a python script that meets the following requirements: 37 | - uses the selenium python package 38 | - searches for an iphone 14 at amazon 39 | - finds the price of the iphone 14 40 | - prints that result to the screen 41 | """, 42 | ) 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /examples/autogen_amazon/scrape_price.py: -------------------------------------------------------------------------------- 1 | # filename: scrape_price.py 2 | 3 | import requests 4 | from bs4 import BeautifulSoup 5 | 6 | def get_price(url): 7 | headers = { 8 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"} 9 | 10 | response = requests.get(url, headers=headers) 11 | soup = BeautifulSoup(response.text, 'html.parser') 12 | 13 | try: 14 | price = soup.find("span", attrs={'class':'a-offscreen'}).string 15 | except AttributeError: 16 | price = "Could not find the price. The HTML structure of the page might be different from what the script expects." 17 | 18 | return price 19 | 20 | url = 'http://example.com/product-page' 21 | print(get_price(url)) -------------------------------------------------------------------------------- /examples/autogen_ebay_slack/demo.py: -------------------------------------------------------------------------------- 1 | import autogen 2 | 3 | # load config list from json file 4 | config_list = autogen.config_list_from_json(env_or_file="OAI_CONFIG_LIST.json") 5 | 6 | # config for autogen's enhanced inference API which is compatible with OpenAI API 7 | llm_config={ 8 | "request_timeout": 600, 9 | "seed": 50, # for caching and reproducibility 10 | "config_list": config_list, # which models to use 11 | "temperature": 0, # for sampling 12 | } 13 | 14 | # create an AssistantAgent instance named "assistant" 15 | agent_assistant = autogen.AssistantAgent( 16 | name="agent_assistant", 17 | llm_config=llm_config, 18 | ) 19 | 20 | # create a UserProxyAgent that acts on the humans behalf 21 | agent_proxy = autogen.UserProxyAgent( 22 | name="agent_proxy", 23 | human_input_mode="NEVER", # NEVER, TERMINATE, or ALWAYS 24 | # TERMINATE - human input needed when assistant sends TERMINATE 25 | max_consecutive_auto_reply=10, 26 | is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"), 27 | code_execution_config={ 28 | "work_dir": "agent_output", # path for file output of program 29 | "use_docker": False, # True or image name like "python:3" to use docker image 30 | }, 31 | llm_config=llm_config, 32 | system_message="""Reply TERMINATE if the task has been solved at full satisfaction. 33 | Otherwise, reply CONTINUE, or the reason why the task is not solved yet.""" 34 | ) 35 | 36 | 37 | agent_proxy.initiate_chat( 38 | agent_assistant, 39 | message="""I'd like for you to create a python script that meets the following requirements: 40 | - uses the selenium python package 41 | - uses the presence_of_element_located method from selenium 42 | - does not use the method find_element_by_css_selector 43 | - searches iphone 14 at ebay 44 | - finds all the prices by looking for the class "s-item__price" 45 | - prints to the screen all the prices it finds 46 | - check the length of the text of the price before printing or sending to slack, just skip if the length is less than 1 47 | - sends all the prices to a slack channel 48 | - the slack url to use is '' 49 | """, 50 | ) 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /examples/autogen_ebay_slack/ebay_price_scraper_working.py: -------------------------------------------------------------------------------- 1 | # filename: ebay_price_scraper.py 2 | 3 | from selenium import webdriver 4 | from selenium.webdriver.common.by import By 5 | from selenium.webdriver.support.ui import WebDriverWait 6 | from selenium.webdriver.support import expected_conditions as EC 7 | import requests 8 | import time 9 | 10 | def send_to_slack(text): 11 | webhook_url = '' 12 | slack_data = {'text': text} 13 | response = requests.post( 14 | webhook_url, json=slack_data, 15 | headers={'Content-Type': 'application/json'} 16 | ) 17 | if response.status_code != 200: 18 | raise ValueError( 19 | 'Request to slack returned an error %s, the response is:\n%s' 20 | % (response.status_code, response.text) 21 | ) 22 | 23 | driver = webdriver.Chrome() # or webdriver.Chrome(), depending on your browser 24 | 25 | driver.get("https://www.ebay.com") 26 | 27 | search_box = WebDriverWait(driver, 10).until( 28 | EC.presence_of_element_located((By.ID, "gh-ac")) 29 | ) 30 | search_box.send_keys("iphone 14") 31 | search_box.submit() 32 | 33 | time.sleep(5) # wait for the page to load 34 | 35 | prices = WebDriverWait(driver, 10).until( 36 | EC.presence_of_all_elements_located((By.CLASS_NAME, "s-item__price")) 37 | ) 38 | 39 | for price in prices: 40 | price_text = price.text 41 | if len(price_text) > 1: 42 | print(price_text) 43 | send_to_slack(price_text) 44 | 45 | driver.quit() -------------------------------------------------------------------------------- /examples/autogen_stock_apis/main.py: -------------------------------------------------------------------------------- 1 | import autogen 2 | 3 | # load config list from json file 4 | config_list = autogen.config_list_from_json(env_or_file="OAI_CONFIG_LIST.json") 5 | 6 | # config for autogen's enhanced inference API which is compatible with OpenAI API 7 | llm_config={ 8 | "request_timeout": 600, 9 | "seed": 50, # for caching and reproducibility 10 | "config_list": config_list, # which models to use 11 | "temperature": 0, # for sampling 12 | } 13 | 14 | # create an AssistantAgent instance named "assistant" 15 | agent_assistant = autogen.AssistantAgent( 16 | name="agent_assistant", 17 | llm_config=llm_config, 18 | ) 19 | 20 | # create a UserProxyAgent that acts on the humans behalf 21 | agent_proxy = autogen.UserProxyAgent( 22 | name="agent_proxy", 23 | human_input_mode="NEVER", # NEVER, TERMINATE, or ALWAYS 24 | # TERMINATE - human input needed when assistant sends TERMINATE 25 | max_consecutive_auto_reply=10, 26 | is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"), 27 | code_execution_config={ 28 | "work_dir": "agent_output", # path for file output of program 29 | "use_docker": False, # True or image name like "python:3" to use docker image 30 | }, 31 | llm_config=llm_config, 32 | system_message="""Reply TERMINATE if the task has been solved at full satisfaction. 33 | Otherwise, reply CONTINUE, or the reason why the task is not solved yet.""" 34 | ) 35 | 36 | agent_proxy.initiate_chat( 37 | agent_assistant, 38 | message="""I'd like for you to create a python script that meets the following requirements: 39 | - searches for the ford stock on Finnhub, Alpha Vantage, Quandl, IEX Cloud, Twelve Data, and Yahoo Finance 40 | - for Alpha Vantage use the TIME_SERIES_DAILY function 41 | - for Twelve Data use the interval "1day" 42 | - compares all the prices 43 | - print which price is lowest at which exchange 44 | - sends the lowest price and echange name to slack 45 | - the slack url to use is '> 64 | You are an expert in software engineering. You will use the provided context to answer the user's 65 | questions. Read the given context before answering the question and think step by step. If you are 66 | unable to answer the question based on the provided context, please inform the user of what context 67 | is missing. Do not use any other information for answering the user. 68 | <> 69 | 70 | Context: {context} 71 | User: {question} 72 | 73 | [/INST] 74 | """ 75 | 76 | QA_CHAIN_PROMPT = PromptTemplate( 77 | input_variables=["context", "question"], 78 | template=template, 79 | ) 80 | 81 | # Docs 82 | question = "How can I initialize a ReAct agent?" 83 | docs = retriever.get_relevant_documents(question) 84 | print(docs) 85 | 86 | # Chain 87 | chain = load_qa_chain(llm, chain_type="stuff", prompt=QA_CHAIN_PROMPT) 88 | 89 | chain({"input_documents": docs, "question": question}, return_only_outputs=True) 90 | 91 | -------------------------------------------------------------------------------- /examples/reddit_sentiment/env_example: -------------------------------------------------------------------------------- 1 | OPENAI_API_KEY="" 2 | 3 | CLIENT_ID="" 4 | CLIENT_SECRET= "" 5 | APP_NAME="" 6 | 7 | 8 | -------------------------------------------------------------------------------- /examples/reddit_sentiment/main.py: -------------------------------------------------------------------------------- 1 | import praw 2 | import os 3 | import dotenv 4 | import openai 5 | import time 6 | from icecream import ic 7 | 8 | dotenv.load_dotenv() 9 | openai.api_key = os.environ.get("OPENAI_API_KEY") 10 | 11 | def reddit_search(praw_obj, subreddits): 12 | all_text = [] 13 | for subreddit in subreddits: 14 | time.sleep(1) 15 | ic(subreddit) 16 | 17 | # top post for the week limited to just 1 18 | for post in praw_obj.subreddit(subreddit).top(limit=1, time_filter='week'): 19 | title = post.title 20 | all_text.append(title) 21 | 22 | # controls the "Morecomments" object to load more comments than was done by default 23 | # this parameter can be None to load all comments 24 | post.comments.replace_more(limit=3) 25 | comments_array = post.comments[:2] 26 | for comment in comments_array: 27 | body = comment.body 28 | ic(subreddit, title) 29 | ic(body) 30 | all_text.append(body) 31 | 32 | return ' '.join(all_text) 33 | 34 | def engage_ai(reddit_data): 35 | system_message = f""" 36 | You are an expert at reading reddit posts and understanding crypto currency trends and topics. 37 | """ 38 | 39 | user_message = f""" 40 | Analyze the following Reddit threads and identify which cryptocurrencies are mentioned the most 41 | frequently. Provide a summary of the top cryptocurrencies discussed, along with the context or 42 | sentiment of the discussion where possible. 43 | 44 | Here are the threads: 45 | {reddit_data} 46 | """ 47 | 48 | messages=[ 49 | {"role": "system", "content": f"{system_message}"}, 50 | {"role": "user", "content": f"{user_message}"}, 51 | ] 52 | 53 | ic(f"calling openai with prompt: {user_message}") 54 | ans = openai.ChatCompletion.create( 55 | model="gpt-3.5-turbo", 56 | max_tokens=2048, 57 | messages=messages, 58 | ) 59 | 60 | res = ans["choices"][0]["message"]["content"] 61 | ic(res) 62 | 63 | return res 64 | 65 | if __name__ == "__main__": 66 | # Set up your credentials 67 | client_id = os.environ.get("CLIENT_ID") 68 | client_secret = os.environ.get("CLIENT_SECRET") 69 | user_agent = os.environ.get("APP_NAME") 70 | 71 | # Initialize praw instance 72 | praw_obj = praw.Reddit( 73 | client_id=client_id, 74 | client_secret=client_secret, 75 | user_agent=user_agent 76 | ) 77 | 78 | # Define subreddits 79 | subreddits = [ 80 | 'CryptoCurrency', 81 | 'Bitcoin', 82 | 'ethereum', 83 | 'CryptoMarkets', 84 | 'CryptoMoonShots' 85 | ] 86 | 87 | ic(f"searching {subreddits}") 88 | 89 | # get data from reddit 90 | response = reddit_search(praw_obj, subreddits) 91 | ic(len(response)) 92 | 93 | # send to the AI 94 | chatgpt_res = engage_ai(response) 95 | ic(chatgpt_res) 96 | -------------------------------------------------------------------------------- /examples/reservation_scraper/reservation_scraper.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | import requests 6 | from icecream import ic 7 | 8 | # Slack webhook URL 9 | SLACK_WEBHOOK_URL = " response.json()) 25 | .then(data => { 26 | console.log('Email sent successfully:', data); 27 | }) 28 | .catch(error => { 29 | console.error('Error sending email:', error); 30 | }); 31 | } 32 | 33 | chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { 34 | if (request.action === "findPrices") { 35 | console.log("findPrices called") 36 | 37 | setInterval(function() { 38 | const button = document.getElementById('quickpick-buy-button-qp-0'); 39 | if (button) { 40 | let parts = button.innerHTML.split('$'); 41 | let numericPart = parts[1]; 42 | let price = Number(numericPart); 43 | if (price < 275) { 44 | sendElasticEmail('Price update', `New price is: ${price}`); 45 | } 46 | } else { 47 | console.log('Button not found'); 48 | } 49 | }, 10000); // 10K milliseconds = 10 seconds 50 | } 51 | }); 52 | -------------------------------------------------------------------------------- /examples/ticket_prices_chrome_extension/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifest_version": 3, 3 | "name": "Ticket Tracker", 4 | "version": "1.0", 5 | "permissions": ["activeTab"], 6 | "action": { 7 | "default_popup": "popup.html" 8 | }, 9 | "content_scripts": [ 10 | { 11 | "matches": [""], 12 | "js": ["content.js"] 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /examples/ticket_prices_chrome_extension/popup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Ticket Finder 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /examples/ticket_prices_chrome_extension/popup.js: -------------------------------------------------------------------------------- 1 | document.getElementById('findPrices').addEventListener('click', () => { 2 | console.log("hello from popup.js file") 3 | chrome.tabs.query({active: true, currentWindow: true}, (tabs) => { 4 | chrome.tabs.sendMessage(tabs[0].id, { action: "findPrices" }); 5 | }); 6 | }); 7 | 8 | --------------------------------------------------------------------------------