Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
vblagoje committed Aug 20, 2024
1 parent 37908ce commit f50b491
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
28 changes: 18 additions & 10 deletions integrations/anthropic/example/prompt_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,33 @@

# Build QA pipeline
qa_pipeline = Pipeline()
qa_pipeline.add_component("llm", AnthropicChatGenerator(
api_key=Secret.from_env_var("ANTHROPIC_API_KEY"),
streaming_callback=print_streaming_chunk,
generation_kwargs={"extra_headers": {"anthropic-beta": "prompt-caching-2024-07-31"}},
))
qa_pipeline.add_component(
"llm",
AnthropicChatGenerator(
api_key=Secret.from_env_var("ANTHROPIC_API_KEY"),
streaming_callback=print_streaming_chunk,
generation_kwargs={"extra_headers": {"anthropic-beta": "prompt-caching-2024-07-31"}},
),
)

questions = ["Why is Monte-Carlo Tree Search used in LATS",
"Summarize LATS selection, expansion, evaluation, simulation, backpropagation, and reflection"]
questions = [
"Why is Monte-Carlo Tree Search used in LATS",
"Summarize LATS selection, expansion, evaluation, simulation, backpropagation, and reflection",
]

# Answer the questions using prompt caching (i.e. the entire document is cached, we run the question against it)
for question in questions:
print("Question: " + question)
result = qa_pipeline.run(
data={
"llm": {"messages": [final_prompt_msg,
ChatMessage.from_user("Given these documents, answer the question:" + question)]},
"llm": {
"messages": [
final_prompt_msg,
ChatMessage.from_user("Given these documents, answer the question:" + question),
]
},
}
)

print("\n\nChecking cache usage:", result["llm"]["replies"][0].meta.get("usage"))
print("\n")

1 change: 1 addition & 0 deletions integrations/anthropic/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ select = [
"YTT",
]
ignore = [
"T201", # print statements
# Allow non-abstract empty methods in abstract base classes
"B027",
# Ignore checks for possible passwords
Expand Down

0 comments on commit f50b491

Please sign in to comment.