File size: 694 Bytes
4824952
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import anthropic
from typing import Union
from fastapi import FastAPI

app = FastAPI()
key = "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"
client = anthropic.Anthropic(api_key=key,)
MODEL_NAME = "claude-3-opus-20240229"

@app.get("/")
def read_root():
    return {"Hello": "Welcome to the response generator by Claude"}


@app.get("/generate/{prompt}")

def read_item(prompt: str):
    response  = message = client.messages.create( model="claude-3-opus-20240229", max_tokens=1024, 
                                                 messages=[{"role": "user", "content": prompt}]
).content[0].text
    return {"response": response}