Spaces:
Sleeping
Sleeping
File size: 1,571 Bytes
ac13c4a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# agents2.py
import requests
import json
import os
key = os.getenv("API-KEY")
api_key = key
def extract_search_string(content):
possible_operators = ['AND', 'OR', 'NOT', '"']
for line in content.split('\n'):
if any(op in line for op in possible_operators):
return line
return content
def generate_search_string_with_gpt(objective, research_questions):
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
# Removed the explicit instruction for logical operators
combined_prompt = f"Given the research objective: '{objective}', and the following research questions: {', '.join(research_questions)}, generate two concise search string for identifying relevant literature for literature review.Do not include OR. Use AND if needed."
data = {
"model": "gpt-3.5-turbo",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": combined_prompt}
],
"temperature": 0.7
}
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, data=json.dumps(data))
if response.status_code == 200:
result = response.json()
content = result['choices'][0]['message']['content']
search_string = extract_search_string(content)
return search_string.strip()
else:
print(f"Error: {response.status_code}")
print(response.text)
return "An error occurred while generating the search string." |