Update app.py
Browse files
app.py
CHANGED
@@ -3,12 +3,12 @@ import os, time
|
|
3 |
|
4 |
from dotenv import load_dotenv, find_dotenv
|
5 |
|
6 |
-
from rag import
|
7 |
from trace import trace_wandb
|
8 |
|
9 |
_ = load_dotenv(find_dotenv())
|
10 |
|
11 |
-
|
12 |
|
13 |
config = {
|
14 |
"chunk_overlap": 150, # split documents
|
@@ -32,8 +32,8 @@ def invoke(openai_api_key, prompt, rag_option):
|
|
32 |
|
33 |
os.environ["OPENAI_API_KEY"] = openai_api_key
|
34 |
|
35 |
-
if (
|
36 |
-
|
37 |
|
38 |
chain = None
|
39 |
completion = ""
|
@@ -45,12 +45,12 @@ def invoke(openai_api_key, prompt, rag_option):
|
|
45 |
start_time_ms = round(time.time() * 1000)
|
46 |
|
47 |
if (rag_option == RAG_OFF):
|
48 |
-
completion, chain, cb =
|
49 |
|
50 |
if (completion.generations[0] != None and completion.generations[0][0] != None):
|
51 |
result = completion.generations[0][0].text
|
52 |
else:
|
53 |
-
completion, chain, cb =
|
54 |
|
55 |
result = completion["result"]
|
56 |
except Exception as e:
|
@@ -70,6 +70,7 @@ def invoke(openai_api_key, prompt, rag_option):
|
|
70 |
err_msg,
|
71 |
start_time_ms,
|
72 |
end_time_ms)
|
|
|
73 |
return result
|
74 |
|
75 |
gr.close_all()
|
|
|
3 |
|
4 |
from dotenv import load_dotenv, find_dotenv
|
5 |
|
6 |
+
from rag import llm_chain, rag_chain, rag_ingestion
|
7 |
from trace import trace_wandb
|
8 |
|
9 |
_ = load_dotenv(find_dotenv())
|
10 |
|
11 |
+
RAG_INGESTION = False # load, split, embed, and store documents
|
12 |
|
13 |
config = {
|
14 |
"chunk_overlap": 150, # split documents
|
|
|
32 |
|
33 |
os.environ["OPENAI_API_KEY"] = openai_api_key
|
34 |
|
35 |
+
if (RAG_INGESTION):
|
36 |
+
rag_ingestion(config)
|
37 |
|
38 |
chain = None
|
39 |
completion = ""
|
|
|
45 |
start_time_ms = round(time.time() * 1000)
|
46 |
|
47 |
if (rag_option == RAG_OFF):
|
48 |
+
completion, chain, cb = llm_chain(config, openai_api_key, prompt)
|
49 |
|
50 |
if (completion.generations[0] != None and completion.generations[0][0] != None):
|
51 |
result = completion.generations[0][0].text
|
52 |
else:
|
53 |
+
completion, chain, cb = rag_chain(config, openai_api_key, rag_option, prompt)
|
54 |
|
55 |
result = completion["result"]
|
56 |
except Exception as e:
|
|
|
70 |
err_msg,
|
71 |
start_time_ms,
|
72 |
end_time_ms)
|
73 |
+
|
74 |
return result
|
75 |
|
76 |
gr.close_all()
|