cogcorp commited on
Commit
d7a0cb9
·
1 Parent(s): 7be5bd9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -29,7 +29,7 @@ nltk.download('all') # or any other packages your project depends on
29
  # Put your OpenAI API key here
30
  openai.api_key = os.getenv('OpenAPI')
31
 
32
- def call_openai_api(prompt):
33
  max_retries = 5
34
  for attempt in range(max_retries):
35
  try:
@@ -37,7 +37,7 @@ def call_openai_api(prompt):
37
  model="gpt-3.5-turbo",
38
  messages=[
39
  {"role": "system", "content": "You are a research assistant. Provide factual short answers to your prompts. The user will provide reference data followed by instructions."},
40
- {"role": "user", "content": prompt},
41
  ]
42
  )
43
  return response['choices'][0]['message']['content']
@@ -67,11 +67,11 @@ def pdf_to_text(file, user_prompt):
67
  chunk = tokens[i:i + 2000]
68
  chunk_str = ' '.join(chunk)
69
  # Using OpenAI API
70
- response = call_openai_api(chunk_str)
71
  texts.append(response)
72
  else:
73
  # Using OpenAI API
74
- response = call_openai_api(text)
75
  texts.append(response)
76
  return '\n'.join(texts)
77
 
 
29
  # Put your OpenAI API key here
30
  openai.api_key = os.getenv('OpenAPI')
31
 
32
+ def call_openai_api(text, user_prompt):
33
  max_retries = 5
34
  for attempt in range(max_retries):
35
  try:
 
37
  model="gpt-3.5-turbo",
38
  messages=[
39
  {"role": "system", "content": "You are a research assistant. Provide factual short answers to your prompts. The user will provide reference data followed by instructions."},
40
+ {"role": "user", "content": f"{text}\n\n{user_prompt}"},
41
  ]
42
  )
43
  return response['choices'][0]['message']['content']
 
67
  chunk = tokens[i:i + 2000]
68
  chunk_str = ' '.join(chunk)
69
  # Using OpenAI API
70
+ response = call_openai_api(chunk_str, user_prompt)
71
  texts.append(response)
72
  else:
73
  # Using OpenAI API
74
+ response = call_openai_api(text, user_prompt)
75
  texts.append(response)
76
  return '\n'.join(texts)
77