-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent_analyzer.py
More file actions
41 lines (32 loc) · 1.36 KB
/
Copy pathcontent_analyzer.py
File metadata and controls
41 lines (32 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from typing import List
import anthropic
from config import Config
def analyze_and_answer(query: str, scraped_contents: List[str]) -> str:
"""
Uses Claude to summarize the scraped content and answer the query.
Args:
query (str): The original search query.
scraped_contents (list): List of scraped content from web pages.
Returns:
str: A summary and answer based on the scraped content, generated by Claude.
"""
client = anthropic.Anthropic(api_key=Config.ANTHROPIC_API_KEY)
# Combine the scraped contents into a single string
combined_content = "\n\n".join(scraped_contents)
# Prepare the message for Claude
prompt = f"""Based on the following scraped web content, please provide a comprehensive summary and answer to the query: "{query}"
Scraped content:
{combined_content}
Please summarize the key points and provide a clear, concise answer to the query. Keep some of the original phrasing and sentence structure as well retain some of the links to images.
At the end of your answer, add a list of links to the images you used.
"""
# Send the request to Claude
message = client.messages.create(
model="claude-3-5-sonnet-20240620",
max_tokens=1024,
messages=[
{"role": "user", "content": prompt}
]
)
# Return Claude's response
return message.content[0].text