import json import requests def toolgen_request(endpoint_url, query, system_prompt=None): payload = { "query": query, "system_prompt": system_prompt } try: response = requests.post(endpoint_url, json=payload, stream=True) # Enable streaming response.raise_for_status() # Raise an error for HTTP errors for line in response.iter_lines(decode_unicode=True): if line: # Filter out keep-alive new lines yield json.loads(line) # Parse each line as JSON except requests.exceptions.RequestException as e: print(f"Error calling ToolGen model: {e}") yield {"error": str(e)}