Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/Anthropic/Anthropic_Chat_with_Claude_v2.ipynb
2973 views
Kernel: Python 3

Anthropic.jpg

Anthropic - Chat with Claude v2



Give Feedback | Bug report

Tags: #anthropic #claude #ai #llm #model #plugin #amazon #bedrock

Last update: 2023-12-12 (Created: 2023-12-12)

Description: This notebook will show how to chat with Claude v2 model from Anthropic.

Input

Import libraries

from IPython.display import Markdown import naas import json

Setup variables

Mandatory

  • name: The name of the plugin.

  • prompt: The prompt for the plugin.

  • model: The name of the model to be used for tokenization.

Optional

  • avatar: Image URL to be displayed in the Naas Chat.

  • output_path: The path where the JSON file should be saved. If not provided, it will be created from the plugin name.

# Mandatory name = "Claude v2" prompt = """ You are a virtual assistant designed to provide information and assistance to users about Claude v2. Start by presenting yourself and what a user can do with you. """ model = "anthropic.claude-v2" # Optional avatar = "https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/.github/assets/logos/Anthropic.jpg" output_path = name.lower().replace(" ", "_") + ".json"

Model

Create Naas Chat plugin

This function will generate the plugin in JSON format and also verify if your prompt adheres to the recommended limit, which is set at 20% of the maximum tokens allowed by the model. Then, it will save your plugin in your local environment.

# Create json plugin = { "name": name, "model": model, "prompt": prompt, "avatar": avatar, } # Save dict to JSON file with open(output_path, "w") as f: json.dump(plugin, f)

Output

Display plugin

The cell below is tagged as 'plugin'. This tag will allow us to use this pre-prompt on our Naas Chat. NB: The plugin must be printed.

print(json.dumps(plugin))
{"name": "Claude v2", "model": "anthropic.claude-v2", "prompt": "\nYou are a virtual assistant designed to provide information and assistance to users about Claude v2.1.\nStart by presenting yourself and what a user can do with you.\n", "avatar": "https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/.github/assets/logos/Anthropic.jpg"}

Create asset

This asset can be utilized by using the command /use in your Naas Chat or by simply clicking on the link provided in the cell below.

plugin_url = naas.asset.add(output_path, params={"inline": True})

Create new chat

You don't need to click on 'Create New Chat' everytime you update your system prompt, you can use the command /refresh.

Markdown(f"[Create New Chat](https://naas.ai/chat/use?plugin_url={plugin_url})")