File size: 671 Bytes
f661a7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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)}