llm/bedrock.py aktualisiert

This commit is contained in:
2026-07-05 09:55:11 +00:00
parent f291cb950a
commit 46a3c86dc5
+20 -3
View File
@@ -1,6 +1,7 @@
import boto3
import asyncio
from config import AWS_REGION, BEDROCK_MODEL
from botocore.exceptions import ClientError
class BedrockClient:
@@ -11,10 +12,14 @@ class BedrockClient:
)
async def chat(self, messages, tools=None):
request = {
"modelId": BEDROCK_MODEL,
"messages": messages,
"inferenceConfig": {
"maxTokens": 1000,
"temperature": 0.7,
"topP": 0.9
}
}
if tools:
@@ -22,4 +27,16 @@ class BedrockClient:
"tools": tools
}
return self.client.converse(**request)
try:
# Synchronen boto3-Aufruf in Executor auslagern
loop = asyncio.get_running_loop()
response = await loop.run_in_executor(
None,
lambda: self.client.converse(**request)
)
return response
except ClientError as e:
raise Exception(f"Bedrock API Error: {e}") from e
except Exception as e:
raise Exception(f"Unexpected error in Bedrock chat: {e}") from e