```import anthropic
client = anthropic.Anthropic( # defaults to os.environ.get("ANTHROPIC_API_KEY") api_key=os.environ["ANTHROPIC_API_KEY"] # Save ANTHROPIC_API_KEY in .env )
def create_anthropic_message(system_prompt, user_prompt, anthropic_model = "claude-3-opus-20240229", max_tokens = 200, temperature = 0.999, *kwargs): message = client.messages.create( model=anthropic_model, max_tokens=max_tokens, temperature=temperature, system=system_prompt, # Also include any other arguments in the def function kwargs *kwargs, messages=[{"role": "user","content": [{"type": "text","text": user_prompt}]}]) return (message)
# Run
for i in range(20): try: r = create_anthropic_message("You are an oncology expert","Compose a brief 1-sentence presentation of a US-based patient presenting with Skin Cancer.") print(r.content[0]) except Exception as error: # handle the exception print("An exception occurred:", error)```
Responses --
# Results
ContentBlock(text='A 68-year-old retired Caucasian male from Florida presented with a growing, asymmetric, irregularly bordered, multicolored 8mm lesion on his left forearm that had changed in size and color over the past 6 months.', type='text')
ContentBlock(text='A 62-year-old Caucasian male with a history of extensive sun exposure presents with a rapidly growing, irregularly shaped, darkly pigmented lesion on his left forearm that has changed in size and color over the past 3 months.', type='text')
ContentBlock(text='A 45-year-old fair-skinned male from Florida presents with a suspicious, asymmetric, irregularly bordered, multicolored, and evolving mole on his left upper back that has been growing for the past 3 months.', type='text')
ContentBlock(text='A 62-year-old fair-skinned male from Florida presented with a rapidly growing, asymmetric, irregularly bordered, darkly pigmented lesion on his left shoulder that had changed in size and color over the past 3 months.', type='text')
ContentBlock(text='A 45-year-old Caucasian male construction worker from Florida presents with a rapidly growing, irregularly shaped, ulcerated dark brown lesion on his left forearm that has doubled in size over the past 3 months and is accompanied by swollen lymph nodes in his left axilla.', type='text')
ContentBlock(text='A 62-year-old Caucasian male from Florida presented with a slow-growing, irregularly shaped, dark brown patch on his left shoulder that had changed in size and color over the past 6 months.', type='text')
ContentBlock(text='A 62-year-old Caucasian male from Florida presented with a slowly enlarging, irregularly bordered, pigmented lesion on his left forearm that had changed in color and size over the past 6 months.', type='text')
ContentBlock(text='A 45-year-old Caucasian male construction worker from Florida presents with a rapidly growing, asymmetric, irregularly bordered, multicolored, 8mm diameter lesion on his left upper back that has changed in size and color over the past 3 months.', type='text')
ContentBlock(text='A 62-year-old Caucasian male with a history of extensive sun exposure presents with a rapidly growing, irregularly shaped, ulcerated pigmented lesion measuring 1.5 cm in diameter on his left upper back.', type='text')
[... Same profile with changes in only 1-2 words]