diff --git a/llm/bedrock.py b/llm/bedrock.py index f3f6a72..0df9069 100644 --- a/llm/bedrock.py +++ b/llm/bedrock.py @@ -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) \ No newline at end of file + 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 \ No newline at end of file