Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions libs/oci/langchain_oci/chat_models/oci_generative_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ def process_stream_tool_calls(
return tool_call_chunks


class MetaProvider(Provider):
"""Provider implementation for Meta."""
class GenericProvider(Provider):
"""Provider for models using generic API spec."""

stop_sequence_key: str = "stop"

Expand Down Expand Up @@ -934,6 +934,11 @@ def process_stream_tool_calls(
return tool_call_chunks


class MetaProvider(GenericProvider):
"""Provider for Meta models. This provider is for backward compatibility."""
pass


class ChatOCIGenAI(BaseChatModel, OCIGenAIBase):
"""ChatOCIGenAI chat model integration.

Expand Down Expand Up @@ -1018,6 +1023,7 @@ def _provider_map(self) -> Mapping[str, Provider]:
return {
"cohere": CohereProvider(),
"meta": MetaProvider(),
"generic": GenericProvider(),
}

@property
Expand Down
26 changes: 18 additions & 8 deletions libs/oci/langchain_oci/llms/oci_generative_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def completion_response_to_text(self, response: Any) -> str:
return response.data.inference_response.generated_texts[0].text


class MetaProvider(Provider):
class GenericProvider(Provider):
"""Provider for models using generic API spec."""
stop_sequence_key: str = "stop"

def __init__(self) -> None:
Expand All @@ -50,6 +51,11 @@ def __init__(self) -> None:

def completion_response_to_text(self, response: Any) -> str:
return response.data.inference_response.choices[0].text


class MetaProvider(GenericProvider):
"""Provider for Meta models. This provider is for backward compatibility."""
pass


class OCIAuthType(Enum):
Expand Down Expand Up @@ -202,14 +208,17 @@ def _identifying_params(self) -> Mapping[str, Any]:
def _get_provider(self, provider_map: Mapping[str, Any]) -> Any:
if self.provider is not None:
provider = self.provider
elif self.model_id is None:
raise ValueError(
"model_id is required to derive the provider, "
"please provide the provider explicitly or specify "
"the model_id to derive the provider."
)
elif self.model_id.startswith(CUSTOM_ENDPOINT_PREFIX):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order might need to change. You have to check the self.model_id is None first, otherwise, this line will raise exception.

Copy link
Member Author

@qiuosier qiuosier Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I moved up the logic to check if model_id is None.

BTW, is there a reason to allow model_id to be None?
It appears to me that the proper way to do model_id validation is not to allow None as default value in OCIGenAIBase. However, this is probably out of the scope here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think allowing model_id to be None was just an old langchain standard of how other vendor packages were doing. We sure can revisit the detail later.

raise ValueError("provider is required for custom endpoints.")
else:
if self.model_id is None:
raise ValueError(
"model_id is required to derive the provider, "
"please provide the provider explicitly or specify "
"the model_id to derive the provider."
)
provider = self.model_id.split(".")[0].lower()

provider = provider_map.get(self.model_id.split(".")[0].lower(), "generic")

if provider not in provider_map:
raise ValueError(
Expand Down Expand Up @@ -269,6 +278,7 @@ def _provider_map(self) -> Mapping[str, Any]:
return {
"cohere": CohereProvider(),
"meta": MetaProvider(),
"generic": GenericProvider(),
}

@property
Expand Down