jixiaxue 知识库
evidence · 2026-04-15

T0-1-ch00-Tutorial-How-To

/Users/shanfang/Documents/pe/jixiaxuegong/research/提示工程教程/evidence/T0-anthropic/T0-1-ch00-Tutorial-How-To.md

来源:https://github.com/anthropics/prompt-eng-interactive-tutorial 章节:Chapter 0: Tutorial How-To 爬取日期:2026-03-22


Tutorial How-To

This tutorial 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 our static tutorial answer key instead.

How to get started

  1. Clone this repository to your local machine.

  2. Install the required dependencies by running the following command:

!pip install anthropic
  1. Set up your API key and model name. Replace "your_api_key_here" with your actual Anthropic API key.
API_KEY = "your_api_key_here"
MODEL_NAME = "claude-3-haiku-20240307"

# Stores the API_KEY & MODEL_NAME variables for use across notebooks within the IPython store
%store API_KEY
%store MODEL_NAME
  1. Run the notebook cells in order, following the instructions provided.

Usage Notes & Tips 💡

The Anthropic SDK & the Messages API

We will be using the Anthropic python SDK and the Messages API throughout this tutorial.

Below is an example of what running a prompt will look like in this tutorial. First, we create get_completion, which is a helper function that sends a prompt to Claude and returns Claude’s generated response. Run that cell now.

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

Now we will write out an example prompt for Claude and print Claude’s output by running our get_completion helper function. Running the cell below will print out a response from Claude beneath it.

Feel free to play around with the prompt string to elicit different responses from Claude.

# Prompt
prompt = "Hello, Claude!"

# Get Claude's response
print(get_completion(prompt))

The API_KEY and MODEL_NAME variables defined earlier will be used throughout the tutorial. Just make sure to run the cells for each tutorial page from top to bottom.