import requests


remote = "http://chals.tisc25.ctf.sg:35190"


def query(prompt: str, file: str | None=None):
	if file is None:
		response = requests.post(f"{remote}/query", data={"input": prompt})
	else:
		with open(file, 'rb') as fin:
			response = requests.post(f"{remote}/query", files={"input": prompt, "file": fin})

	if response.status_code != 200 or "response" not in response.json():
		raise Exception(f"query failed: {response.status_code} {response.text}")

	response_json = response.json()
	if "response" not in response_json:
		raise Exception(f"unexpected response format: {response}")

	return response_json["response"]
