Skip to content

Commit 3ce47ff

Browse files
committed
Partial support of reasoning
1 parent b26ee3e commit 3ce47ff

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/api/models/bedrock.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,19 @@ def _parse_request(self, chat_request: ChatRequest) -> dict:
420420
"system": system_prompts,
421421
"inferenceConfig": inference_config,
422422
}
423+
if chat_request.reasoning_effort:
424+
# From OpenAI api, the max_token is not supported in reasoning mode
425+
# Use max_completion_tokens if provided.
426+
max_tokens = chat_request.max_completion_tokens if chat_request.max_completion_tokens else chat_request.max_tokens
427+
inference_config["maxTokens"] = max_tokens
428+
# unset topP - Not supported
429+
inference_config.pop("topP")
430+
args["additionalModelRequestFields"] = {
431+
"reasoning_config": {
432+
"type": "enabled",
433+
"budget_tokens": max_tokens - 1
434+
}
435+
}
423436
# add tool config
424437
if chat_request.tools:
425438
args["toolConfig"] = {
@@ -476,8 +489,13 @@ def _create_response(
476489
message.content = None
477490
else:
478491
message.content = ""
479-
if content:
480-
message.content = content[0]["text"]
492+
for c in content:
493+
if "reasoningContent" in c:
494+
message.reasoning_content = c["reasoningContent"]["reasoningText"].get("text", "")
495+
if "text" in c:
496+
message.content = c["text"]
497+
else:
498+
logger.warning("Unknown tag in message content " + ",".join(c.keys()))
481499

482500
response = ChatResponse(
483501
id=message_id,

src/api/schema.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class ChatRequest(BaseModel):
9494
top_p: float | None = Field(default=1.0, le=1.0, ge=0.0)
9595
user: str | None = None # Not used
9696
max_tokens: int | None = 2048
97+
max_completion_tokens: int | None = None
98+
reasoning_effort: Literal["low", "medium", "high"] | None = None
9799
n: int | None = 1 # Not used
98100
tools: list[Tool] | None = None
99101
tool_choice: str | object = "auto"
@@ -111,6 +113,7 @@ class ChatResponseMessage(BaseModel):
111113
role: Literal["assistant"] | None = None
112114
content: str | None = None
113115
tool_calls: list[ToolCall] | None = None
116+
reasoning_content: str | None = None
114117

115118

116119
class BaseChoice(BaseModel):

src/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
fastapi==0.115.6
1+
fastapi==0.115.8
22
pydantic==2.7.1
33
uvicorn==0.29.0
44
mangum==0.17.0
55
tiktoken==0.6.0
66
requests==2.32.3
77
numpy==1.26.4
8-
boto3==1.35.81
9-
botocore==1.35.81
8+
boto3==1.37.0
9+
botocore==1.37.0

0 commit comments

Comments
 (0)