Anthropic AI models support

This commit is contained in:
ajaysi
2024-06-29 10:04:19 +05:30
parent 591c373aef
commit 60f0bbaa07
4 changed files with 51 additions and 3 deletions

View File

@@ -0,0 +1,33 @@
import os
import anthropic
from anthropic import Anthropic
import streamlit as st
def anthropic_text_response(prompt):
""" """
client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"),)
try:
response = client.messages.create(
max_tokens=1024,
messages=[
{
"role": "user",
"content": prompt,
}
],
# This will come from config file.
model="claude-3-opus-20240229",
)
return(message.content)
except anthropic.APIConnectionError as e:
st.error("The server could not be reached")
st.error(e.__cause__) # an underlying Exception, likely raised within httpx.
except anthropic.RateLimitError as e:
st.error("A 429 status code was received; we should back off a bit.")
except anthropic.APIStatusError as e:
st.error("Another non-200-range status code was received")
st.error(e.status_code)
st.error(e.response)