When you use assistant for data visualization in playground it starts to write codes for data pre-processing, data visualization and etc. But when you call assistant api in application that you wrote it only shows the results, not the codes that it generated for getting these results. How can I make it to show the codes that it generated, and results that it got after running this code. Same output as we get in playground.
You can get this from run steps after the completion, where you in this case have the AI output a message before about what it will do, sending to python, then output to user again:
Here’s $0.04 of demonstration of the run steps, where output to code interpreter is a type available.
get https://api.openai.com/v1/threads/{thread_id}/runs/{run_id}/steps
{
"object": "list",
"data": [
{
"id": "step_message creation"
},
{
"id": "step_xxxxxxxxxxxxxxxxxxxxx",
"object": "thread.run.step",
"created_at": 1716076888,
"run_id": "run_xxxxxxxxxxxxxx",
"assistant_id": "asst_xxxxxxxxxxxxxx",
"thread_id": "thread_xxxxxxxxxxxxxx",
"type": "tool_calls",
"status": "completed",
"cancelled_at": null,
"completed_at": 1716075555,
"expires_at": null,
"failed_at": null,
"last_error": null,
"step_details": {
"type": "tool_calls",
"tool_calls": [
{
"id": "call_xxxxxxxxxxxxxxxx",
"type": "code_interpreter",
"code_interpreter": {
"input": "from mpmath import mp\n\n# Set the precision to 102 digits (100 digits after the decimal point plus the '3' before the decimal point)\nmp.dps = 102\n\n# Get the value of pi\npi_str = str(mp.pi)\n\n# Extract the first 100 digits after the decimal point\nfirst_100_digits = pi_str[2:102]\n\n# Convert the digits to integers and sum them\nsum_of_digits = sum(int(digit) for digit in first_100_digits)\nsum_of_digits",
"outputs": [
{
"type": "logs",
"logs": "477"
}
]
}
}
]
},
"usage": {
"prompt_tokens": 215,
"completion_tokens": 113,
"total_tokens": 328
}
},
{message creation
}
}
],
"first_id": "step_333333333333",
"last_id": "step_55555555555",
"has_more": false
}
1 Like