<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Naoto Shibata on Medium]]></title>
        <description><![CDATA[Stories by Naoto Shibata on Medium]]></description>
        <link>https://medium.com/@naoto.shibata?source=rss-5e65a875d1d5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sFVnlX538CYKERFGjawf8A.png</url>
            <title>Stories by Naoto Shibata on Medium</title>
            <link>https://medium.com/@naoto.shibata?source=rss-5e65a875d1d5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 11:00:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@naoto.shibata/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Tutorial: Deploying a User-Authenticated Streamlit App in Just 5 Minutes.]]></title>
            <link>https://medium.com/morph-tech-blog/tutorial-deploying-a-user-authenticated-streamlit-app-in-just-5-minutes-f9d2a81b9a50?source=rss-5e65a875d1d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9d2a81b9a50</guid>
            <category><![CDATA[streamlit]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[morph]]></category>
            <category><![CDATA[streamlit-app-deployment]]></category>
            <dc:creator><![CDATA[Naoto Shibata]]></dc:creator>
            <pubDate>Tue, 25 Mar 2025 09:04:04 GMT</pubDate>
            <atom:updated>2025-03-25T09:04:04.633Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pOdfrmJZPDhRtsQLFPeqcg.jpeg" /></figure><blockquote><em>This tutorial explains how to deploy a Streamlit data app to the cloud with user authentication using Morph. With this method, there’s no need for Docker builds typically required when deploying Streamlit apps to Cloud Run. This makes sharing apps within your team simpler and quicker.</em></blockquote><p>Morph is a cloud service designed to automatically deploy internal data and AI apps from your GitHub repository to the cloud, providing built-in user authentication for easy sharing.</p><p>Now that Morph supports Streamlit deployment, this tutorial will guide you through deploying a Streamlit application. Make sure you’ve logged in to morph-data.io beforehand.</p><p><a href="https://morph-data.io/">Morph - AI-powered Data Apps with Code</a></p><h3>TL;DR</h3><p>The sample code from this tutorial is available in the repository below:</p><p><a href="https://github.com/shibatanaoto/streamlit-morph-sample">GitHub - shibatanaoto/streamlit-morph-sample</a></p><p>Fork the above repository and follow the video tutorial linked below to deploy your Streamlit app to the cloud and share it with invited members:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FW4NEHIQqQbg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DW4NEHIQqQbg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FW4NEHIQqQbg%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/92967f85f4d67e652feaae3505c91eaf/href">https://medium.com/media/92967f85f4d67e652feaae3505c91eaf/href</a></iframe><h3>Preparation</h3><p>Install the necessary packages before starting:</p><pre>pip install streamlit pandas</pre><h3>Building a Simple Streamlit App</h3><p>As this tutorial focuses mainly on deployment, we’ll use a simple Streamlit app. First, create a file named <a href="http://main.py/">main.py</a>. (Do not change this filename.)</p><pre>import streamlit as st<br>import pandas as pd<br>import numpy as np<br><br>st.markdown(&quot;# Hello world!!!&quot;)<br>df: pd.DataFrame = pd.DataFrame(<br>    np.random.randn(30, 3),<br>    columns=[&quot;x&quot;, &quot;y&quot;, &quot;z&quot;]<br>)<br>st.line_chart(df)</pre><p>Run the app locally to check it.</p><pre>streamlit run main.py</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*FrJjqHwyK1KWOR3LOhoXwg.png" /></figure><h3>Configuring Morph Deployment</h3><p>Next, create a file named `morph_project.yml` in the same directory as <a href="http://main.py/">main.py</a>. Enter the following configuration, adjusting the runtime version according to your Python environment (supported versions are Python 3.9 to 3.12):</p><pre>version: &#39;1&#39;<br><br>build:<br>  framework: streamlit<br>  runtime: python3.12<br>deployment:<br>  provider: gcp</pre><p>Detailed documentation for morph_project.yml, including how to adjust CPU and memory based on your needs, can be found here:</p><p><a href="https://docs.morph-data.io/reference/en/framework/morph-project">morph_project.yml - Docs</a></p><p>After configuration, generate a requirements.txt file with your dependencies and push the changes to GitHub:</p><pre>pip freeze &gt; requirements.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2gWdTJPCDa3Yua76c9AXVg.png" /></figure><h3>Deploying to Morph</h3><p>Log in to <a href="https://morph-data.io/">https://morph-data.io</a>, click the “+Create” button on the homepage, connect your GitHub repository, and select the repository and branch. Deployment starts automatically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ksZNZbpatCleXzOh0Y_hIw.png" /></figure><p>On the homepage, you’ll see a list of your created apps. Select the app with the same name as your repository. Under the “Deployments” tab, you can view the build status. Once it shows “Ready,” the deployment is complete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FV3gok_WktGMCn6HDpx08g.png" /></figure><p>Click the “Open” button to view the deployed app. There might be a slight cold start delay initially, but you should see your application successfully loaded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AEuMSbMAgJuY-TkPxp5yRg.png" /></figure><p>The deployed app has built-in user authentication, meaning only members invited via the “Member Access” dashboard can access it.</p><p>To invite members, use the following screen. You can invite 5 members in Free plan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tdG5aoHb-uzTPqhBuD2wPw.png" /></figure><p>Morph simplifies deploying Streamlit apps to the cloud and securely sharing them with your team.</p><p>Morph is also expanding support for full-stack frameworks like Next.js and HonoX. If you have requests for additional frameworks, feel free to reach out 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9d2a81b9a50" width="1" height="1" alt=""><hr><p><a href="https://medium.com/morph-tech-blog/tutorial-deploying-a-user-authenticated-streamlit-app-in-just-5-minutes-f9d2a81b9a50">Tutorial: Deploying a User-Authenticated Streamlit App in Just 5 Minutes.</a> was originally published in <a href="https://medium.com/morph-tech-blog">Squadbase Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tutorial: Building SQL Agent with Langchain, OpenAI and DuckDB.]]></title>
            <link>https://medium.com/morph-tech-blog/tutorial-building-sql-agent-with-langchain-openai-and-duckdb-238d80f8a180?source=rss-5e65a875d1d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/238d80f8a180</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[duckdb]]></category>
            <dc:creator><![CDATA[Naoto Shibata]]></dc:creator>
            <pubDate>Mon, 10 Mar 2025 15:37:44 GMT</pubDate>
            <atom:updated>2025-03-10T15:37:44.336Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>We will explain how to implement an SQL Agent using </em><strong><em>LangChain, OpenAI API, and DuckDB</em></strong><em>, and how to turn it into an application with </em><strong><em>Morph</em></strong><em>. This app will generate SQL queries using an LLM, execute them in DuckDB, and use the results to answer user questions.</em></blockquote><p>LangChain is an excellent framework equipped with components and third-party integrations for developing applications that leverage LLMs.</p><p>In this article, we will build an AI workflow using LangChain and construct an AI agent workflow by issuing SQL queries on CSV data with DuckDB.</p><p>This time, we will implement an agent that performs SQL-based Q&amp;A on demo data containing web advertisement traffic and order performance from the following CSV file.</p><p><a href="https://data.morphdb.io/assets/sample-data/Traffic_Orders_Demo_Data.csv">Traffic_Orders_Demo_Data.csv</a></p><p>The final output of this tutorial is available in the SQL Agent App in the following repository.</p><p><a href="https://github.com/morph-data/morph-sample-apps">https://github.com/morph-data/morph-sample-apps</a></p><h3>Setup</h3><p>Use the morph new to create a new project. It is recommended to select Poetry as the package manager.</p><pre>morph new sql-agent-app</pre><p>In pyproject.toml, set the dependencies as follows. Since DuckDB execution is handled by execute_sql included in morph-data, there is no need to install it separately.</p><pre>[tool.poetry.dependencies]<br>python = &quot;&lt;3.13,&gt;=3.9&quot;<br>morph-data = &quot;0.2.0&quot;<br>langchain = &quot;0.3.16&quot;<br>langchain-core = &quot;0.3.32&quot;<br>langchain-openai = &quot;0.3.2&quot;</pre><p>In this tutorial, set API key in .env for OpenAI API usage.</p><pre>OPENAI_API_KEY=[Put your API KEY]</pre><p>Please save the CSV data for demo data in data/Traffic_Orders_Demo_Data.csv.</p><h3>Buidling frontend</h3><p>With Morph, you can build frontend using mdx files in src/pages .</p><p>This time, we will use the &lt;Chat /&gt; component to create a chat interface built using LangChain. Since we want to view the data while asking questions, we display the data in a table format using &lt;DataTable /&gt; side by side.</p><p>We also adjust the layout using &lt;Grid /&gt; and Tailwind CSS utility classes.</p><pre># Q&amp;A Agent over SQL<br><br>You can ask questions to the SQL Agent about the data and get the answer in SQL.<br>Only admin user can ask questions to the SQL Agent.<br>p<br>&lt;Grid cols={2} className=&quot;py-4&quot;&gt;<br>    &lt;div&gt;<br>        &lt;DataTable loadData=&quot;example_data&quot; height={400} /&gt;<br>    &lt;/div&gt;<br>    &lt;div className=&quot;p-4 bg-gray-50 rounded-lg shadow-sm border border-gray-200 hover:shadow-md transition-shadow&quot;&gt;<br>        &lt;Chat postData=&quot;sql_agent&quot; /&gt;<br>    &lt;/div&gt;<br>&lt;/Grid&gt;</pre><p>You can check the pages by accessing to <a href="http://localhost:8080/">http://localhost:8080</a> after running morph serve in terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vTnZtXrD0oREC7kB2cIoqw.png" /></figure><p><strong>Building Q&amp;A Agent with Text-to-SQL Using LangChain</strong></p><p>We will use LangChain’s Runnable API and StructuredOutputParser to generate the necessary SQL queries to answer user questions. By executing these SQL queries with DuckDB and using the results, we will build an AI agent that answers user questions by leveraging the Runnable API again.</p><p>In MDX, the &lt;Chat /&gt; component automatically sends prompt and thread_id:</p><ul><li><strong>prompt</strong>: The message entered by the user.</li><li><strong>thread_id</strong>: A unique identifier for the thread displayed in the chat UI (not used in this implementation).</li></ul><p>By receiving the prompt and using it in the messages parameter for LangChain’s invoke function, we enable the interaction between the AI agent and the front-end.</p><p><strong>Generating SQL Queries and Retrieving Data Based on User Questions in LangChain</strong></p><p>First, we create a function decorated with @morph.func so that it can be handled within the Morph framework. We then initialize an instance of LangChain’s OpenAI model.</p><pre>import morph<br>from morph import MorphGlobalContext<br>from morph_lib.types import MorphChatStreamChunk<br>from langchain_openai import ChatOpenAI<br><br>@morph.func<br>def sql_agent(<br>    context: MorphGlobalContext,<br>) -&gt; Generator[MorphChatStreamChunk, None, None]:<br>    chat = ChatOpenAI(<br>        model=&quot;gpt-4o&quot;,<br>        temperature=1,<br>        streaming=False<br>    )</pre><p>For the CSV file used in this implementation, we specify the file path and data description in the system prompt. By providing format_instructions, we enable StructuredOutputParser to define the SQL output format.</p><pre>SYSTEM_TEMPLATE = &quot;&quot;&quot;Please execute SQL queries on a table named `./data/Traffic_Orders_Demo_Data.csv` in DuckDB with the following schema:<br>date: text - date<br>source: text - traffic source (Coupon, Google Organic など)<br>traffic: int - traffic count<br>orders: int - order count<br><br>This table contains traffic and order data for the marketing campaigns.<br><br>As a source, you have the following data:<br>- Coupon<br>- Google Organic<br>- Google Paid<br>- TikTok Ads<br>- Meta Ads<br>- Referral<br><br>Generate a SQL query to answer the user&#39;s question.<br>{format_instructions}<br>&quot;&quot;&quot;</pre><p>We use <strong>StructuredOutputParser</strong> to make the generated text parsable as structured data (JSON).</p><p>Then, leveraging <strong>LangChain’s Runnable API</strong>, we build a data flow for generating SQL queries.</p><pre># Setup the SQL query output parser<br>sql_schema = ResponseSchema(name=&quot;sql&quot;, description=&quot;The SQL query to execute&quot;)<br>output_parser = StructuredOutputParser.from_response_schemas([sql_schema])<br>format_instructions = output_parser.get_format_instructions()<br><br>prompt = ChatPromptTemplate.from_messages([<br>    (&quot;system&quot;, SYSTEM_TEMPLATE),<br>    (&quot;human&quot;, &quot;{question}&quot;)<br>])<br># Create the chain for SQL generation<br>chain = (<br>    {&quot;question&quot;: RunnablePassthrough(), &quot;format_instructions&quot;: lambda _: format_instructions}<br>    | prompt<br>    | chat<br>    | StrOutputParser()<br>    | output_parser<br>)</pre><p>Execute the created data flow to generate SQL. The generated SQL is streamed back to the chat using the stream_chat function.</p><pre>from morph_lib.stream import stream_chat<br><br># Generate SQL query<br>result = chain.invoke(context.vars[&quot;prompt&quot;])<br>sql = result[&quot;sql&quot;]<br>		# display generated sql<br>yield stream_chat(f&quot;&quot;&quot;<br>### SQL<br>```sql<br>{sql}<br>```<br>&quot;&quot;&quot;)</pre><p>Next, execute the generated SQL. By specifying “DUCKDB” as the second argument of execute_sql, we can use DuckDB as the engine.</p><p>The execution result is returned as a DataFrame, which is then converted into a Markdown string to be passed to the LLM.</p><pre>from morph_lib.database import execute_sql<br><br># Execute SQL and get results<br>data = execute_sql(sql, &quot;DUCKDB&quot;)<br>data_md = data.to_markdown(index=False)</pre><p><strong>Generating Responses Using SQL Results</strong></p><p>Using the retrieved results, we leverage LangChain’s <strong>Runnable API</strong> again to create an agent that constructs prompts, processes questions, and streams responses to answer user queries.</p><pre># Create analysis prompt with results<br>analysis_prompt = ChatPromptTemplate.from_messages([<br>    (&quot;system&quot;, f&quot;&quot;&quot;Please answer in markdown format.<br>You can use the following data:<br>{data_md}<br>The data is from the following SQL query:<br>{sql}<br>&quot;&quot;&quot;),<br>    (&quot;human&quot;, &quot;{question}&quot;)<br>])<br><br># Create analysis chain<br>analysis_chain = (<br>    {&quot;question&quot;: RunnablePassthrough()}<br>    | analysis_prompt<br>    | chat<br>)<br># stream analysis result<br>for chunk in analysis_chain.stream(context.vars[&quot;prompt&quot;]):<br>    if chunk.content:<br>        yield stream_chat(chunk.content)</pre><h3>All Python code</h3><pre>from typing import Generator<br><br>from langchain_openai import ChatOpenAI<br>from langchain.prompts import ChatPromptTemplate<br>from langchain.schema.output_parser import StrOutputParser<br>from langchain.schema.runnable import RunnablePassthrough<br>from langchain.output_parsers import ResponseSchema, StructuredOutputParser<br>from morph_lib.database import execute_sql<br>from morph_lib.stream import stream_chat<br>from morph_lib.types import MorphChatStreamChunk<br><br>import morph<br>from morph import MorphGlobalContext<br><br>SYSTEM_TEMPLATE = &quot;&quot;&quot;Please execute SQL queries on a table named `./data/Traffic_Orders_Demo_Data.csv` in DuckDB with the following schema:<br>date: text - date<br>source: text - traffic source (Coupon, Google Organic など)<br>traffic: int - traffic count<br>orders: int - order count<br><br>This table contains traffic and order data for the marketing campaigns.<br><br>As a source, you have the following data:<br>- Coupon<br>- Google Organic<br>- Google Paid<br>- TikTok Ads<br>- Meta Ads<br>- Referral<br><br>Generate a SQL query to answer the user&#39;s question.<br>{format_instructions}<br>&quot;&quot;&quot;<br><br>@morph.func<br>def sql_agent(<br>    context: MorphGlobalContext,<br>) -&gt; Generator[MorphChatStreamChunk, None, None]:<br>    chat = ChatOpenAI(<br>        model=&quot;gpt-4o&quot;,<br>        temperature=0,<br>        streaming=False,<br>    )<br><br>    # Setup the SQL query output parser<br>    sql_schema = ResponseSchema(name=&quot;sql&quot;, description=&quot;The SQL query to execute&quot;)<br>    output_parser = StructuredOutputParser.from_response_schemas([sql_schema])<br>    format_instructions = output_parser.get_format_instructions()<br><br>    prompt = ChatPromptTemplate.from_messages([<br>        (&quot;system&quot;, SYSTEM_TEMPLATE),<br>        (&quot;human&quot;, &quot;{question}&quot;)<br>    ])<br><br>    # Create the chain for SQL generation<br>    chain = (<br>        {&quot;question&quot;: RunnablePassthrough(), &quot;format_instructions&quot;: lambda _: format_instructions}<br>        | prompt<br>        | chat<br>        | StrOutputParser()<br>        | output_parser<br>    )<br><br>    # Generate SQL query<br>    result = chain.invoke(context.vars[&quot;prompt&quot;])<br>    sql = result[&quot;sql&quot;]<br>    # display generated sql<br>    yield stream_chat(f&quot;&quot;&quot;<br>### SQL<br>```sql<br>{sql}<br>```<br>&quot;&quot;&quot;)<br><br>    # Execute SQL and get results<br>    data = execute_sql(sql, &quot;DUCKDB&quot;)<br>    data_md = data.to_markdown(index=False)<br>    # Create analysis prompt with results<br>    analysis_prompt = ChatPromptTemplate.from_messages([<br>        (&quot;system&quot;, f&quot;&quot;&quot;Please answer in markdown format.<br>You can use the following data:<br>{data_md}<br><br>The data is from the following SQL query:<br>{sql}<br>&quot;&quot;&quot;),<br>        (&quot;human&quot;, &quot;{question}&quot;)<br>    ])<br><br>    # Create analysis chain<br>    analysis_chain = (<br>        {&quot;question&quot;: RunnablePassthrough()}<br>        | analysis_prompt<br>        | chat<br>    )<br><br>    # stream analysis result<br>    for chunk in analysis_chain.stream(context.vars[&quot;prompt&quot;]):<br>        if chunk.content:<br>            yield stream_chat(chunk.content)</pre><p><strong>Deploying and Sharing the App</strong></p><p>Morph’s dashboard supports automated deployment using GitHub integration.</p><p>By pushing your code to GitHub and selecting the repository from the <a href="https://app.morph-data.io/">dashboard</a>, you can deploy the app as an internal application with authentication enabled automatically.</p><p><strong>Reference:</strong></p><p><a href="https://docs.morph-data.io/docs/en/quickstart/deploy">https://docs.morph-data.io/docs/en/quickstart/deploy</a></p><p>Once the deployment is complete, access the app from the “Open” button in the dashboard. You can easily share the SQL Agent app with your team!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7jj77TDN8Z8RoVToyOHBtw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=238d80f8a180" width="1" height="1" alt=""><hr><p><a href="https://medium.com/morph-tech-blog/tutorial-building-sql-agent-with-langchain-openai-and-duckdb-238d80f8a180">Tutorial: Building SQL Agent with Langchain, OpenAI and DuckDB.</a> was originally published in <a href="https://medium.com/morph-tech-blog">Squadbase Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tutorial: Building a custom AI chat with user authentication using LangChain, OpenAI API, and Morph.]]></title>
            <link>https://medium.com/morph-tech-blog/tutorial-building-and-deploying-a-custom-ai-chat-with-authentication-using-langchain-and-openai-e90aa3bbd22f?source=rss-5e65a875d1d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e90aa3bbd22f</guid>
            <category><![CDATA[morph]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[rbac]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[ai-app-development]]></category>
            <dc:creator><![CDATA[Naoto Shibata]]></dc:creator>
            <pubDate>Thu, 13 Feb 2025 01:23:35 GMT</pubDate>
            <atom:updated>2025-02-13T07:54:11.173Z</atom:updated>
            <content:encoded><![CDATA[<p>I published this on <a href="https://dev.to/morph-data/tutorial-building-a-custom-ai-chat-with-user-authentication-using-langchain-openai-api-and-morph-3f2i">dev.to</a>, where you can read for free.</p><blockquote><em>In this guide, we explain how to create an authenticated AI application using LangChain and Morph. With Morph’s RBAC (Role-based Access Control) system, you can securely deploy an AI application built with LangChain within your organization.</em></blockquote><p>Morph is a framework that allows you to build and deploy AI apps using Python and Markdown. In the tutorial, we will use the Morph cloud dashboard (available for free), so please log in to <a href="https://morph-data.io/">morph-data.io</a> in advance.</p><p>LangChain is an excellent framework for developing applications that utilize large language models (LLMs). It comes equipped with a variety of components and third-party integrations.</p><p>In this article, we detail the steps to build an AI workflow with LangChain and deploy it as an authenticated AI application using Morph, ready for your team to use.</p><p>The outcome of this tutorial is available as the RBAC LangChain App in the following repository:</p><p><a href="https://github.com/morph-data/morph-sample-apps">https://github.com/morph-data/morph-sample-apps</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FWzV3agEy9Y4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DWzV3agEy9Y4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FWzV3agEy9Y4%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bf7a54bde7dddc9b069a1ef9e14d642/href">https://medium.com/media/7bf7a54bde7dddc9b069a1ef9e14d642/href</a></iframe><h3>Environment Setup</h3><p>Start a new project using the morph new command. It is recommended to choose poetry as the package manager.</p><pre>morph new rbac-langchain-app</pre><p>In your pyproject.toml, set the dependencies as shown below:</p><pre>[tool.poetry.dependencies]<br>python = &quot;&lt;3.13,&gt;=3.9&quot;<br>morph-data = &quot;0.1.3&quot;<br>langchain = &quot;0.3.16&quot;<br>langchain-core = &quot;0.3.32&quot;<br>langchain-openai = &quot;0.3.2&quot;</pre><p>Since this tutorial uses the OpenAI API, be sure to set your API KEY in the .env file:</p><pre>OPENAI_API_KEY=[Put your API KEY]</pre><h3>Building the Frontend</h3><p>With Morph, you can build your frontend by placing MDX files under the src/pages directory.</p><p>In this example, we use the &lt;Chat /&gt; component to create an interface where users can chat with the built AI. We also adjust the layout using the &lt;Grid /&gt; component and Tailwind CSS utility classes:</p><pre># Role-based access control with LangChain<br><br>This example shows how to use LangChain with role-based access control (RBAC).<br><br>&lt;Grid cols={1} className=&quot;py-4&quot;&gt;<br>    &lt;div className=&quot;p-4 bg-gray-50 rounded-lg shadow-sm border border-gray-200 hover:shadow-md transition-shadow&quot;&gt;<br>        &lt;LLM postData=&quot;rbac_langchain&quot; /&gt;<br>    &lt;/div&gt;<br>&lt;/Grid&gt;</pre><p>Now, run morph serve in your terminal and open <a href="http://localhost:8080/">http://localhost:8080</a> in your browser to see the interface.</p><h3>Building the AI App with LangChain and Enforcing RBAC</h3><p>We will build an AI workflow with LangChain that is accessible only to users with the ‘admin’ role.</p><p>From the MDX &lt;Chat /&gt; component, two parameters are automatically sent:</p><ul><li><strong>prompt:</strong> The message entered by the user.</li><li><strong>thread_id:</strong> A unique ID that identifies the thread displayed in the Chat UI.</li></ul><p>We use a global variable called history to store information about the most recent thread so that the system can respond to follow-up questions in context.</p><pre>history = {}<br><br>@morph.func<br>def rbac_langchain(context: MorphGlobalContext):<br>    model = ChatOpenAI(model=&quot;gpt-4o-mini&quot;)<br>    # Initialize history when a new thread starts.<br>    if history.get(&quot;thread_id&quot;) != context.vars[&quot;thread_id&quot;]:<br>        history[&quot;thread_id&quot;] = context.vars[&quot;thread_id&quot;]<br>        history[&quot;messages&quot;] = [<br>            SystemMessage(content=&quot;Please translate the following text from English to French.&quot;),<br>        ]<br>    # Append the user&#39;s prompt.<br>    history[&quot;messages&quot;].append(HumanMessage(content=context.vars[&quot;prompt&quot;]))<br>    result = &quot;&quot;<br>    for token in model.stream(history[&quot;messages&quot;]):<br>        result += token.content<br>        yield create_chunk(token.content)<br>    history[&quot;messages&quot;].append(AIMessage(content=result))</pre><p>Next, we return an error message via chat if the user does not have the “admin” role:</p><pre># context.user_info comes from the user&#39;s authentication info.<br>if &quot;admin&quot; not in context.user_info[&quot;roles&quot;]:<br>    yield stream_chat(&quot;You are not authorized to use this feature.&quot;)<br>    return</pre><h3>Complete Python Code</h3><pre>import morph<br>from morph import MorphGlobalContext<br>from morph_lib.stream import create_chunk<br>from langchain_openai import ChatOpenAI<br>from langchain_core.messages import HumanMessage, SystemMessage, AIMessage<br>from morph_lib.stream import stream_chat<br><br>history = {}<br><br>@morph.func<br>def rbac_langchain(context: MorphGlobalContext):<br>    # context.user_info comes from the user&#39;s authentication info.<br>    if &quot;admin&quot; not in context.user_info[&quot;roles&quot;]:<br>        yield stream_chat(&quot;You are not authorized to use this feature. \\n\\n Please login as admin.&quot;)<br>        return<br>    model = ChatOpenAI(model=&quot;gpt-4o-mini&quot;)<br>    if history.get(&quot;thread_id&quot;) != context.vars[&quot;thread_id&quot;]:<br>        history[&quot;thread_id&quot;] = context.vars[&quot;thread_id&quot;]<br>        history[&quot;messages&quot;] = [<br>            SystemMessage(content=&quot;Please translate the following text from English to French.&quot;),<br>        ]<br>    history[&quot;messages&quot;].append(HumanMessage(content=context.vars[&quot;prompt&quot;]))<br>    result = &quot;&quot;<br>    for token in model.stream(history[&quot;messages&quot;]):<br>        result += token.content<br>        yield create_chunk(token.content)<br>    history[&quot;messages&quot;].append(AIMessage(content=result))</pre><h3>Deploying and Sharing Your App</h3><ol><li>Create a new project on the <a href="https://app.morph-data.io/">dashboard</a> and issue an API Key.</li><li>In your morph_project.yml, set the project_id you obtained from the project details page:</li></ol><pre>default_connection: DUCKDB<br>package_manager: pip<br>profile: default<br>project_id: [Insert your project ID]<br>result_cache_ttl: 0<br>source_paths:<br>- src</pre><p>3. Next, bind your API Key to the CLI:</p><pre>morph config</pre><p>With everything set up, deploy your app from the dashboard!</p><pre>morph deploy</pre><p>For more details, see: <a href="https://docs.morph-data.io/docs/ja/deploy/deploy">https://docs.morph-data.io/docs/ja/deploy/deploy</a></p><p>After the deployment is complete, click “Open” from the dashboard to access your app. You can verify that access control is working as expected based on the Project Role set under Member Access in the dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*plOg_oDdyzbyZEnPwlDYUA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XfyC2l7qfG8_mAtf7yiC8A.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e90aa3bbd22f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/morph-tech-blog/tutorial-building-and-deploying-a-custom-ai-chat-with-authentication-using-langchain-and-openai-e90aa3bbd22f">Tutorial: Building a custom AI chat with user authentication using LangChain, OpenAI API, and Morph.</a> was originally published in <a href="https://medium.com/morph-tech-blog">Squadbase Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Two new technologies that allow everyone to handle data]]></title>
            <link>https://medium.com/morph-blog/two-new-technologies-that-allow-everyone-to-handle-data-b6c2eff0829c?source=rss-5e65a875d1d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6c2eff0829c</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[saas]]></category>
            <category><![CDATA[launch]]></category>
            <dc:creator><![CDATA[Naoto Shibata]]></dc:creator>
            <pubDate>Thu, 24 Aug 2023 01:22:31 GMT</pubDate>
            <atom:updated>2023-09-01T04:48:09.566Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CXpoT_XdnFan3mLivscGZg.jpeg" /></figure><p>To achieve our vision of ‘making data an everyday tool’, we are developing a new data management tool.</p><p>Morph is based on the concept of an ‘all-in-one Data Studio,’ and makes easy and powerful use of data available to not just engineers but also marketing, sales, customer support, and management.</p><h3>The challenges we face: data should be easier</h3><p>We have been building business software and end-user software for various companies for seven years. This included projects that dealt with complex data, such as machine learning and blockchain.</p><p>We became aware of the major challenges faced by all business people who work with data, and we are trying to solve them.</p><h3>1. The need for an engineer</h3><p>First, and perhaps most obvious: data is very difficult to handle, so you have no choice but to ask a knowledgeable engineer to extract the data for you, or build a dedicated system.</p><p>Customers have asked us, “can you output the data in CSV so we can use it?” I would assume that many of our readers may have made or received a similar request. This challenge worsens as the amount of data available to businesses increases.</p><h3>2. While database technology has evolved, database clients have not evolved at all</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*euDa3VS6u6sH13T7pQD8tA.png" /></figure><p>The development of database technology for utilizing data has been progressing all over the world and many innovations have been made. Large data and complex aggregations that cannot be processed by Excel or Google spreadsheets can be easily handled using databases.</p><p>However, the use of databases is currently only available to engineers, as advanced skills and knowledge are required to use such technology.</p><p>In other words, <strong>database technology is evolving at a tremendous pace, but client tools are not evolving at all</strong>. There are no client tools that can create new databases, connect to existing databases, extract / save data, or create APIs and visualizations in one place.</p><h3>3. The cost of implementing a database is too high</h3><p>A database is required if you want to manage a reasonable size of data within your company. Databases are expensive to use, and require advanced knowledge for selection and construction. In most cases database selection and construction is not done by the department using it, but rather by consulting internal and external engineers. As mentioned above, there are no client tools other than those for engineers, so it becomes necessary to develop the interface to use the database as well. This also leads to vendor lock-in.</p><p>Thus, <strong>the high cost of implementing databases has further raised the hurdles to database utilization.</strong></p><h3>Why the solution is now possible — two technologies.</h3><h3>1. Serverless RDB (serverless relational database)</h3><p>In recent years, database technology has seen innovations not only in scalability, but also in the way it is hosted.</p><p>We are developing Morph using the open source Serverless Postgres system called Neon, which automatically puts normally expensive database instances on standby when they are not in use. This greatly reduces the cost of database usage. Users can also dynamically adjust start-up when using the database, so the database uses only the amount of resources they need.</p><p>Neon also automates all the work involved in setting up a database, so you get a database with one click where you would <strong>normally have to log in to a cloud platform such as AWS, Azure or GCP and do a lot of configuration before you can build it.</strong></p><p>Neon’s technology is also used in the recently announced Vercel Postgres, which shows the reliability of Neon’s technology in this area.</p><h3>2. Natural language interfaces (LLM and Chat GPT)</h3><p>LLMs, including ChatGPT, play an important role in enabling new data tools.</p><p>Until now, in order to manipulate databases <strong>programming languages such as SQL and Python had to be learnt</strong>. This knowledge was a huge hurdle for people who do not know how to code, or how to code in the back end.</p><p>We thought that Chat GPT might be the solution, and through repeated experimentation we discovered that it is very good at outputting programming languages.</p><p>We have integrated Chat GPT into Morph. Even in the current early version, with natural language instructions we are able to perform:</p><ul><li>Data extraction (automatic SQL generation and execution)</li><li>Visualization and complex data analysis (automatic Python generation, execution)</li><li>Structuring unstructured data to match the table structure in the DB</li></ul><p>…as well as several other processes that previously required a high level of technical expertise.</p><p>With the emergence of code-specific LLMs such as StarCoder, this functionality can only be expected to develop. For our part, we aim to bring the knowledge required to use the database closer to zero through multimodal support and the development of dedicated LLMs.</p><h3>What kind of tool is Morph?</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fhm0pNlFhOOM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dhm0pNlFhOOM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fhm0pNlFhOOM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/88d05eddd1d2a3177b3bbc90c6797dfb/href">https://medium.com/media/88d05eddd1d2a3177b3bbc90c6797dfb/href</a></iframe><p>Morph is a no-code tool for data management. Without any programming knowledge, it can be used to:</p><ul><li>Create new databases</li><li>Import existing databases (MySQL, PostgresSQL)</li><li>Import CSV, Excel files, etc.</li><li>Display, manage and co-edit records</li><li>Create APIs to manipulate databases (see API Document for details)</li><li>Aggregate, analyze and visualize data.</li></ul><h3>Request</h3><blockquote><em>Data should be easy for everyone to understand and use, and this should be completed through one simple interface.</em></blockquote><p>Morph is a tool for data operations, but the processing and aggregation of data has a wide range of applications and expectations depending on the business.</p><p>However, through internal testing — and from prior users in a wide range of industries, including tech companies, manufacturing, call centres and healthcare — it has become clear that these processes are very similar in nature.</p><p>To achieve our vision of completing all data work on one simple interface, <strong>we need feedback and input from people from a wide range of industries and backgrounds.</strong></p><p>We invite you to join us on our journey by following the links below.</p><p>LP: <a href="https://www.morphdb.io/">https://www.morphdb.io/</a></p><p>Discord: <a href="https://discord.com/invite/8ZcSbDrN6e">https://discord.com/invite/8ZcSbDrN6e</a></p><h3>Try for free</h3><p>Morph has a free plan which you can start using right now. Please try it out!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6c2eff0829c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/morph-blog/two-new-technologies-that-allow-everyone-to-handle-data-b6c2eff0829c">Two new technologies that allow everyone to handle data</a> was originally published in <a href="https://medium.com/morph-blog">Morph Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>