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

Bedrock cohere fix max length 2048 #4253

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

Conversation

kerlion
Copy link
Contributor

@kerlion kerlion commented May 10, 2024

Description

It includes 2 changes:

  1. For Cohere, count the tokens as text length to avoid 2048 length limitation..
  2. For others, count the tokens with tiktoken tokennizer, uses gpt-4 instead of gpt2.

Fixes #3942

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update, included: Dify Document
  • Improvement, including but not limited to code refactoring, performance optimization, and UI/UX improvement
  • Dependency upgrade

How Has This Been Tested?

Test with text file with consecutive punctuation marks or long English words. It will failed with expected maxLength: 2048 before. Now it is fixed by counting the tokens as chars.

  • TODO

Suggested Checklist:

  • I have performed a self-review of my own code
  • have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
  • optional I have made corresponding changes to the documentation
  • optional I have added tests that prove my fix is effective or that my feature works
  • optional New and existing unit tests pass locally with my changes

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. 🐞 bug Something isn't working 💪 enhancement New feature or request labels May 10, 2024
@takatost takatost requested a review from guchenhe May 10, 2024 06:49
@crazywoola crazywoola changed the title Bedrock coher fix max length 2048 Bedrock cohere fix max length 2048 May 14, 2024
@@ -28,7 +29,7 @@
logger = logging.getLogger(__name__)

class BedrockTextEmbeddingModel(TextEmbeddingModel):

_enc = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

please define this in the get_num_tokens where its needed, instead of the class level

@crazywoola
Copy link
Member

@kerlion Please resolve the conversation above, we will merge it later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 💪 enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AWS bedrock Cohere embedding - got error "expected maxLength: 2048"
3 participants