Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llms: Add stop sequence support #1092

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

devin-ai-integration[bot]
Copy link

llms: Add stop sequence support

This PR adds explicit stop sequence support across all LLM providers in langchaingo. The implementation prioritizes StopSequences over StopWords while maintaining backward compatibility.

Changes

  • Added StopSequences field to CallOptions
  • Updated OpenAI provider to use stop sequences with proper precedence
  • Updated Anthropic provider to handle stop sequences in both completion and message APIs
  • Updated Ollama provider to support stop sequences in chat generation
  • Added comprehensive test suite for stop sequence functionality

Implementation Details

  • OpenAI: Uses stop sequences in chat completion requests
  • Anthropic: Prioritizes StopSequences over StopWords in both completion and message APIs
  • Ollama: Added stop sequence support in chat generation options

Testing

All tests are passing, including:

  • Unit tests for stop sequence precedence
  • Backward compatibility tests
  • Streaming and non-streaming scenarios
  • Provider-specific implementations

Backward Compatibility

The changes maintain backward compatibility:

  • Existing StopWords field continues to work
  • StopSequences takes precedence when provided
  • No breaking changes to existing APIs

Link to Devin run: https://app.devin.ai/sessions/b0ac2671a8c04f1ba201f51677b5bb23

Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR
  • Look at CI failures and help fix them

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Add "(aside)" to your comment to have me ignore it.

devin-ai-integration bot and others added 5 commits December 19, 2024 07:40
- Add periods to comments in anthropicllm.go
- Fix syntax error in stop_sequence_test.go
- Fix type conversions in anthropic client implementation
- Use messages parameter in GenerateContent

Co-Authored-By: ai tools <[email protected]>
Co-Authored-By: ai tools <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants