Is it possible to get the response text in HTML format?

At the moment, we get the output text by API unformatted.
ChatGPT replied to use the format=“html” parameter, but that parameter didn’t work.
The question is, maybe there is an option how to get the formatted text, or maybe there is some other way?

import openai

openai.api_key = "YOUR_API_KEY"

prompt = "Generate a short story about a haunted house."
model = "text-davinci-002"
temperature = 0.5
max_tokens = 50
format = "html"

response = openai.Completion.create(
    engine=model,
    prompt=prompt,
    temperature=temperature,
    max_tokens=max_tokens,
    format=format
)

output_text = response.choices[0].text
print(output_text)

What are you expecting ?

You could always preprend your prompt with “Answer should be embedded in html tags.” for example.

prepend = "Answer should be embedded in html tags. "
prompt = preprend + prompt

1 Like

Hi,

There’s no format parameter in the docs.

Always refer to docs

1 Like

Yes, you can get the response text in html, json, xml, knowledge graphs etc. But there is no explicit setting or parameter for it. You need to add instruction to do so. For instance, “Please do the html formatting of the content”.

@Kostarica

you can do this hack

import markdown2
gpt_response="The latest reviews for Hotel Jagdamba are: \n1. \"Best Hotel With Best service\"\n2. \"Quality is too good 👍\"\n3. \"Test was good.\""

text='### '+gpt_response

print(markdown2.markdown(f"""{text}"""))

<h3>The latest reviews for Hotel Jagdamba are:</h3>

<ol>

<li>"Best Hotel With Best service"</li>

<li>"Quality is too good 👍"</li>

<li>"Test was good."</li>

</ol>

The answer is a big YES. I do it all the time in GPT Chat Interface, hence you can do it with your own LLM model/GPT. The art is in the prompt only no need for the python code, just set rules as to how to output and format its plain text answer (i.e. use exclamation mark (!) and alt in square brackets, with an image url in parentheses to display an image in Markdown, if and when GPT outputs it as plain text, instead of its own markdown… right?) - . I also let it display full blogposts with formatted text and images, or can get it to display me a blogpost in html container tags, and even re-explain (not translate, rather re-explain in the indigenous form of a language), all the human readable content, alt and title tags, and other human readable or meta data related translatable text within the html code to be transposed into different languages. I have some sophisticated prompts developed to do this. It wont display video for me yet though in the chat interface… but i can get a decent visual copy and paste for quick mini-blogging, or pasting into a rich text editor and save as pdf, as well as for reblogging the same content in multiple languages whilst maintaining a uniform format





p.s. Sorry if i do not share the prompts.