You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not set up right now to make it a pull request, but for those who care: You can use the anthropic python sdk now.
!pip install -U anthropic
import anthropic
client = anthropic.Anthropic(
api_key=ANTHROPIC_API_KEY,
)
def ask_claude(system_prompt, messages, model="claude-3-opus-20240229", max_tokens=2000):
try:
message = client.messages.create(
model=model,
max_tokens=max_tokens,
temperature=0.5,
system=system_prompt,
messages=messages
)
# count_tokens(model=model, in_tokens=message.usage.input_tokens, out_tokens=message.usage.output_tokens)
except anthropic.APIConnectionError as e:
print("The server could not be reached")
print(e.__cause__) # an underlying Exception, likely raised within httpx.
except anthropic.RateLimitError as e:
print("A 429 status code was received; we should back off a bit.")
except anthropic.APIStatusError as e:
print("Another non-200-range status code was received")
print(e.status_code)
print(e.response)
return message.content[0].text
The text was updated successfully, but these errors were encountered:
bent-verbiage
changed the title
Anthropic SDK available for python - simplifies code
Anthropic SDK available for python
Apr 2, 2024
Not set up right now to make it a pull request, but for those who care: You can use the anthropic python sdk now.
The text was updated successfully, but these errors were encountered: