Skip to content

Commit 30b921b

Browse files
authored
updated langchain related codebase (#7314)
1 parent 9c2ceb3 commit 30b921b

File tree

3 files changed

+6
-27
lines changed

3 files changed

+6
-27
lines changed

examples/langchain/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.env
2+
.venv
23
__pycache__
34
vectorstore.pkl

examples/langchain/streamlit_app.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,16 @@
88
from dotenv import load_dotenv
99
from langchain import OpenAI
1010
from langchain.embeddings import OpenAIEmbeddings
11-
from langchain.vectorstores.faiss import FAISS
11+
from langchain.vectorstores import FAISS
1212
from langchain.document_loaders import CubeSemanticLoader
1313
from pathlib import Path
1414

1515
from 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

2723
load_dotenv()
@@ -67,7 +63,10 @@ def ingest_cube_meta():
6763

6864
if 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

examples/langchain/utils.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
import streamlit as st
2-
import pickle
32
import datetime
43
import os
54
import psycopg2
65

76
from dotenv import load_dotenv
8-
from pathlib import Path
9-
from typing import List
10-
from langchain.vectorstores import VectorStore
117
from langchain.prompts import PromptTemplate
12-
from langchain.embeddings import OpenAIEmbeddings
13-
from langchain.vectorstores.faiss import FAISS
148
from 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.
5029
Unless 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.

0 commit comments

Comments
 (0)