<?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>DEV Community: Shubhank92</title>
    <description>The latest articles on DEV Community by Shubhank92 (@shubhank92).</description>
    <link>https://dev.to/shubhank92</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%2F1094071%2Fe83058d1-82bd-4b07-bce1-02800530f977.png</url>
      <title>DEV Community: Shubhank92</title>
      <link>https://dev.to/shubhank92</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shubhank92"/>
    <language>en</language>
    <item>
      <title>Creating a Chatbot using the data stored in my huge database</title>
      <dc:creator>Shubhank92</dc:creator>
      <pubDate>Fri, 02 Jun 2023 05:46:01 +0000</pubDate>
      <link>https://dev.to/shubhank92/creating-a-chatbot-using-the-data-stored-in-my-huge-database-3oih</link>
      <guid>https://dev.to/shubhank92/creating-a-chatbot-using-the-data-stored-in-my-huge-database-3oih</guid>
      <description>&lt;p&gt;Hello Everyone,&lt;/p&gt;

&lt;p&gt;I want to build a custom chat bot which can answer questions based on the data in my databse&lt;br&gt;
Below are my tries and the problems I am facing&lt;br&gt;
I am open for all suggestions, so please do help me&lt;/p&gt;

&lt;p&gt;Tried without using langchain&lt;/p&gt;

&lt;p&gt;The code establishes a connection to a PostgreSQL database and prompts the user for information they want to obtain.&lt;br&gt;
It then generates an SQL query based on the (user input + the table names of the db) using the OpenAI GPT-3.5 language model.&lt;br&gt;
The code extracts table names from the generated query and fetches column information from the connected database. It generates a prompt that includes the table names and column details, and uses the GPT-3.5 model to generate a final SQL query based on this prompt.&lt;br&gt;
The final SQL query is executed on the database, and the results are printed. (currently )&lt;br&gt;
Overall, the code utilizes natural language processing and database interactions to generate and execute SQL queries based on user input.&lt;/p&gt;

&lt;p&gt;Tried using Langchain&lt;br&gt;
import os&lt;br&gt;
from langchain import OpenAI, SQLDatabase&lt;br&gt;
from langchain.chains import SQLDatabaseSequentialChain&lt;/p&gt;

&lt;p&gt;os.environ['OPENAI_API_KEY'] = "****"&lt;/p&gt;

&lt;p&gt;dburi = 'postgresql://postgres:*&lt;strong&gt;&lt;em&gt;@&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;:&lt;/em&gt;&lt;strong&gt;&lt;em&gt;/&lt;/em&gt;&lt;/strong&gt;*'&lt;br&gt;
db = SQLDatabase.from_uri(dburi)&lt;/p&gt;

&lt;h1&gt;
  
  
  llm = OpenAI(temperature=0, model='text-curie-001')
&lt;/h1&gt;

&lt;p&gt;llm = OpenAI(temperature=0)&lt;br&gt;
db_chain = SQLDatabaseSequentialChain(llm=llm, database=db, verbose=True)&lt;/p&gt;

&lt;p&gt;resp = db_chain.run('what is my last po value for testaccount')&lt;br&gt;
print(resp)&lt;/p&gt;

&lt;p&gt;the problem I have Faced is that the prompt size is getting to 1,29,300+ Tokens some how&lt;br&gt;
I am unable to figure it out why it is happening&lt;br&gt;
I tried custom prompt templates also but that did not decrease the prompt size&lt;br&gt;
What I felt is that they just add my custom prompt data to their prompt and send to the open ai api instead of just sending my custom prompt&lt;/p&gt;

&lt;p&gt;So if any one can help me in any way around, pls do&lt;/p&gt;

&lt;p&gt;Other than these two methods I have seen that there is something known as fine tuning and embeddings&lt;br&gt;
I know how fine tuning is done using the Open AI but I don’t have much Idea of Embeddings&lt;br&gt;
I want to know which one is better to use&lt;br&gt;
As far as what I have re searched I came to know that in both cases we have to give all the database information to them&lt;br&gt;
which is not secure I think for my organization as my user privacy will be at risk&lt;/p&gt;

&lt;p&gt;So finally what could be a better way to build a bot that can answer my questions based on the information in my db&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>api</category>
      <category>database</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
