We can import it with:from langchain.llms import Anthropicmodel = Anthropic()This model class is designed to work with normal PromptTemplates. An example of that is below:prompt = PromptTemplate.from_template("Tell me a joke about {topic}")chain = prompt | modelchain.invoke({"topic": "bears"})Let's see what is going on with the prompt templating under the hood!prompt_value = prompt.format_prompt(topic="bears")model.convert_prompt(prompt_value)This outputs the following'\n\nHuman: Tell me a joke about bears\n\nAssistant: Sure, here you go:\n'Notice that it adds the Human tag at the start of the string, and then finishes it with \n\nAssistant: Sure, here you go:.
The extra Sure, here you go was added on purpose by the Anthropic team.What happens if we have those symbols in the prompt directly?prompt = PromptTemplate.from_template("Human: Tell me a joke about {topic}")prompt_value = prompt.format_prompt(topic="bears")model.convert_prompt(prompt_value)This outputs:'\n\nHuman: Tell me a joke about bears'We can see that we detect that the user is trying to use the special tokens, and so we don't do any formatting.PreviousProvidersNextAWSPrompting OverviewPrompting Best PracticesChatAnthropicDeprecated AnthropicCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.
All functionality related to Anthropic models.
All functionality related to Anthropic models. ->: We can import it with:from langchain.llms import Anthropicmodel = Anthropic()This model class is designed to work with normal PromptTemplates. An example of that is below:prompt = PromptTemplate.from_template("Tell me a joke about {topic}")chain = prompt | modelchain.invoke({"topic": "bears"})Let's see what is going on with the prompt templating under the hood!prompt_value = prompt.format_prompt(topic="bears")model.convert_prompt(prompt_value)This outputs the following'\n\nHuman: Tell me a joke about bears\n\nAssistant: Sure, here you go:\n'Notice that it adds the Human tag at the start of the string, and then finishes it with \n\nAssistant: Sure, here you go:.
The extra Sure, here you go was added on purpose by the Anthropic team.What happens if we have those symbols in the prompt directly?prompt = PromptTemplate.from_template("Human: Tell me a joke about {topic}")prompt_value = prompt.format_prompt(topic="bears")model.convert_prompt(prompt_value)This outputs:'\n\nHuman: Tell me a joke about bears'We can see that we detect that the user is trying to use the special tokens, and so we don't do any formatting.PreviousProvidersNextAWSPrompting OverviewPrompting Best PracticesChatAnthropicDeprecated AnthropicCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.