NAB1108 commited on
Commit
f2a8094
·
1 Parent(s): 9f8ee69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -30,6 +30,7 @@ import tempfile
30
 
31
  os.environ["OPENAI_API_KEY"] = "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"
32
  query1=" "
 
33
  def loading_pdf():
34
  return "Loading..."
35
 
@@ -96,16 +97,19 @@ def infer(question):
96
  prompt_text = question
97
  if prompt_text:
98
  query1 = query1 + "\nUser: " + prompt_text + "\nBot: "
99
- result = chain(query1)
100
- query1 = query1 + result['answer']
101
- query1 = openai.ChatCompletion.create(
102
- model="gpt-3.5-turbo",
103
- messages=[
104
- {"role": "system", "content": "You are provided with chat history and latset conversation between user and bot. Summarise the history and latest conversationin minimum most tokens possible. Do not include greetings in the summary like hi, hello, etc."},
105
- {"role": "user", "content": query1},
106
- ]
107
- ) ["choices"][0]["message"]["content"].replace("'", "")
108
- return result['answer']
 
 
 
109
 
110
  css="""
111
  #col-container { margin-left: auto; margin-right: auto;}
 
30
 
31
  os.environ["OPENAI_API_KEY"] = "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"
32
  query1=" "
33
+ limit = 0
34
  def loading_pdf():
35
  return "Loading..."
36
 
 
97
  prompt_text = question
98
  if prompt_text:
99
  query1 = query1 + "\nUser: " + prompt_text + "\nBot: "
100
+ if limit <= 5:
101
+ result = chain(query1)
102
+ query1 = query1 + result['answer']
103
+ query1 = openai.ChatCompletion.create(
104
+ model="gpt-3.5-turbo",
105
+ messages=[
106
+ {"role": "system", "content": "You are provided with chat history and latset conversation between user and bot. Summarise the history and latest conversationin minimum most tokens possible. Do not include greetings in the summary like hi, hello, etc."},
107
+ {"role": "user", "content": query1},
108
+ ]
109
+ ) ["choices"][0]["message"]["content"].replace("'", "")
110
+ return result['answer']
111
+ else:
112
+ return "Usage Limit reached :("
113
 
114
  css="""
115
  #col-container { margin-left: auto; margin-right: auto;}