chipling-api / test.py
Maouu's picture
added google search!
328de20
raw
history blame
1.67 kB
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)