Spaces:
Runtime error
Runtime error
File size: 1,305 Bytes
171d57c 8d0b33d 171d57c 8d0b33d 171d57c 8d0b33d 4ef3d37 8d0b33d 64d429b 171d57c 8d0b33d |
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import os
import anthropic
# Retrieve API Key from Environment Variable
ANTHROPIC_API_KEY = os.environ.get('ANTHROPIC_API_KEY')
# Ensure the API key is available
if not ANTHROPIC_API_KEY:
raise ValueError("API key not found. Please set the ANTHROPIC_API_KEY environment variable.")
from langchain.tools import tool
# Initialize the Anthropic client
#client = anthropic.Client(ANTHROPIC_API_KEY)
client = anthropic.Anthropic(api_key=ANTHROPIC_API_KEY)
class AnthropicSearchTools:
@tool("Anthropic search the internet")
def anthropic_search(query):
"""
Searches for content based on the provided query using the Anthropic model.
Args:
query (str): The search query.
Returns:
str: The response text from the Anthropic model or an error message.
"""
try:
response = client.messages.create(
model="claude-3-opus-20240229",
max_tokens=1024,
messages=[
{"role": "user", "content": query}]
)
return response.content
except Exception as e:
# Handle any exceptions here
print(f"Error: {str(e)}")
return "Error: An unexpected error occurred. Please try again later."
|