Code Monkey home page Code Monkey logo

anthropic-cookbook's Introduction

Anthropic Cookbook

The Anthropic Cookbook provides code and guides designed to help developers build with Claude, providing copy-able code snippets that you can easily integrate into your own projects.

Prerequisites

To make the most of the examples in this cookbook, you'll need an Anthropic API key (sign up for free here).

While the code examples are primarily written in Python, the concepts can be adapted to any programming language that supports interaction with the Anthropic API.

Explore Further

Looking for more resources to enhance your experience with Claude and AI assistants? Check out these helpful links:

Contributing

The Anthropic Cookbook thrives on the contributions of the developer community. We value your input, whether it's submitting an idea, fixing a typo, adding a new guide, or improving an existing one. By contributing, you help make this resource even more valuable for everyone.

To avoid duplication of efforts, please review the existing issues and pull requests before contributing.

If you have ideas for new examples or guides, share them on the issues page.

Table of recipes

anthropic-cookbook's People

Contributors

alexalbertt avatar ben-epstein avatar carsonkahn-external avatar davidhershey avatar eltociear avatar jamescalam avatar jenan-anthropic avatar jpvajda avatar korakot avatar mikez avatar ph-7 avatar ravi03071991 avatar richmondalake avatar stakats avatar zack-anthropic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

anthropic-cookbook's Issues

Add Tools Beta Example using Typescript SDK

I've been experimenting with the Tools beta in Typescript and thought it would be useful to contribute a working example to this repo for those that are looking for non-Python examples.

The POC I've written is a basic command line tool that includes Addition, Subtraction, Division and Multiplication tools.

Is this contribution worth making? I don't think it would take too long to tidy up the code but want to make sure the Anthropic maintainers are wanting to go down this road before spending much time on it.

Claude is not able to understand "before" and "after"

Ran the wiki search notebook (https://github.com/anthropics/anthropic-cookbook/blob/main/long_context/wikipedia-search-cookbook.ipynb) a couple of times. For this particular question, "Which movie came out first: Are You There God It's Me Margaret or Oppenheimer?", the model is able to come up with the right search queries, and correctly summarize the search results. But the model draws a wrong conclusion that Oppenheimer came out first even with the right information.

<information>
- Oppenheimer was released on July 21, 2023
- Are You There God? It's Me, Margaret was released on April 28, 2023
</information>

Based on the release dates found through my searches, **Oppenheimer came out first**, being released on July 21, 2023, while Are You There God? It's Me, Margaret was released later on April 28, 2023.

AI Safety Concerns

I have an issue here that I'm not sure if it was in the right place, saffronh/ccai#1

It seems like the article on your site here, https://www.anthropic.com/index/collective-constitutional-ai-aligning-a-language-model-with-public-input discussed different types of comments but left out this one,

"AI should not promote any form of immorality, like homosexuality, abortion, and trans stupidity! It should not go against the laws of God."

https://www.anthropic.com/index/collective-constitutional-ai-aligning-a-language-model-with-public-input

It also concerns me that this repositories issues remain closed, https://github.com/anthropics/ConstitutionalHarmlessnessPaper which may have been another place to put concerns.

Something is wrong wit the calculator_tool.ipynb cookbook

Cookbook located at tool_use/calculator_tool.ipynb is unable to be opened from GitHub website, nor after downloading the file.
Hyperlink to the file: https://github.com/anthropics/anthropic-cookbook/blob/main/tool_use/calculator_tool.ipynb

The exact error displayed on GH website is:

Invalid Notebook
The Notebook Does Not Appear to Be Valid JSON
Using nbformat v5.10.4 and nbconvert v7.16.1

The exact error displayed in VS Code after attempt to open the file:

The editor could not be opened due to an unexpected error: Bad escaped character in JSON at position 1785 (line 61 column 39)

Chat Model - Remembering the context

Can we have an example of how Claude remembers the context so that the subsequent questions asked by humans can be answered by Claude? Thanks!

How does Claude.ai reads the document uploaded

Query on the notebook "Long Context: PDF "Upload" and Summarization" where it is mentioned that we'll use pypdf to read the pdf. It's not identical to what Claude.ai uses behind the scenes, but it's pretty close.

Trying to replicate the Chat Interface functionality using the Claude API but the results are not good. Is it because of the difference in the approach used by chat interface to read the uploaded document

How to stream with MessageStreamManager?

Hi

I have an instance of the MessageStreamManager which I return from a function, and use in another function to stream my output.

But how do I do that?

Here is what I am returning from a function:

completion = client.messages.stream(
                max_tokens=1024, 
                system=system_message, 
                messages=[{"role": "user", "content": user_message}],
                model="claude-3-haiku-20240307"
                ) 
return completion

How do I then stream the chunks from this completion object, which is a MessageStreamManager?

Doing dir(MessageStreamManager) does not return any method which can be used to stream from this object.

When using tools to get a structured response, the returned array sometimes becomes a string.

Hi!
I found this error.
image
The topics should be an array, as defined in the tool.
const tools: Tool[] = [
{
name: 'print_note_schema',
description: 'Prints a article schema of the input document into well-structured JSON.',
input_schema: {
type: 'object',
properties: {
title: {
type: 'string',
description:
'Title of this article schema. Should be as concise and precise as possible.',
},
summary: {
type: 'string',
description:
'Summary of the input article.',
},
topics: {
type: 'array',
items: {
type: 'object',
properties: {
subtitle: {
type: 'string',
description:
'Subtitle of the topic Should be as concise and precise as possible.And ensure that the topic can match the corresponding content in the summary.',
},
topicSummary: {
type: 'string',
description:
'Summary of the topic. Should be as concise and precise as possible.And ensure that the topic can match the corresponding content in the summary of this schema.',
},
markIds: {
type: 'string',
description:
'What is stored here is the id of the mark related to the current topic. The marks come from the tag in the input.If there are multiple corresponding marks, be sure to use "," to separate them.',
},
additionalSuggestions: {
type: 'string',
description:
'Apart from the input I gave you, what do you think can be expanded on this topic? This content is not required, so the content of the suggestions you give me needs to be non-redundant and to the point.If there are multiple corresponding additionalSuggestions, be sure to use "," to separate them.',
},
},
required: ['subtitle', 'topicSummary', 'markIds', 'additionalSuggestions'],
},
description:
'Array of topics. Should be as specific as possible.And ensure that these topics can match the corresponding content in the summary.',
},
},
required: ['title', 'summary', 'topics'],
},
},
];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.