new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Prompt Engineering · all subjects

tutorial setup

10 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Helper function pattern: get_completion

The tutorial uses a helper function called get_completion that encapsulates the basic pattern for calling Claude. This function sends a prompt to Claude using the Anthropic SDK and returns Claude's generated response. The function accepts a prompt string and calls client.messages.create() with the model, max_tokens set to 2000, temperature set to 0.0, and messages containing the user's prompt.

Anthropic tutorial requires API key

The prompt engineering interactive tutorial from Anthropic requires an API key for interaction. If you don't have an API key, you can sign up for one via the Anthropic Console or view a static tutorial answer key instead.

Install anthropic SDK

To set up the tutorial environment, run 'pip install anthropic' to install the required dependencies.

Set API_KEY and MODEL_NAME for tutorial

Configure your environment by setting API_KEY to your actual Anthropic API key and MODEL_NAME to 'claude-3-haiku-20240307'. Use %store API_KEY and %store MODEL_NAME in IPython notebooks to store these variables for use across notebooks.

Tutorial uses Claude 3 Haiku with temperature 0

The tutorial uses Claude 3 Haiku with temperature set to 0, which yields more deterministic results. All prompt engineering techniques taught in this course also apply to previous generation legacy Claude models such as Claude 2 and Claude Instant 1.2.

Example: Basic get_completion helper function

import anthropic client = anthropic.Anthropic(api_key=API_KEY) def get_completion(prompt: str): message = client.messages.create( model=MODEL_NAME, max_tokens=2000, temperature=0.0, messages=[ {"role": "user", "content": prompt} ] ) return message.content[0].text This example shows how to create a helper function that sends a prompt to Claude and returns its response using the Anthropic SDK and Messages API.

Example: Calling get_completion with a simple prompt

prompt = "Hello, Claude!" print(get_completion(prompt)) This example demonstrates how to send a prompt to Claude using the get_completion helper function and print the response.

Tutorial uses Anthropic SDK and Messages API

The tutorial uses the Anthropic Python SDK and the Messages API throughout all lessons. These are the primary tools for interacting with Claude.

get_completion helper function signature

The helper function is defined as: get_completion(prompt: str, system_prompt="", prefill="") It creates a message with the Claude API using model from MODEL_NAME variable, max_tokens=2000, temperature=0.0, optional system prompt, and messages list containing the user prompt and optional assistant prefill. Returns message.content[0].text.

Helper function for prompt testing

The tutorial provides a `get_completion()` helper function that takes three parameters: prompt (str), system_prompt (str, default empty), and prefill (str, default empty). It creates a message using the Anthropic client with model=MODEL_NAME, max_tokens=2000, temperature=0.0, includes the system_prompt, and passes the prompt as user content and prefill as assistant content. This function enables easy testing of complex prompts.

Give your agent this brain