#formatting OpenAI API responses

6 messages · Page 1 of 1 (latest)

full anvil
#

Hi guys! I am quite new to openAi API I want make it so the response from OpenAI would be in markdown text I want it so it could be easily formatted I am build a chat bot

#

my current implemation
`
// Make the API request
const completion = await openai.createChatCompletion({
model: 'gpt-3.5-turbo-16k',
messages: newMessages.map(message => ({
role: message.role as ChatCompletionRequestMessageRoleEnum,
content: message.content
})),
max_tokens: 400,
temperature: 0.2,
});

    if (completion.data.choices && completion.data.choices[0].message) {
        newMessages.push({
            role: ChatCompletionRequestMessageRoleEnum.Assistant,
            content: completion.data.choices[0].message.content!,
            display: true,
        });
    }

`

#

I want that it would format the text like GTP so and I why I want it to return it in markdown type with new lines

full anvil
#

Thanks I will check it

full anvil
#

@tidal sphinx it is not consistent I expanded the system prompt it looks like this now
`
Your primary role is to provide responses in a specific text format. This format includes using the literal "\n" for new lines, "* " for bullet points, and "#" for headers.

Your responses should be well-structured and easy to read. Use "\n" to create new lines and separate different sections of your response. When presenting multiple points or steps, use "* " to create bullet points. For section headers, use "#".

For example:

If a user asks for a list of the top 5 programming languages, your response should be a bullet-point list, with each language on a new line preceded by "* ".
If a user asks for a detailed explanation of a concept, your response should include different sections separated by "\n", with each section explaining a subtopic. Each section should start with a header, denoted by "#".
If a user asks for a step-by-step guide, your response should be a bullet-point list with each step clearly explained on a new line. The title of the guide should be a header, denoted by "#".

Remember, the goal is to provide clear, concise, and well-structured responses that are easy to read and understand. Always use "\n" for new lines, "* " for bullet points, and "#" for headers.
`

#

turns out it works the response
`content
:
"Nike is a multinational corporation that specializes in the design, development, manufacturing, and marketing of footwear, apparel, equipment, accessories, and services. It is one of the world's largest suppliers of athletic shoes and apparel, and it is known for its iconic "swoosh" logo.\n\n# History of Nike\nNike was founded in 1964 as Blue Ribbon Sports by Bill Bowerman and Phil Knight. Initially, the company operated as a distributor for the Japanese shoe company Onitsuka Tiger (now ASICS). In 1971, Blue Ribbon Sports rebranded itself as Nike, Inc. and began manufacturing its own line of footwear.\n\n# Products and Services\nNike offers a wide range of products and services, including:\n\n* Footwear: Nike produces athletic shoes for various sports, including running, basketball, soccer, tennis, and more."