<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: br-raia</title>
    <description>The latest articles on Forem by br-raia (@brraia).</description>
    <link>https://forem.com/brraia</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1434860%2F9d3bb645-809b-43a1-8f2c-87f41bb6d750.png</url>
      <title>Forem: br-raia</title>
      <link>https://forem.com/brraia</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/brraia"/>
    <language>en</language>
    <item>
      <title>Using AI to facilitate backend logic</title>
      <dc:creator>br-raia</dc:creator>
      <pubDate>Wed, 07 Aug 2024 00:26:01 +0000</pubDate>
      <link>https://forem.com/brraia/using-ai-to-facilitate-backend-logic-3ahb</link>
      <guid>https://forem.com/brraia/using-ai-to-facilitate-backend-logic-3ahb</guid>
      <description>&lt;p&gt;Hey DEV community,&lt;/p&gt;

&lt;p&gt;I guess everyone has heard of GitHub Copilot right now, and many of you are using it (well, I am) to help with code development.&lt;/p&gt;

&lt;p&gt;In addition, I wanted to use AI to hold much of the backend logic. To test that, I decided to build a Stock Analysis application. &lt;/p&gt;

&lt;p&gt;Here is what I used and did:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I created a frontend where my users could enter the Stock Symbol they want to receive the analysis&lt;/li&gt;
&lt;li&gt;I created a Python backend with a few endpoints (to send data and receive data)&lt;/li&gt;
&lt;li&gt;I used my account on &lt;a href="https://raia.live" rel="noopener noreferrer"&gt;Raia&lt;/a&gt; to create the stock analysis process&lt;/li&gt;
&lt;li&gt;The analysis process created on Raia then calls back the backend Python service, sending the result&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is the code for my backend:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import logging
import uuid
from flask import render_template, request, jsonify
from app import app
import requests

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

users = {}
user_analysis_results = {}

@app.route('/')
def index():
    logger.info("Rendering index page")
    return render_template('index.html')

@app.route('/submit-symbol', methods=['POST'])
def submit_symbol():
    try:
        user_id = str(uuid.uuid4())
        stock_symbol = request.form['stock_symbol']
        users[user_id] = stock_symbol
        logger.info(f"Received symbol: {stock_symbol} for generated user ID: {user_id}")
        # Trigger external workflow here
        trigger_workflow()
        return jsonify({"message": "Symbol received", "user_id": user_id, "stock_symbol": stock_symbol})
    except Exception as e:
        logger.error(f"Error in submit_symbol: {e}")
        return jsonify({"error": str(e)}), 500

def trigger_workflow():
    try:
        external_workflow_url = "https://hooks.raia.live/hooks/catch/xNVvu31VX9EItm4"
        response = requests.post(external_workflow_url)
        logger.info(f"Workflow triggered with status code: {response.status_code}")
        return response.status_code
    except Exception as e:
        logger.error(f"Error in trigger_workflow: {e}")
        return None

@app.route('/get-symbols', methods=['GET'])
def get_symbols():
    try:
        return jsonify(users)
    except Exception as e:
        logger.error(f"Error in get_symbols: {e}")
        return jsonify({"error": str(e)}), 500

@app.route('/receive-analysis', methods=['POST'])
def receive_analysis():
    try:
        user_id = request.json['user_id']
        analysis_result = request.json['analysis_result']
        user_analysis_results[user_id] = analysis_result
        logger.info(f"Received analysis for user: {user_id}")
        return jsonify({"message": "Analysis received", "user_id": user_id})
    except Exception as e:
        logger.error(f"Error in receive_analysis: {e}")
        return jsonify({"error": str(e)}), 500

@app.route('/get-analysis/&amp;lt;user_id&amp;gt;', methods=['GET'])
def get_analysis(user_id):
    try:
        analysis_result = user_analysis_results.get(user_id, "")
        return jsonify({"user_id": user_id, "analysis_result": analysis_result})
    except Exception as e:
        logger.error(f"Error in get_analysis: {e}")
        return jsonify({"error": str(e)}), 500
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Stock Analysis
&lt;/h2&gt;

&lt;p&gt;On the &lt;a href="https://raia.live" rel="noopener noreferrer"&gt;Raia&lt;/a&gt; front, here is the sample stock analysis workflow I created:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F48vr28rdctslrdcfmcz6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F48vr28rdctslrdcfmcz6.png" alt="Raia Workflow" width="800" height="690"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Here is what this workflow does:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Receives the stock symbol from the application&lt;/li&gt;
&lt;li&gt;Gathers data like the company financials, analyst recommendations, stock history, and company news&lt;/li&gt;
&lt;li&gt;Perform the analysis based on all this data and gives me an estimated trend for the stock&lt;/li&gt;
&lt;li&gt;Sends it back to the application/the user&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By using this approach, I created a stock analysis "platform" having to handle very few details on the application side and using AI to help me handle the heavy logic, data integration, and data analysis&lt;/p&gt;

&lt;p&gt;I also used AI to help me create the frontend and backend code.&lt;/p&gt;

&lt;p&gt;Overall, this took me about 30 minutes to create everything, which would have taken me way more to create everything if I had to handle everything myself, including the analysis&lt;/p&gt;

&lt;p&gt;Is that the future? Have you all considered using AI to handle the backend logic for your applications instead of having to build it all in?&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>ai</category>
      <category>python</category>
    </item>
    <item>
      <title>Using AI on top of your DB</title>
      <dc:creator>br-raia</dc:creator>
      <pubDate>Thu, 18 Apr 2024 21:24:37 +0000</pubDate>
      <link>https://forem.com/brraia/using-ai-on-top-of-your-db-2mlb</link>
      <guid>https://forem.com/brraia/using-ai-on-top-of-your-db-2mlb</guid>
      <description>&lt;p&gt;Hey everyone.&lt;/p&gt;

&lt;p&gt;I've worked on many projects where users need access to the data hosted in the Postgres DB (or whatever other DB) for whatever reason (monitor utilization, issues, etc). I also spent a lot of time trying to automate analysis and reports using the data in the DBs&lt;/p&gt;

&lt;p&gt;Seeing what AI could do, I decided to put this together and wanted to see if you are open to providing feedback on the approach and if this is something you find helpful &lt;/p&gt;

&lt;p&gt;&lt;a href="https://ooo.mmhmm.app/watch/z_qKix6EGHLb9YCxBeKoFD"&gt;You can watch a 3 min demo here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://raia.live"&gt;I've made the product available here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any constructive feedback is very much appreciated!&lt;/p&gt;

</description>
      <category>ai</category>
      <category>database</category>
      <category>postgres</category>
      <category>datascience</category>
    </item>
  </channel>
</rss>
