How to format response from Assistants API

I have been searching online but to no avail. Is there a way to format the response (e.g. paragraphs, bullet points, numbered lists) when they exist?

I can see this is possible since the playground renders the response appropriately, but when I examine the code, the text is just a single string (no new line (\n) no way to indicate that something is a bullet point or an indented bullet point etc).

Here’s how I extract the response currently:

# ....First, validate the run was completed and successful...
#.........
#........

messages = openai.beta.threads.messages.list(
    thread_id=thread.id
)

my_msg = messages.data[0].content[0].text.value

#Above, my_msg is always just a long string....

How to extract formatting??

I have an idea that I haven’t tried yet for this issue: JSON. They said that both 4turbo and the new 3.5 version can output accurate JSON consistently. I’m assuming that if you set up the format you want in 4turbo or 3.5 and then parse the JSON into your desired end format afterwards, you should be fine.

Let me know if it works please :smiley:

Most language will have a library that will help translate the markup syntax returned by messages.data[0].content[0].text.value.
For Python, https://python-markdown.github.io/ is very useful.

JSON is useful if you are parsing the message and want to do something with specific bits of info but of you are dumping the text in the message back to the user (like in a chat window), a markup to html translator like the one linked above has worked well for us.

1 Like

I use Highlight JS to apply some javascript/client-side rendering of the text in Flask