Skip to content

Commit 3086b24

Browse files
authored
Merge pull request #23 from nuhatech/dev
Release v0.1.22: Added `use_max_completion_tokens` parameter to `Open…
2 parents 8c1c1fd + 7c02ca7 commit 3086b24

File tree

5 files changed

+47
-14
lines changed

5 files changed

+47
-14
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.1.22] - 2026-02-11
11+
12+
### Added
13+
- **`use_max_completion_tokens` parameter for `OpenAILLM`**: Newer OpenAI models (o1, o3, gpt-5-nano, etc.) require `max_completion_tokens` instead of the deprecated `max_tokens`. Set `use_max_completion_tokens=True` to use the new parameter name. When `max_tokens` is `None`, the parameter is now omitted entirely instead of sending `null` (which some models reject).
14+
- **`use_max_completion_tokens` parameter for `AgenticQueryPipeline`**: Propagated to the internally created `OpenAILLM` when no custom LLM is provided.
15+
1016
## [0.1.21] - 2026-02-11
1117

1218
### Fixed
@@ -264,7 +270,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
264270
- Example scripts for common use cases
265271
- API reference documentation
266272

267-
[Unreleased]: https://github.com/nuhatech/maktaba/compare/v0.1.21...HEAD
273+
[Unreleased]: https://github.com/nuhatech/maktaba/compare/v0.1.22...HEAD
274+
[0.1.22]: https://github.com/nuhatech/maktaba/compare/v0.1.21...v0.1.22
268275
[0.1.21]: https://github.com/nuhatech/maktaba/compare/v0.1.20...v0.1.21
269276
[0.1.20]: https://github.com/nuhatech/maktaba/compare/v0.1.19...v0.1.20
270277
[0.1.19]: https://github.com/nuhatech/maktaba/compare/v0.1.18...v0.1.19

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "maktaba"
3-
version = "0.1.21"
3+
version = "0.1.22"
44
description = "Production-ready RAG infrastructure for multilingual applications"
55
authors = [
66
{name = "NuhaTech", email = "contact@nuhatech.com"}

src/maktaba/llm/openai.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __init__(
3636
temperature: float = 0.0,
3737
timeout_s: float = 30.0,
3838
prompts: Optional[AgenticPrompts] = None,
39+
use_max_completion_tokens: bool = False,
3940
) -> None:
4041
"""
4142
Initialize OpenAI LLM.
@@ -46,12 +47,16 @@ def __init__(
4647
temperature: Sampling temperature (default: 0 for deterministic)
4748
timeout_s: Request timeout in seconds
4849
prompts: Custom prompts for agentic operations (defaults to default_prompts())
50+
use_max_completion_tokens: Use ``max_completion_tokens`` instead of
51+
``max_tokens`` in API calls. Required for newer OpenAI models
52+
(o1, o3, gpt-5-nano, etc.) that no longer accept ``max_tokens``.
4953
"""
5054
self.api_key = api_key
5155
self.model = model
5256
self.temperature = temperature
5357
self.timeout_s = timeout_s
5458
self.prompts = prompts or default_prompts()
59+
self.use_max_completion_tokens = use_max_completion_tokens
5560
self._logger = get_logger("maktaba.llm.openai")
5661

5762
# Lazy client initialization
@@ -70,6 +75,18 @@ def _get_client(self) -> Optional[Any]:
7075
self._client = self._OpenAI(api_key=self.api_key, timeout=self.timeout_s)
7176
return self._client
7277

78+
def _token_limit_kwargs(self, max_tokens: int | None) -> Dict[str, Any]:
79+
"""Build the token-limit keyword argument for the OpenAI API.
80+
81+
Returns an empty dict when *max_tokens* is ``None`` so the parameter
82+
is omitted entirely (some models reject ``null``). When a value is
83+
provided the key name depends on :attr:`use_max_completion_tokens`.
84+
"""
85+
if max_tokens is None:
86+
return {}
87+
key = "max_completion_tokens" if self.use_max_completion_tokens else "max_tokens"
88+
return {key: max_tokens}
89+
7390
def _format_chat_history(self, messages: List[Tuple[str, str]]) -> str:
7491
"""Format chat history as text."""
7592
lines = []
@@ -102,7 +119,7 @@ async def complete_text(
102119
{"role": "user", "content": prompt},
103120
],
104121
temperature=temperature,
105-
max_tokens=max_tokens,
122+
**self._token_limit_kwargs(max_tokens),
106123
)
107124

108125
usage = LLMUsage(
@@ -141,7 +158,7 @@ async def complete_json(
141158
{"role": "user", "content": prompt},
142159
],
143160
temperature=temperature,
144-
max_tokens=max_tokens,
161+
**self._token_limit_kwargs(max_tokens),
145162
response_format={"type": "json_object"},
146163
)
147164

@@ -182,7 +199,7 @@ async def stream_text(
182199
{"role": "user", "content": prompt},
183200
],
184201
temperature=temperature,
185-
max_tokens=max_tokens,
202+
**self._token_limit_kwargs(max_tokens),
186203
stream=True,
187204
)
188205

src/maktaba/pipeline/agentic.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def __init__(
4343
llm_model: str = "gpt-4o-mini",
4444
prompts: Optional[AgenticPrompts] = None,
4545
namespace: Optional[str] = None,
46+
use_max_completion_tokens: bool = False,
4647
) -> None:
4748
"""
4849
Initialize agentic pipeline.
@@ -57,6 +58,9 @@ def __init__(
5758
llm_model: LLM model name
5859
prompts: Custom prompts for LLM operations (defaults to default_prompts())
5960
namespace: Default namespace for searches
61+
use_max_completion_tokens: Use ``max_completion_tokens`` instead of
62+
``max_tokens`` in OpenAI API calls. Required for newer models
63+
(o1, o3, gpt-5-nano, etc.). Only applies when *llm* is not provided.
6064
6165
Example:
6266
# Use default prompts
@@ -85,7 +89,12 @@ def __init__(
8589
if llm is not None:
8690
self.llm = llm
8791
else:
88-
self.llm = OpenAILLM(api_key=llm_api_key, model=llm_model, prompts=prompts)
92+
self.llm = OpenAILLM(
93+
api_key=llm_api_key,
94+
model=llm_model,
95+
prompts=prompts,
96+
use_max_completion_tokens=use_max_completion_tokens,
97+
)
8998

9099
async def _execute_single_query(
91100
self,

uv.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)