Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Enable max tokens for openai and top_p

Magnus Müller6285bfeca0f9
diff --git a/browser_use/llm/openai/chat.py b/browser_use/llm/openai/chat.py
index 96ce849fa..48be7993e 100644
--- a/browser_use/llm/openai/chat.py
+++ b/browser_use/llm/openai/chat.py
@@ -50,6 +50,8 @@ class ChatOpenAI(BaseChatModel):
default_query: Mapping[str, object] | None = None
http_client: httpx.AsyncClient | None = None
_strict_response_validation: bool = False
+ max_completion_tokens: int | None = None
+ top_p: float | None = None
# Static
@property
@@ -150,6 +152,12 @@ class ChatOpenAI(BaseChatModel):
if self.temperature is not None:
model_params['temperature'] = self.temperature
+ if self.max_completion_tokens is not None:
+ model_params['max_completion_tokens'] = self.max_completion_tokens
+
+ if self.top_p is not None:
+ model_params['top_p'] = self.top_p
+
if output_format is None:
# Return string response
response = await self.get_client().chat.completions.create(