bstraehle commited on
Commit
e0ddc02
1 Parent(s): 61d6f57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -3,7 +3,7 @@ import os, time
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())
@@ -16,9 +16,9 @@ config = {
16
  "temperature": 0 # llm
17
  }
18
 
19
- RAG_OFF = "Off"
20
- RAG_MONGODB = "MongoDB" # serverless
21
- RAG_CHROMA = "Chroma" # requires persistent storage (small is $0.01/hour)
22
 
23
  def invoke(openai_api_key, prompt, rag_option):
24
  if (openai_api_key == ""):
@@ -42,15 +42,17 @@ def invoke(openai_api_key, prompt, rag_option):
42
  try:
43
  start_time_ms = round(time.time() * 1000)
44
 
45
- if (rag_option == RAG_OFF):
 
 
 
 
 
 
46
  completion, chain, cb = llm_chain(config, prompt)
47
 
48
  if (completion.generations[0] != None and completion.generations[0][0] != None):
49
  result = completion.generations[0][0].text
50
- else:
51
- completion, chain, cb = rag_chain(config, rag_option, prompt)
52
-
53
- result = completion["result"]
54
  except Exception as e:
55
  err_msg = e
56
 
@@ -76,15 +78,15 @@ gr.close_all()
76
  demo = gr.Interface(fn = invoke,
77
  inputs = [gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1),
78
  gr.Textbox(label = "Prompt", value = "What are GPT-4's media capabilities in 5 emojis and 1 sentence?", lines = 1),
79
- gr.Radio([RAG_OFF, RAG_MONGODB], label = "Retrieval-Augmented Generation", value = RAG_MONGODB)],
80
  outputs = [gr.Textbox(label = "Completion", lines = 1)],
81
  title = "Context-Aware Reasoning Application",
82
  description = os.environ["DESCRIPTION"],
83
- examples = [["", "What are GPT-4's media capabilities in 5 emojis and 1 sentence?", RAG_MONGODB],
84
- ["", "List GPT-4's exam scores and benchmark results.", RAG_MONGODB],
85
- ["", "Compare GPT-4 to GPT-3.5 in markdown table format.", RAG_MONGODB],
86
- ["", "Write a Python program that calls the GPT-4 API.", RAG_MONGODB],
87
- ["", "What is the GPT-4 API's cost and rate limit? Answer in English, Arabic, Chinese, Hindi, and Russian in JSON format.", RAG_MONGODB]],
88
  cache_examples = False)
89
 
90
  demo.launch()
 
3
 
4
  from dotenv import load_dotenv, find_dotenv
5
 
6
+ from rag_langchain import llm_chain, rag_chain, rag_ingestion
7
  from trace import trace_wandb
8
 
9
  _ = load_dotenv(find_dotenv())
 
16
  "temperature": 0 # llm
17
  }
18
 
19
+ RAG_OFF = "Off"
20
+ RAG_LANGCHAIN = "LangChain"
21
+ RAG_LLAMAINDEX = "LlamaIndex"
22
 
23
  def invoke(openai_api_key, prompt, rag_option):
24
  if (openai_api_key == ""):
 
42
  try:
43
  start_time_ms = round(time.time() * 1000)
44
 
45
+ if (rag_option == RAG_LANGCHAIN):
46
+ completion, chain, cb = rag_chain(config, rag_option, prompt)
47
+
48
+ result = completion["result"]
49
+ elif (rag_option == RAG_LLAMAINDEX):
50
+ print("TODO")
51
+ else:
52
  completion, chain, cb = llm_chain(config, prompt)
53
 
54
  if (completion.generations[0] != None and completion.generations[0][0] != None):
55
  result = completion.generations[0][0].text
 
 
 
 
56
  except Exception as e:
57
  err_msg = e
58
 
 
78
  demo = gr.Interface(fn = invoke,
79
  inputs = [gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1),
80
  gr.Textbox(label = "Prompt", value = "What are GPT-4's media capabilities in 5 emojis and 1 sentence?", lines = 1),
81
+ gr.Radio([RAG_OFF, RAG_LANGCHAIN, RAG_LLAMAINDEX], label = "Retrieval-Augmented Generation", value = RAG_LANGCHAIN)],
82
  outputs = [gr.Textbox(label = "Completion", lines = 1)],
83
  title = "Context-Aware Reasoning Application",
84
  description = os.environ["DESCRIPTION"],
85
+ examples = [["", "What are GPT-4's media capabilities in 5 emojis and 1 sentence?", RAG_LANGCHAIN],
86
+ ["", "List GPT-4's exam scores and benchmark results.", RAG_LANGCHAIN],
87
+ ["", "Compare GPT-4 to GPT-3.5 in markdown table format.", RAG_LANGCHAIN],
88
+ ["", "Write a Python program that calls the GPT-4 API.", RAG_LANGCHAIN],
89
+ ["", "What is the GPT-4 API's cost and rate limit? Answer in English, Arabic, Chinese, Hindi, and Russian in JSON format.", RAG_LANGCHAIN]],
90
  cache_examples = False)
91
 
92
  demo.launch()