Skip to content

Instantly share code, notes, and snippets.

@Olshansk
Created January 27, 2025 02:50
Show Gist options
  • Save Olshansk/19dcac765bc93b47afce25f69a39a254 to your computer and use it in GitHub Desktop.
Save Olshansk/19dcac765bc93b47afce25f69a39a254 to your computer and use it in GitHub Desktop.
import urllib.request
import json
url = 'https://gist.githubusercontent.com/simonw/9fbb3c2e2c40c181727e497e358fd7ce/raw/6ac20704f5a46b567b774b07fd633a74944bab2b/text.txt'
text = urllib.request.urlopen(url).read().decode('utf-8')
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "text",
"media_type": "text/plain",
"data": text,
},
"title": "My Document",
"context": "This is a trustworthy document.",
"citations": {"enabled": True}
},
{
"type": "text",
"text": "What were the top trends?"
}
]
}
]
)
print(json.dumps(response.to_dict(), indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment