File tree Expand file tree Collapse file tree 3 files changed +6
-27
lines changed Expand file tree Collapse file tree 3 files changed +6
-27
lines changed Original file line number Diff line number Diff line change 11.env
2+ .venv
23__pycache__
34vectorstore.pkl
Original file line number Diff line number Diff line change 88from dotenv import load_dotenv
99from langchain import OpenAI
1010from langchain .embeddings import OpenAIEmbeddings
11- from langchain .vectorstores . faiss import FAISS
11+ from langchain .vectorstores import FAISS
1212from langchain .document_loaders import CubeSemanticLoader
1313from pathlib import Path
1414
1515from utils import (
16- create_docs_from_values ,
17- create_vectorstore ,
18- init_vectorstore ,
1916 check_input ,
2017 log ,
2118 call_sql_api ,
2219 CUBE_SQL_API_PROMPT ,
2320 _NO_ANSWER_TEXT ,
24- PROMPT_POSTFIX ,
2521)
2622
2723load_dotenv ()
@@ -67,7 +63,10 @@ def ingest_cube_meta():
6763
6864if st .button ("Submit" , type = "primary" ):
6965 check_input (question )
70- vectorstore = init_vectorstore ()
66+ if not Path ("vectorstore.pkl" ).exists ():
67+ st .warning ("vectorstore.pkl does not exist." )
68+ with open ("vectorstore.pkl" , "rb" ) as f :
69+ vectorstore = pickle .load (f )
7170
7271 # log("Quering vectorstore and building the prompt...")
7372
Original file line number Diff line number Diff line change 11import streamlit as st
2- import pickle
32import datetime
43import os
54import psycopg2
65
76from dotenv import load_dotenv
8- from pathlib import Path
9- from typing import List
10- from langchain .vectorstores import VectorStore
117from langchain .prompts import PromptTemplate
12- from langchain .embeddings import OpenAIEmbeddings
13- from langchain .vectorstores .faiss import FAISS
148from langchain .docstore .document import Document
159
1610
@@ -30,21 +24,6 @@ def check_input(question: str):
3024 pass
3125
3226
33- def init_vectorstore () -> VectorStore :
34- vectorstore : VectorStore = None
35- if not Path ("vectorstore.pkl" ).exists ():
36- st .warning ("vectorstore.pkl does not exist, please run ingest.py first" )
37- with open ("vectorstore.pkl" , "rb" ) as f :
38- vectorstore = pickle .load (f )
39- return vectorstore
40-
41-
42- def create_vectorstore (documents : List [Document ]) -> VectorStore :
43- embeddings = OpenAIEmbeddings ()
44- vectorstore = FAISS .from_documents (documents , embeddings )
45- return vectorstore
46-
47-
4827_postgres_prompt = """\
4928 You are a PostgreSQL expert. Given an input question, create a syntactically correct PostgreSQL query to run and return it as the answer to the input question.
5029Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the LIMIT clause as per PostgreSQL.
You can’t perform that action at this time.
0 commit comments