search

Home  >  Q&A  >  body text

Formatting of chat gpt response

I'm using chat gpt api on my react app. The problem I'm facing is how to format the response from chat gpt. If I ask it to give me a response in a table format it gives a weird response, I'm using pre-tagged to display the text and the response is showing the attached image this way but I want the correct table like chat gpt does if I ask, in the same way it displays as paragraph form instead of any list of items on different lines, so how to format chat GPT response correctly.

I want the correct tables and lists as shown by the chat gpt but this is how I receive the data This is how the data appears when using pre-tagging, but I want the correct table

P粉563446579P粉563446579401 days ago727

reply all(1)I'll reply

  • P粉098417223

    P粉0984172232023-10-26 11:50:14

    ChatGPT and the OpenAI API can return data in a format that works for you. Just add formatting instructions to the prompt.

    Example:

    Return the answer as a JSON object.

    Do you know the 10 most popular books by Stephen King? Returns an array of books in a JSON object.

    ChatGPT Answer:

    {
      "books": [
        {
          "title": "The Shining",
          "year": 1977,
          "description": "A horror novel about a family that moves into an isolated hotel with a dark past."
        },
        {
          "title": "It",
          "year": 1986,
          "description": "A story about a group of friends who confront a shape-shifting evil entity in their small town."
        },
        ...
      ]
    }
    
    

    You can then fine-tune the results using ordered by {something}, group by {something}, etc.

    reply
    0
  • Cancelreply