AI Tools
Error Enhancement
Request
Shows additional context and suggestions for error messages. The /ai/tools/error-enhance API accepts requests in the following format:
ErrorEnhanceRequest Model - Request to show additional context and suggestions for error messages. | |
|---|---|
| language | string Enum Programming language for the code completion. Options : ['C#', 'Py'] |
| error | Error object Error information. |
| Example |
{
"language": "Py",
"error": {
"message": "string",
"stacktrace": "string"
}
}
|
Error Model - Error information. | |
|---|---|
| message | string Error message. |
| stacktrace | string Stack trace of the error. |
| Example |
{
"message": "string",
"stacktrace": "string"
}
|
Responses
The /ai/tools/error-enhance API provides a response in the following format:
200 Success
ErrorEnhanceResponse Model - Response to error enhancement request. | |
|---|---|
| state | string State of the code completion. |
| version | string Version of the response. |
| payload | string Error message suggestions. |
| payloadType | string Type of the payload, e.g. String. |
| Example |
{
"state": "End",
"version": 2.0,
"payload": "string",
"payloadType": "String"
}
|
401 Authentication Error
UnauthorizedError Model - Unauthorized response from the API. Key is missing, invalid, or timestamp is too old for hash. | |
|---|---|
| www_authenticate | string Header |
Examples
The following example demonstates how to get additional context and suggestions for error messages through the cloud API.
from base64 import b64encode
from hashlib import sha256
from time import time
from requests import get, post
BASE_URL = 'https://www.quantconnect.com/api/v2/'
# You need to replace these with your actual credentials.
# You can request your credentials at https://www.quantconnect.com/settings/
# You can find our organization ID at https://www.quantconnect.com/organization/
USER_ID = 0
API_TOKEN = '____'
ORGANIZATION_ID = '____'
def get_headers():
# Get timestamp
timestamp = f'{int(time())}'
time_stamped_token = f'{API_TOKEN}:{timestamp}'.encode('utf-8')
# Get hased API token
hashed_token = sha256(time_stamped_token).hexdigest()
authentication = f'{USER_ID}:{hashed_token}'.encode('utf-8')
authentication = b64encode(authentication).decode('ascii')
# Create headers dictionary.
return {
'Authorization': f'Basic {authentication}',
'Timestamp': timestamp
}
# Authenticate to verify credentials
response = post(f'{BASE_URL}/authenticate', headers = get_headers())
print(response.json())
# --------------------
### Error Enhancement
# Send a POST request to the /ai/tools/error-enhance endpoint to enhance error message
response = post(f'{BASE_URL}/ai/tools/error-enhance/', headers=get_headers(), json={
"language": "Python", # Programming language of the code
"error": { # Error details
"message": ''' at initialize
self._option = self.add_index_option("SPX", Resolution.MINUTE, "SPXW").symbol
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
in c1afe80a-e056-4841-b0c1-d9c562cf2bd8.py: line 15
The specified market wasn't found in the markets lookup. Requested: spxw. You can add markets by calling QuantConnect.Market.Add(string,int) (Parameter 'market')''', # Error message
"stacktrace": "" # Stacktrace (empty in this case)
}
})
# Parse the JSON response
result = response.json()
# Check if the request was successful and print the enhanced error details
if result['success']:
print("Enhanced Error Details:")
print(result)