Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,7 +59,6 @@ class SupplyChainOptimizer:
|
|
| 59 |
print("Tavily API key not found. Search functionality will use demo mode.")
|
| 60 |
self.tavily = None
|
| 61 |
|
| 62 |
-
|
| 63 |
# Initialize agents
|
| 64 |
self._setup_agents()
|
| 65 |
|
|
@@ -68,30 +67,31 @@ class SupplyChainOptimizer:
|
|
| 68 |
self.latest_optimization = ""
|
| 69 |
self.search_results = ""
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
| 95 |
|
| 96 |
def _setup_agents(self):
|
| 97 |
"""Setup agents with AWS Bedrock Claude"""
|
|
|
|
| 59 |
print("Tavily API key not found. Search functionality will use demo mode.")
|
| 60 |
self.tavily = None
|
| 61 |
|
|
|
|
| 62 |
# Initialize agents
|
| 63 |
self._setup_agents()
|
| 64 |
|
|
|
|
| 67 |
self.latest_optimization = ""
|
| 68 |
self.search_results = ""
|
| 69 |
|
| 70 |
+
def call_claude_api(self, prompt, system_message=""):
|
| 71 |
+
"""Call Claude via AWS Bedrock"""
|
| 72 |
+
if self.demo_mode:
|
| 73 |
+
return "Demo mode response"
|
| 74 |
+
|
| 75 |
+
try:
|
| 76 |
+
body = {
|
| 77 |
+
"anthropic_version": "bedrock-2023-05-31",
|
| 78 |
+
"max_tokens": 4000,
|
| 79 |
+
"system": system_message,
|
| 80 |
+
"messages": [
|
| 81 |
+
{
|
| 82 |
+
"role": "user",
|
| 83 |
+
"content": prompt
|
| 84 |
+
}
|
| 85 |
+
]
|
| 86 |
+
}
|
| 87 |
+
response = self.bedrock_client.invoke_model(
|
| 88 |
+
modelId="anthropic.claude-3-haiku-20240307-v1:0",
|
| 89 |
+
body=json.dumps(body)
|
| 90 |
+
)
|
| 91 |
+
response_body = json.loads(response['body'].read())
|
| 92 |
+
return response_body['content'][0]['text']
|
| 93 |
+
except Exception as e:
|
| 94 |
+
return f"Error calling Claude API: {str(e)}"
|
| 95 |
|
| 96 |
def _setup_agents(self):
|
| 97 |
"""Setup agents with AWS Bedrock Claude"""
|