sujitb commited on
Commit
8596e21
1 Parent(s): b403bb0

Added openai key

Browse files
Files changed (1) hide show
  1. app.py +56 -1
app.py CHANGED
@@ -3,7 +3,13 @@ import streamlit as st
3
  #from transformers import pipeline
4
  from pinecone import Pinecone, ServerlessSpec
5
  from sentence_transformers import SentenceTransformer, util
 
 
 
6
 
 
 
 
7
 
8
  bi_encoder = SentenceTransformer('msmarco-distilbert-base-v4')
9
  bi_encoder.max_seq_length = 256 # Truncate long documents to 256 tokens
@@ -36,7 +42,56 @@ if QUESTION:
36
  out= resp[0]['metadata']['data']
37
  url= "Matching url "+resp[0]['id']
38
  #+ '\n*************\n'+ resp[1]['metadata']['text'] + '\n*************\n'+ resp[2]['metadata']['text']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  st.write(url)
40
- st.write(out)
 
41
  else:
42
  st.write("No matches for query")
 
3
  #from transformers import pipeline
4
  from pinecone import Pinecone, ServerlessSpec
5
  from sentence_transformers import SentenceTransformer, util
6
+ from openai import OpenAI
7
+ import os
8
+ api_key='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'
9
 
10
+ os.environ["OPENAI_API_KEY"] = api_key
11
+
12
+ os.environ.get("OPENAI_API_KEY")
13
 
14
  bi_encoder = SentenceTransformer('msmarco-distilbert-base-v4')
15
  bi_encoder.max_seq_length = 256 # Truncate long documents to 256 tokens
 
42
  out= resp[0]['metadata']['data']
43
  url= "Matching url "+resp[0]['id']
44
  #+ '\n*************\n'+ resp[1]['metadata']['text'] + '\n*************\n'+ resp[2]['metadata']['text']
45
+
46
+
47
+ system_instructions_text='''
48
+ Your task is to extract the answer to a question from a body of text provided to you.
49
+ The body of text will be enclosed within the delimiter tags <text> and </text>
50
+
51
+ For example,
52
+ <text> General Preparation Tips for VARC Section:
53
+
54
+ You need to develop an incessant habit of speed reading.
55
+ Start with reading newspapers, editorials, fiction and nonfiction novels and simple passages.
56
+ The more you read, the faster you read. Learn the basic grammar concepts like parts of speech, articles,verbs, adjectives, tenses, auxiliary verbs, modifiers, modals etc.
57
+ Revise at least 50 new words every day
58
+ </text>
59
+
60
+ Question: What are some tips for preparing for VARC?
61
+ Here are some tips for preparing for the VARC section:
62
+ 1. develop an incessant habit of speed reading
63
+ 2. Start reading newspapers, editorials, fiction and nonfiction novels
64
+ 3. Learn basic grammar concepts\n
65
+ 4. Revise at least 50 new words a day
66
+
67
+ Question: How many new words are to be learnt in a day?
68
+ It is advised that 50 new words are learn every day
69
+
70
+ Your response should be based on the information contained in the provided text and should not included any other sources.
71
+ If you are unable to answer the question from the text provided, please respond " Sorry. I do not have enough information to answer this"
72
+ Do repeat the question. Do not make a pointed reference to the text provided. Directly answer the question
73
+ '''
74
+
75
+ client = OpenAI()
76
+ content="""
77
+ <text>
78
+ {}
79
+ </text>
80
+ """.format(out)
81
+
82
+ response = client.chat.completions.create(
83
+ model="gpt-3.5-turbo",
84
+ messages=[
85
+ {"role": "system", "content":system_instructions_text },
86
+ {"role": "user", "content": content},
87
+ {"role": "user", "content": "Question:"+QUESTION}
88
+ ]
89
+ )
90
+
91
+ ans= response.choices[0].message.content
92
+
93
  st.write(url)
94
+ st.write(ans)
95
+
96
  else:
97
  st.write("No matches for query")