Skip to content

Commit 8151628

Browse files
[Bug]Add instructions and warning for token limit parameters for OpenAI models (#51)
* Add instructions for token limit parameters fro OpenAI models Add instructions for token limit parameters fro OpenAI models * Bump oci requirement to >=2.161.0 Upgrade oci dependency from >=2.144.0 to >=2.161.0
1 parent 2ce0bf5 commit 8151628

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

libs/oci/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ This repository includes two main integration categories:
3030
```python
3131
from langchain_oci import ChatOCIGenAI
3232

33-
llm = ChatOCIGenAI()
33+
llm = ChatOCIGenAI(
34+
model_id="MY_MODEL_ID",
35+
service_endpoint="MY_SERVICE_ENDPOINT",
36+
compartment_id="MY_COMPARTMENT_ID",
37+
model_kwargs={"max_tokens": 1024}, # Use max_completion_tokens instead of max_tokens for OpenAI models
38+
auth_profile="MY_AUTH_PROFILE",
39+
is_stream=True,
40+
auth_type="SECURITY_TOKEN"
3441
llm.invoke("Sing a ballad of LangChain.")
3542
```
3643

libs/oci/langchain_oci/chat_models/oci_generative_ai.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,15 @@ def _prepare_request(
11461146
if stop is not None:
11471147
_model_kwargs[self._provider.stop_sequence_key] = stop
11481148

1149+
# Warn if using max_tokens with OpenAI models
1150+
if self.model_id and self.model_id.startswith("openai.") and "max_tokens" in _model_kwargs:
1151+
import warnings
1152+
warnings.warn(
1153+
f"OpenAI models require 'max_completion_tokens' instead of 'max_tokens'.",
1154+
UserWarning,
1155+
stacklevel=2
1156+
)
1157+
11491158
chat_params = {**_model_kwargs, **kwargs, **oci_params}
11501159

11511160
if not self.model_id:

libs/oci/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ license = "UPL"
1414
python = ">=3.9,<4.0"
1515
langchain-core = ">=0.3.20,<1.0.0"
1616
langchain = ">=0.3.20,<1.0.0"
17-
oci = ">=2.144.0"
17+
oci = ">=2.161.0"
1818
pydantic = ">=2,<3"
1919
aiohttp = ">=3.12.14"
2020

0 commit comments

Comments
 (0)