Spaces:
Running
Running
File size: 1,674 Bytes
75ddbd7 328de20 |
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 39 40 41 42 43 44 45 46 47 48 49 50 |
import requests
import json
# import requests
# import json
# url = "http://127.0.0.1:8000/chat"
# payload = {
# "model": "your-model-name",
# "message": "Create a json object of top 10 anime! answer in json only!",
# "messages": []
# }
# headers = {
# "Content-Type": "application/json"
# }
# # Send streaming POST request
# with requests.post(url, data=json.dumps(payload), headers=headers, stream=True) as response:
# if response.status_code == 200:
# for line in response.iter_lines(decode_unicode=True):
# if line and line.startswith('data: '):
# try:
# # Remove 'data: ' prefix and parse JSON
# json_data = json.loads(line[6:])
# # Extract text from choices if available
# if json_data.get('choices') and len(json_data['choices']) > 0:
# text = json_data['choices'][0].get('text', '')
# if text:
# print(text, end='')
# except json.JSONDecodeError:
# continue
# else:
# print("Error:", response.status_code, response.text)
def search_chips(term, num_results=10, advanced=False, unique=False):
url = f"http://127.0.0.1:8000/chipsearch?term={term}&num_results={num_results}&advanced={advanced}&unique={unique}"
try:
response = requests.post(url)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
return None
results = search_chips("top 10 anime of all time")
print(results) |