Py.Cafe

maartenbreddels/

anthropic-demo

Poetic Responses with Anthropic API

DocsPricing
  • app.py
  • requirements.txt
app.py
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
import streamlit as st
import pycafe
import anthropic

reason = """
Get your API key at the [Anthroptic console](https://console.anthropic.com/settings/keys)
"""
ANTHROPIC_API_KEY = pycafe.get_secret("ANTHROPIC_API_KEY", reason)


client = anthropic.Anthropic(api_key=ANTHROPIC_API_KEY)

message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1000,
    temperature=0,
    system="You are a world-class poet. Respond only with short poems.",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "Why is the ocean salty?"
                }
            ]
        }
    ]
)
st.write(message.content)
requirements.txt
1
2
3
4

streamlit==1.27.2  # currently pinned to this version
anthropic
https://py.cafe/files/maartenbreddels/jiter-demo/jiter-0.6.1-cp312-cp312-pyodide_2024_0_wasm32.whl