Skip to content

Commit

Permalink
Update Anthropic example, use ChatPromptBuilder properly (#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
vblagoje authored Aug 14, 2024
1 parent 4c8c881 commit 1caa410
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions integrations/anthropic/example/documentation_rag_with_claude.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@

messages = [
ChatMessage.from_system("You are a prompt expert who answers questions based on the given documents."),
ChatMessage.from_user("Here are the documents: {{documents}} \\n Answer: {{query}}"),
ChatMessage.from_user(
"Here are the documents:\n"
"{% for d in documents %} \n"
" {{d.content}} \n"
"{% endfor %}"
"\nAnswer: {{query}}"
),
]

rag_pipeline = Pipeline()
rag_pipeline.add_component("fetcher", LinkContentFetcher())
rag_pipeline.add_component("converter", HTMLToDocument())
rag_pipeline.add_component("prompt_builder", ChatPromptBuilder())
rag_pipeline.add_component("prompt_builder", ChatPromptBuilder(variables=["documents"]))
rag_pipeline.add_component(
"llm",
AnthropicChatGenerator(
Expand All @@ -32,10 +38,10 @@
rag_pipeline.connect("converter", "prompt_builder")
rag_pipeline.connect("prompt_builder.prompt", "llm.messages")

question = "What are the best practices in prompt engineering?"
question = "When should we use prompt engineering and when should we fine-tune?"
rag_pipeline.run(
data={
"fetcher": {"urls": ["https://docs.anthropic.com/claude/docs/prompt-engineering"]},
"fetcher": {"urls": ["https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/overview"]},
"prompt_builder": {"template_variables": {"query": question}, "template": messages},
}
)

0 comments on commit 1caa410

Please sign in to comment.