1. Learn
  2. /
  3. Courses
  4. /
  5. Prompt Engineering with the OpenAI API

Connected

Exercise

Customizing output format

You work as a developer at a startup that offers a text analysis platform for content creators. Your platform helps users automatically categorize and format their content, and you're now working on a new feature that detects the language of a given piece of text and generates a suitable title for that text in a custom format. You decide to craft a prompt that guides the language model through this.

The OpenAI package, the get_response() function, and the text variable have been pre-loaded for you.

Instructions

100 XP
  • Create the instructions for the prompt, asking the model to determine the language and generate a suitable title for the pre-loaded text excerpt that will be provided using triple backticks (```) delimiters.
  • Create the output_format with directions to include the text, language, and title, each on a separate line, using 'Text:', 'Language:', and 'Title:' as prefixes for each line.
  • Create the final_prompt by combining all parts and the delimited text to use.