Larry Yin commited on
Commit
db6f7db
1 Parent(s): dbe6be4

Added secrets

Browse files
Files changed (2) hide show
  1. .env +0 -2
  2. app.py +6 -17
.env DELETED
@@ -1,2 +0,0 @@
1
- OPENAI_API_KEY=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
2
- HF_API_KEY=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
 
 
 
app.py CHANGED
@@ -1,27 +1,17 @@
1
  import os
2
  import openai
3
- import sys
4
- import io
5
  import gradio as gr
6
  from langchain.embeddings.openai import OpenAIEmbeddings
7
  from langchain.vectorstores.pgvector import PGVector
8
  from langchain.chat_models import ChatOpenAI
9
  from langchain.chains import ConversationalRetrievalChain
10
  from langchain.memory import ConversationTokenBufferMemory
11
- from dotenv import load_dotenv, find_dotenv
12
- _ = load_dotenv(find_dotenv()) # read local .env file
13
 
14
- openai.api_key = os.environ['OPENAI_API_KEY']
15
- hf_api_key = os.environ['HF_API_KEY']
16
 
17
  embedding = OpenAIEmbeddings()
18
 
19
- host = "experian-ai-instance-1.cyqxijnzhxga.us-west-2.rds.amazonaws.com"
20
- port = "5432"
21
- database_name = "experian"
22
- user = "larryyin"
23
- passwd = "experianai"
24
-
25
  CONNECTION_STRING = PGVector.connection_string_from_db_params(
26
  driver=os.environ.get("PGVECTOR_DRIVER", "psycopg2"),
27
  host=os.environ.get("PGVECTOR_HOST", host),
@@ -31,22 +21,21 @@ CONNECTION_STRING = PGVector.connection_string_from_db_params(
31
  password=os.environ.get("PGVECTOR_PASSWORD", passwd),
32
  )
33
 
34
- COLLECTION_NAME = "experian230725"
35
-
36
  vectordb = PGVector(embedding_function=embedding,
37
  collection_name=COLLECTION_NAME,
38
  connection_string=CONNECTION_STRING,
39
  )
40
 
41
  # llm_name = "gpt-3.5-turbo"
42
- llm_name = "gpt-3.5-turbo-16k"
43
  # llm_name = "gpt-4-32k"
 
44
  llm = ChatOpenAI(model_name=llm_name, temperature=0)
45
 
46
  retriever=vectordb.as_retriever()
47
  memory = ConversationTokenBufferMemory(
48
  llm = llm,
49
- max_token_limit=8000,
50
  memory_key="chat_history",
51
  return_messages=True
52
  )
@@ -58,7 +47,7 @@ qa = ConversationalRetrievalChain.from_llm(
58
  )
59
 
60
  with gr.Blocks() as demo:
61
- gr.Markdown("# Experian Bot V0.2")
62
  chatbot = gr.Chatbot()
63
  msg = gr.Textbox(label="Type your message (Shift + Enter to submit)", lines=6)
64
  submit = gr.Button("Submit")
 
1
  import os
2
  import openai
 
 
3
  import gradio as gr
4
  from langchain.embeddings.openai import OpenAIEmbeddings
5
  from langchain.vectorstores.pgvector import PGVector
6
  from langchain.chat_models import ChatOpenAI
7
  from langchain.chains import ConversationalRetrievalChain
8
  from langchain.memory import ConversationTokenBufferMemory
 
 
9
 
10
+ openai.api_key = OPENAI_API_KEY
11
+ hf_api_key = HF_API_KEY
12
 
13
  embedding = OpenAIEmbeddings()
14
 
 
 
 
 
 
 
15
  CONNECTION_STRING = PGVector.connection_string_from_db_params(
16
  driver=os.environ.get("PGVECTOR_DRIVER", "psycopg2"),
17
  host=os.environ.get("PGVECTOR_HOST", host),
 
21
  password=os.environ.get("PGVECTOR_PASSWORD", passwd),
22
  )
23
 
 
 
24
  vectordb = PGVector(embedding_function=embedding,
25
  collection_name=COLLECTION_NAME,
26
  connection_string=CONNECTION_STRING,
27
  )
28
 
29
  # llm_name = "gpt-3.5-turbo"
30
+ # llm_name = "gpt-3.5-turbo-16k"
31
  # llm_name = "gpt-4-32k"
32
+
33
  llm = ChatOpenAI(model_name=llm_name, temperature=0)
34
 
35
  retriever=vectordb.as_retriever()
36
  memory = ConversationTokenBufferMemory(
37
  llm = llm,
38
+ max_token_limit=memory_token_limit,
39
  memory_key="chat_history",
40
  return_messages=True
41
  )
 
47
  )
48
 
49
  with gr.Blocks() as demo:
50
+ gr.Markdown(f"# {bot_name}")
51
  chatbot = gr.Chatbot()
52
  msg = gr.Textbox(label="Type your message (Shift + Enter to submit)", lines=6)
53
  submit = gr.Button("Submit")