Skip to content

Conversation

KaparthyReddy
Copy link

Description

Implements strict-mode support for DeepSeek's Beta API function calling feature, as requested in #32670.

Changes

  • Added strict parameter to ChatDeepSeek class to enable strict mode
  • Automatically switches to Beta API endpoint (https://api.deepseek.com/beta) when strict mode is enabled
  • Overrode bind_tools() method to add strict: true to tool function definitions when strict mode is active
  • Added comprehensive unit tests to verify strict mode functionality

Testing

  • All existing tests pass
  • Added new test class TestChatDeepSeekStrictMode with tests for:
    • Beta API endpoint switching
    • Default API usage when strict mode is disabled
    • bind_tools() with strict mode enabled
    • Overriding strict mode per tool binding

Usage Example

   from langchain_deepseek import ChatDeepSeek
   from pydantic import BaseModel, Field
   
   class GetWeather(BaseModel):
       location: str = Field(..., description="City and state")
   
   # Enable strict mode
   model = ChatDeepSeek(
       model="deepseek-chat",
       strict=True,  # Uses Beta API with strict mode
   )
   
   # Bind tools with strict schema enforcement
   model_with_tools = model.bind_tools([GetWeather])
   result = model_with_tools.invoke("What's the weather in SF?")

Resolves #32670

- Add strict parameter to ChatDeepSeek class
- Switch to Beta API endpoint when strict mode is enabled
- Override bind_tools method to add strict: true to tool definitions
- Add comprehensive tests for strict mode functionality

Resolves langchain-ai#32670
@github-actions github-actions bot added feature integration Related to a provider partner package integration and removed feature labels Oct 18, 2025
@ccurme
Copy link
Collaborator

ccurme commented Oct 20, 2025

Closing as duplicated with #32727.

@ccurme ccurme closed this Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration Related to a provider partner package integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(deepseek): Strict-mode

2 participants