mdp-1395 commited on
Commit
617f8fb
1 Parent(s): 91c73fe

first_commit_1

Browse files
Files changed (2) hide show
  1. app.py +75 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from openai import OpenAI
3
+ from pinecone import Pinecone
4
+ import os
5
+
6
+ DEFAULT_SYSTEM_PROMPT = '''
7
+ Your name is Personata. You are a helpful, respectful AI Chatbot.
8
+ You will be representing Divya Prakash Manivannan( First Name: Divya Prakash Last Name: Manivannan) and who goes by pronouns (He/Him).
9
+ You will be prompted by the user for his information about his professional profile and you will have answer it on his behalf.
10
+ You also have access to RAG vectore database access which has his data, with which you will answer the question asked.
11
+ Be careful when giving response, sometime irrelevent Rag content will be there so give response effectivly to user based on the prompt.
12
+ You can speak fluently in English.
13
+ Always answer as helpfully and logically as possible, while being safe.
14
+ Your answers should not include any harmful, political, religious, unethical, racist, sexist, toxic, dangerous, or illegal content.
15
+ Please ensure that your responses are socially unbiased and positive in nature.
16
+ If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct.
17
+ If you don't have the RAG response, answer that " I do not have the information".
18
+ Try to give concise answers, wherever required
19
+ '''
20
+
21
+ ## API Keys
22
+ PINE_CONE_API_KEY = os.getenv('PINE_CONE_API_KEY')
23
+ OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
24
+
25
+ pc = Pinecone(
26
+ api_key= PINE_CONE_API_KEY
27
+ )
28
+ client = OpenAI(api_key= OPENAI_API_KEY)
29
+ index = pc.Index("rag-resume")
30
+
31
+ def vector_search(query):
32
+ rag_data = ""
33
+ xq = client.embeddings.create(input=query,model="text-embedding-ada-002")
34
+ res = index.query(vector = xq.data[0].embedding, top_k=5, include_metadata=True)
35
+ print(res)
36
+ for match in res['matches']:
37
+ if match['score'] < 0.80:
38
+ continue
39
+ rag_data += match['metadata']['text']
40
+ return rag_data
41
+
42
+ def respond(
43
+ message,
44
+ history: list[tuple[str, str]]
45
+ ):
46
+ messages = [{"role": "system", "content": DEFAULT_SYSTEM_PROMPT}]
47
+ print(message)
48
+ rag = vector_search(message)
49
+
50
+ for val in history:
51
+ if val[0]:
52
+ messages.append({"role": "user", "content": val[0] + rag})
53
+ if val[1]:
54
+ messages.append({"role": "assistant", "content": val[1]})
55
+
56
+ messages.append({"role": "user", "content": message})
57
+
58
+ response = ""
59
+
60
+ response = client.chat.completions.create(
61
+ model="gpt-3.5-turbo-1106",
62
+ messages = messages
63
+ )
64
+
65
+ yield response.choices[0].message.content
66
+
67
+
68
+ demo = gr.ChatInterface(
69
+ respond
70
+ )
71
+
72
+ demo.queue()
73
+
74
+ if __name__ == "__main__":
75
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ openai==1.31.0
2
+ pinecone-client==4.1.0
3
+ langchain-text-splitters==0.2.0
4
+ langchain==0.2.1
5
+
6
+