image.py 950 B

123456789101112131415161718192021222324252627282930
  1. from typing import Dict
  2. from langchain_anthropic import ChatAnthropic
  3. from common.config.tokenizer_manage_config import TokenizerManage
  4. from models_provider.base_model_provider import MaxKBBaseModel
  5. def custom_get_token_ids(text: str):
  6. tokenizer = TokenizerManage.get_tokenizer()
  7. return tokenizer.encode(text)
  8. class AnthropicImage(MaxKBBaseModel, ChatAnthropic):
  9. @staticmethod
  10. def is_cache_model():
  11. return False
  12. @staticmethod
  13. def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs):
  14. optional_params = MaxKBBaseModel.filter_optional_params(model_kwargs)
  15. return AnthropicImage(
  16. model=model_name,
  17. anthropic_api_url=model_credential.get('api_base'),
  18. anthropic_api_key=model_credential.get('api_key'),
  19. # stream_options={"include_usage": True},
  20. streaming=True,
  21. **optional_params,
  22. )