File size: 984 Bytes
f74c067 |
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 |
import requests
import json
import yaml
def get_search_list_params(query, k=20):
"""
Returns tuple: (search_fields, search_name)
"""
url = "https://aitest.ebalina.com/stream"
response = requests.post(url,
headers={'Content-Type': 'application/json'},
json={"query": query, "k": k},
stream=True)
for line in response.iter_lines():
if line and line.startswith(b'data: '):
try:
data = json.loads(line[6:])
if data.get('log_title') == 'Search List Result':
yaml_data = yaml.safe_load(data['content'])
# As requested, ignoring 'search_name' and only returning fields
return yaml_data.get('search_fields', []), yaml_data.get('search_name', '')
except:
continue
# Return empty list if no valid data is found
return [], "" |