{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "7114fd1c-671c-4616-a4fc-19ec40a8423f", "metadata": {}, "outputs": [], "source": [ "from langchain.prompts import FewShotPromptTemplate\n", "from langchain.llms import OpenAIChat\n", "from langchain.callbacks import get_openai_callback\n", "from langchain.chains import LLMChain\n", "import requests\n", "import datetime\n", "\n", "\n", "\n", "%reload_ext lab_black" ] }, { "cell_type": "code", "execution_count": null, "id": "295d30ed-ba52-43ab-8df0-4c7b8f9b663e", "metadata": {}, "outputs": [], "source": [ "# url = 'https://newsapi.org/v2/sources'\n", "# params = {\n", "# 'apiKey': NEWS_API_KEY\n", "# }\n", "\n", "# response = requests.get(url, params=params)\n", "\n", "# sources = response.json()['sources']\n", "\n", "# for source in sources:\n", "# print(source['id'], '-', source['name'])" ] }, { "cell_type": "code", "execution_count": null, "id": "122e6596-286b-4fbf-b29f-f1e8db9434f6", "metadata": {}, "outputs": [], "source": [ "finance_regulatory_bodies = [\n", " \"Consumer Financial Protection Bureau\",\n", " \"CFPB\",\n", " \"Federal Reserve System\",\n", " \"The Fed\",\n", " \"Securities and Exchange Commission\",\n", " \"SEC\",\n", " \"Commodity Futures Trading Commission\",\n", " \"CFTC\",\n", " \"National Credit Union Administration\",\n", " \"NCUA\",\n", " \"Office of the Comptroller of the Currency\",\n", " \"OCC\",\n", " \"Financial Industry Regulatory Authority\",\n", " \"FINRA\",\n", " \"Financial Stability Oversight Council\",\n", " \"FSOC\",\n", " \"Internal Revenue Service\",\n", " \"IRS\",\n", "]\n", "\n", "finance_regulatory_bodies = \" OR \".join(\n", " [f\"'{s.lower()}'\" for s in finance_regulatory_bodies]\n", ")\n", "\n", "query = f\"(regulation OR compliance OR legislation) AND (cfpb OR finra OR OCC)\"\n", "# \"law OR regulation OR policy OR compliance OR legislation OR government oversight\"\n", "# categories = \"business,technology,general\" # \"category\": categories,\n", "from_date = datetime.datetime.now() - datetime.timedelta(days=7)\n", "to_date = datetime.datetime.now()\n", "\n", "url = \"https://newsapi.org/v2/everything\"\n", "params = {\n", " \"q\": query,\n", " \"from\": from_date,\n", " \"to\": to_date,\n", " \"language\": \"en\",\n", " \"sortBy\": \"publishedAt\",\n", " \"pageSize\": 100,\n", " \"page\": 1,\n", " \"apiKey\": NEWS_API_KEY,\n", "}\n", "\n", "response = requests.get(url, params=params)" ] }, { "cell_type": "code", "execution_count": null, "id": "6fb7e1b8-642a-456b-a161-91f6993edfc8", "metadata": {}, "outputs": [], "source": [ "articles = response.json()[\"articles\"]" ] }, { "cell_type": "code", "execution_count": null, "id": "6f4784f7-61d4-4d8f-8b55-29c1373c2cb7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "How about some more federal laws to fix banking? - Americanthinker.com - 2023-03-18T05:00:00Z\n", "Bragar Eagel & Squire, P.C. Reminds Investors That Class Action Lawsuits Have Been Filed Against Block, Atlassian, PLDT, and Global Payments and Encourages Investors to Contact the Firm - GlobeNewswire - 2023-03-18T01:00:00Z\n", "Innovating during a regulatory wave - VentureBeat - 2023-03-17T20:07:00Z\n", "Consumer Watchdog Wants to Know Who's Watching Your Internet Behavior - Investopedia - 2023-03-17T15:26:26Z\n", "Regulators Shut Down Banks, Raising Questions About Neutrality - Forbes - 2023-03-17T11:30:00Z\n", "Moomoo's Continuous Innovation Journey on AWS - PRNewswire - 2023-03-17T11:00:00Z\n", "Regulatory Failure 101: What the Collapse of Silicon Valley Bank Reveals - ProPublica - 2023-03-17T11:00:00Z\n", "So Where Were the Regulators? - The Atlantic - 2023-03-17T11:00:00Z\n", "Buy-backs of shares in CoinShares International Limited - Marketscreener.com - 2023-03-17T08:01:01Z\n", "Buy-backs of shares in CoinShares International Limited - Yahoo Entertainment - 2023-03-17T08:00:00Z\n", "Buy-backs of shares in CoinShares International Limited - GlobeNewswire - 2023-03-17T08:00:00Z\n", "Bank Runs, Busts, and Bailouts Are Back. What It Means for Regulations and the Industry. - Barron's - 2023-03-17T06:52:39Z\n", "AdvisorVault Partners With Compliant Workspace to Help FINRA Firms Achieve 17a-4 Compliance on Microsoft 365 - Yahoo Entertainment - 2023-03-17T01:06:00Z\n", "Silicon Valley Bank ex-CEO backed Big Tech lobbying groups that targeted Dodd Frank, sought corporate tax cuts - CNBC - 2023-03-16T17:02:22Z\n", "Blockchain Association seeks info from Fed, FDIC, and OCC on 'de-banking' crypto firms - Cointelegraph - 2023-03-16T16:45:00Z\n", "Baldwin Mader Law Group Wins $6.1 Million Arbitration Award Against Fisker, Inc. - Yahoo Entertainment - 2023-03-16T15:45:00Z\n", "What is Trading Software Development? - Thefrisky.com - 2023-03-16T14:30:58Z\n", "INX ANNOUNCES INTEGRATION WITH POLYGON - Yahoo Entertainment - 2023-03-16T13:48:00Z\n", "AI CEO on GPT-4: This Can Get “Super-Dangerous Very Quickly” - Futurism - 2023-03-16T13:43:43Z\n", "INX ANNOUNCES INTEGRATION WITH POLYGON - PR Newswire UK - 2023-03-16T13:31:00Z\n", "INX ANNOUNCES INTEGRATION WITH POLYGON - Marketscreener.com - 2023-03-16T13:14:03Z\n", "INX ANNOUNCES INTEGRATION WITH POLYGON - Yahoo Entertainment - 2023-03-16T13:13:00Z\n", "INX ANNOUNCES INTEGRATION WITH POLYGON - PRNewswire - 2023-03-16T13:13:00Z\n", "CFPB Launches Long Overdue Probe Of Unaccountable Data Broker Market - Techdirt - 2023-03-16T12:36:58Z\n", "Hashdex Celebrates Six-Month Anniversary of World’s First Bitcoin Futures ETF Registered Solely Under ‘33 Act by Ringing NYSE Opening Bell - GlobeNewswire - 2023-03-16T12:35:00Z\n", "GigaStar, a Startup Bringing YouTube Creators and Fans Together as Partners, Completes a $4.8 Million Seed Round - PRNewswire - 2023-03-16T11:00:00Z\n", "Ray Dalio Commentary: What I Think About the Silicon Valley Bank Situation - Yahoo Entertainment - 2023-03-15T22:41:59Z\n", "Sterling Bancorp, Inc. Enters Into Plea Agreement with DOJ; Resolves DOJ Investigation of the Company Relating to the Advantage Loan Program; Revises Fourth Quarter and Full Year 2022 Unaudited Financial Results - Marketscreener.com - 2023-03-15T21:13:02Z\n", "Retail Traders Left Hanging As Brokers Halt Transactions On Silicon Valley Bank Just As Bets Are Set To Pay Off - Forbes - 2023-03-15T19:27:06Z\n", "How the 2008 financial crisis fuels today's populist politics - PBS - 2023-03-15T17:58:06Z\n", "Patti Brennan Ranks # 5 in Barron s Top 1,200 Financial Advisors State by State - GlobeNewswire - 2023-03-15T17:25:00Z\n", "Patti Brennan Ranks # 5 in Barron s Top 1,200 Financial Advisors State by State - Yahoo Entertainment - 2023-03-15T17:25:00Z\n", "GoLogiq to Acquire Institutional Investment Advisory Firm, CPG Research & Advisory, in $15 Million Merger - GlobeNewswire - 2023-03-15T17:00:00Z\n", "GoLogiq to Acquire Institutional Investment Advisory Firm, CPG Research & Advisory, in $15 Million Merger - Yahoo Entertainment - 2023-03-15T17:00:00Z\n", "Webinar: Navigating Marketing Compliance Challenges in 2023 - Performline.com - 2023-03-15T16:24:05Z\n", "Financial Regulators, Black History and Epistemic Capital - Harvard School of Engineering and Applied Sciences - 2023-03-15T13:30:43Z\n", "How the last banking tumult fuels today's populist politics - seattlepi.com - 2023-03-15T12:20:48Z\n", "How the last banking tumult fuels today's populist politics - ABC News - 2023-03-15T10:32:20Z\n", "How the last banking tumult fuels today's populist politics - ABC News - 2023-03-15T10:32:12Z\n", "How the last banking tumult fuels today's populist politics - Independent - 2023-03-15T10:00:45Z\n", "How the last banking tumult fuels today's populist politics - Yahoo Entertainment - 2023-03-15T10:00:44Z\n", "Central Pacific Financial : CPF Balance Sheet Update - Marketscreener.com - 2023-03-15T00:00:07Z\n", "Bowman, The Innovation Imperative: Modernizing Traditional Banking - Federalreserve.gov - 2023-03-14T21:20:00Z\n", "SVB collapse creates rift among Democrats over 2018 banking law - Yahoo Entertainment - 2023-03-14T20:53:04Z\n", "Enterprise Health Sponsors ACOEM Ambassador Program - Yahoo Entertainment - 2023-03-14T15:42:00Z\n", "Community Reinvestment Act (CRA) Expert Sarah Brons Joins Asurity's RiskExec Team - PRNewswire - 2023-03-14T15:02:00Z\n", "Tom Oscherwitz Joins Informed.IQ as VP of Legal and Regulatory Advisor - PRNewswire - 2023-03-14T13:40:00Z\n", "Biden Highlights Dodd-Frank Repeal in Calls for Stiffer Bank Regulations - Investopedia - 2023-03-14T11:33:00Z\n", "Republicans Who Pushed for Financial Deregulation Blame Silicon Valley Bank Collapse on “Woke Agenda” - The New Republic - 2023-03-13T22:06:50Z\n", "USDC's 'Black Swan' Depegging Could Have Been Avoided With Proper Regulatory Framework - CoinDesk - 2023-03-13T21:59:35Z\n", "How Silicon Valley Bank skirted Washington's toughest banking rules - Yahoo Entertainment - 2023-03-13T21:55:01Z\n", "It’s Not Just Fraud That Chilled Crypto Regulation - CoinDesk - 2023-03-13T20:56:08Z\n", "SVB Moral: Idiot Businesses Get a Bailout—and Indebted College Kids Get Lawsuits - The New Republic - 2023-03-13T20:23:18Z\n", "Fed announces regulatory review of Silicon Valley Bank failure - Yahoo Entertainment - 2023-03-13T20:22:21Z\n", "INX Announces the Listing of Hashrate Asset Group's (HAG) Bitcoin Mining Security Token - Yahoo Entertainment - 2023-03-13T15:13:00Z\n", "INX Announces the Listing of Hashrate Asset Group's (HAG) Bitcoin Mining Security Token - PR Newswire UK - 2023-03-13T14:54:00Z\n", "INX Announces the Listing of Hashrate Asset Group's (HAG) Bitcoin Mining Security Token - Marketscreener.com - 2023-03-13T14:39:04Z\n", "INX Announces the Listing of Hashrate Asset Group's (HAG) Bitcoin Mining Security Token - Yahoo Entertainment - 2023-03-13T14:38:00Z\n", "INX Announces the Listing of Hashrate Asset Group's (HAG) Bitcoin Mining Security Token - PRNewswire - 2023-03-13T14:38:00Z\n", "The Impact Of Evolving Cloud Regulations On Financial Services - Forbes - 2023-03-13T12:45:00Z\n", "Bragar Eagel & Squire, P.C. Reminds Investors That Class Action Lawsuits Have Been Filed Against Global Payments, Caribou, Inspirato, and Kornit and Encourages Investors to Contact the Firm - GlobeNewswire - 2023-03-13T01:00:00Z\n" ] } ], "source": [ "for article in articles:\n", " print(article[\"title\"], \"-\", article[\"source\"][\"name\"], \"-\", article[\"publishedAt\"])" ] }, { "cell_type": "markdown", "id": "b3758b70-c1f8-41dd-8a2b-5d000e851fed", "metadata": {}, "source": [ "# Langchain" ] }, { "cell_type": "code", "execution_count": null, "id": "a21af9b3-6376-4226-81df-377d774f4a99", "metadata": {}, "outputs": [], "source": [ "llm = OpenAIChat(temperature=0.0)" ] }, { "cell_type": "code", "execution_count": null, "id": "87936389-312c-49de-a88d-40a7ad82a06d", "metadata": {}, "outputs": [], "source": [ "# Also, I don't need any article that talks about regulation but rather something that discusses a regulatory change that might impact my work" ] }, { "cell_type": "code", "execution_count": null, "id": "aae3283e-b042-4618-9070-073303985527", "metadata": {}, "outputs": [], "source": [ "prefix = \"\"\"You are a news recommender and your job is to look at an article and decide if I would find it useful or not.\n", "I work in a bank/credit card company and I'm looking for news articles that deal with changes in the regulatory environment. \n", "It could be articles about regulatory authorities like CFPB or OCC announcing changes in regulation or a new focus areas. \n", "Or articles like the president or senate or government announcing new regulations. \n", "Or peer financial institutions getting fined for violations. \n", "To reiterate I'm especially looking for articles in the finance, fin-tech, banking and credit card sector. \n", "**I don't need think pieces or opinion pieces or editorials that talk about the consequences of a regulation but just the ones that talk about objective changes in the regulatory environment that might impact my work**\n", "I'm going to pass in a few headlines. Can you just respond with \"relevant\" or \"not relevant\" for the headlines I send you?\"\"\"\n", "\n", "examples = [\n", " {\n", " \"headline\": \"CFPB Launches Inquiry Into the Business Practices of Data Brokers\",\n", " \"publisher\": \"CFPB\",\n", " \"answer\": \"relevant\",\n", " },\n", " {\n", " \"headline\": \"OCC Issues Prohibition Order, Fines Former Wells Fargo Executive $17 Million in Settlement\",\n", " \"publisher\": \"NYT\",\n", " \"answer\": \"relevant\",\n", " },\n", " {\n", " \"headline\": \"Innovating during a regulatory wave\",\n", " \"publisher\": \"Venture beat\",\n", " \"answer\": \"not relevant\",\n", " },\n", "]" ] }, { "cell_type": "code", "execution_count": null, "id": "07b77a00-3f61-4d4f-9ff5-fbe330e7e6b2", "metadata": {}, "outputs": [], "source": [ "example_prompt = PromptTemplate(\n", " input_variables=[\"headline\", \"publisher\", \"answer\"],\n", " template=\"Headline: {headline}\\nPublisher: {publisher}\\nAnswer: {answer}\",\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "da1d7f5d-bd1b-489f-ac80-804ccc241fa4", "metadata": {}, "outputs": [], "source": [ "prompt = FewShotPromptTemplate(\n", " prefix=prefix,\n", " examples=examples,\n", " example_prompt=example_prompt,\n", " suffix=\"Headline: {headline}\\nPublisher: {publisher}\\nAnswer: \",\n", " input_variables=[\"headline\", \"publisher\"],\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "51216122-1424-4f85-9d72-a094f644f90c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "You are a news recommender and your job is to look at an article and decide if I would find it useful or not.\n", "I work in a bank/credit card company and I'm looking for news articles that deal with changes in the regulatory environment. \n", "It could be articles about regulatory authorities like CFPB or OCC announcing changes in regulation or a new focus areas. \n", "Or articles like the president or senate or government announcing new regulations. \n", "Or peer financial institutions getting fined for violations. \n", "To reiterate I'm especially looking for articles in the finance, fin-tech, banking and credit card sector. \n", "**I don't need think pieces or opinion pieces or editorials that talk about the consequences of a regulation but just the ones that talk about objective changes in the regulatory environment that might impact my work**\n", "I'm going to pass in a few headlines. Can you just respond with \"relevant\" or \"not relevant\" for the headlines I send you?\n", "\n", "\n", "\n", "Headline: CFPB Launches Inquiry Into the Business Practices of Data Brokers\n", "Publisher: CFPB\n", "Answer: relevant\n", "\n", "Headline: OCC Issues Prohibition Order, Fines Former Wells Fargo Executive $17 Million in Settlement\n", "Publisher: NYT\n", "Answer: relevant\n", "\n", "Headline: Innovating during a regulatory wave\n", "Publisher: Venture beat\n", "Answer: not relevant\n", "\n", "Headline: CFPB Launches Inquiry Into the Business Practices of Data Brokers\n", "Publisher: CFPB\n", "Answer: \n" ] } ], "source": [ "print(\n", " prompt.format(\n", " **{\n", " \"headline\": \"CFPB Launches Inquiry Into the Business Practices of Data Brokers\",\n", " \"publisher\": \"CFPB\",\n", " }\n", " )\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "d1bcdf3a-c41c-4815-a802-7903e6ce43b2", "metadata": {}, "outputs": [], "source": [ "news_predictor_chain = LLMChain(prompt=prompt, llm=llm)" ] }, { "cell_type": "code", "execution_count": null, "id": "c1dc07e5-e2fb-4a5b-8078-de83a3c8e1d4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'headline': 'Ray Dalio Commentary: What I Think About the Silicon Valley Bank Situation',\n", " 'publisher': 'Yahoo Entertainment',\n", " 'text': 'not relevant'}" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "news_predictor_chain.run(\n", " {\n", " \"headline\": \"Ray Dalio Commentary: What I Think About the Silicon Valley Bank Situation\",\n", " \"publisher\": \"Yahoo Entertainment\",\n", " }\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "91d5dfc2-08ed-417e-abc6-cd961ac62a79", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'headline': 'Financial Regulators, Black History and Epistemic Capital',\n", " 'publisher': 'Harvard School of Engineering',\n", " 'text': 'not relevant'}" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "news_predictor_chain.run(\n", " {\n", " \"headline\": \"Financial Regulators, Black History and Epistemic Capital\",\n", " \"publisher\": \"Harvard School of Engineering\",\n", " }\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "b2b868b0-1d7e-4074-b55d-fab0e8b12bf6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'headline': 'Agencies Issue Joint Statement on Crypto-Asset Risks to Banking Organizations',\n", " 'publisher': 'OCC',\n", " 'text': 'relevant'}" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "news_predictor_chain(\n", " {\n", " \"headline\": \"Agencies Issue Joint Statement on Crypto-Asset Risks to Banking Organizations\",\n", " \"publisher\": \"OCC\",\n", " }\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "8d18d0b9-274d-4ae9-8c0e-1dc1e6f42add", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'headline': 'Acting Comptroller of the Currency Testifies on Regulatory Priorities',\n", " 'publisher': 'The Washington Post',\n", " 'text': 'relevant'}" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "news_predictor_chain.run(\n", " {\n", " \"headline\": \"Acting Comptroller of the Currency Testifies on Regulatory Priorities\",\n", " \"publisher\": \"The Washington Post\",\n", " }\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "fe55edc1-43f3-4e13-a3f7-53f24593a0a5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'headline': 'The Impact Of Evolving Cloud Regulations On Financial Services',\n", " 'publisher': 'Forbes',\n", " 'text': 'relevant'}" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "news_predictor_chain.run(\n", " {\n", " \"headline\": \"The Impact Of Evolving Cloud Regulations On Financial Services\",\n", " \"publisher\": \"Forbes\",\n", " }\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "d0a45c24-dfff-4af3-897f-5182c21f1d06", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sum([1, 2])" ] }, { "cell_type": "code", "execution_count": null, "id": "e4bc7325-6748-4837-b6b0-bff4467c077b", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:news_ai]", "language": "python", "name": "conda-env-news_ai-py" } }, "nbformat": 4, "nbformat_minor": 5 }