Add Claude class for Anthropic API integration with message generation
Browse files
app.py
CHANGED
|
@@ -63,7 +63,18 @@ def check_format(answer: str | list, *args, **kwargs) -> list:
|
|
| 63 |
elif isinstance(answer, dict):
|
| 64 |
raise TypeError(f"Final answer must be a list, not a dict. Please check the answer format.")
|
| 65 |
|
|
|
|
|
|
|
|
|
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
## tools definition
|
| 68 |
@tool
|
| 69 |
def download_images(image_urls: str) -> list:
|
|
|
|
| 63 |
elif isinstance(answer, dict):
|
| 64 |
raise TypeError(f"Final answer must be a list, not a dict. Please check the answer format.")
|
| 65 |
|
| 66 |
+
class Claude:
|
| 67 |
+
def __init__(self):
|
| 68 |
+
self.client = anthropic.Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
|
| 69 |
|
| 70 |
+
def generate(self, prompt: str):
|
| 71 |
+
message = self.client.messages.create(
|
| 72 |
+
model="claude-sonnet-4-20250514",
|
| 73 |
+
max_tokens=20000,
|
| 74 |
+
temperature=1,
|
| 75 |
+
messages=[{"role": "user", "content": prompt}]
|
| 76 |
+
)
|
| 77 |
+
return message.content
|
| 78 |
## tools definition
|
| 79 |
@tool
|
| 80 |
def download_images(image_urls: str) -> list:
|