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.
This exercise is part of the course
Prompt Engineering with the OpenAI API
Exercise instructions
- Create the
instructions
for the prompt, asking the model to determine the language and generate a suitable title for the pre-loadedtext
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 delimitedtext
to use.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
client = OpenAI(api_key="")
# Create the instructions
instructions = ____
# Create the output format
output_format = ____
# Create the final prompt
prompt = ____
response = get_response(prompt)
print(response)