ChatBot / chatbot.py
Heramb1's picture
Upload 2 files
b433100 verified
import anthropic
# Function to interact with Anthropi API and generate response
def get_anthropic_response(question):
# Initialize the Anthropi client with your API key
client = anthropic.Anthropic(api_key="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")
# Specify parameters for text generation
model_name = "claude-3-opus-20240229"
max_tokens = 1024
# Generate response using the specified model and parameters
message = client.messages.create(
model=model_name,
max_tokens=max_tokens,
messages=[{"role": "user", "content": question}]
)
# Extract and return the generated response
return message.content
# Function to simulate a chatbot interaction
def chatbot(user_message):
# Use the Anthropi model to generate a response
response = get_anthropic_response(user_message)
print(response)
return response[0].text # Directly return the generated text