tencent_model_provider.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. import os
  4. from common.utils.common import get_file_content
  5. from models_provider.base_model_provider import (
  6. IModelProvider, ModelProvideInfo, ModelInfo, ModelTypeConst, ModelInfoManage
  7. )
  8. from models_provider.impl.tencent_model_provider.credential.embedding import TencentEmbeddingCredential
  9. from models_provider.impl.tencent_model_provider.credential.image import TencentVisionModelCredential
  10. from models_provider.impl.tencent_model_provider.credential.llm import TencentLLMModelCredential
  11. from models_provider.impl.tencent_model_provider.credential.stt import TencentSTTModelCredential
  12. from models_provider.impl.tencent_model_provider.credential.tti import TencentTTIModelCredential
  13. from models_provider.impl.tencent_model_provider.model.embedding import TencentEmbeddingModel
  14. from models_provider.impl.tencent_model_provider.model.image import TencentVision
  15. from models_provider.impl.tencent_model_provider.model.llm import TencentModel
  16. from models_provider.impl.tencent_model_provider.model.stt import TencentSpeechToText
  17. from models_provider.impl.tencent_model_provider.model.tti import TencentTextToImageModel
  18. from maxkb.conf import PROJECT_DIR
  19. from django.utils.translation import gettext as _
  20. def _create_model_info(model_name, description, model_type, credential_class, model_class):
  21. return ModelInfo(
  22. name=model_name,
  23. desc=description,
  24. model_type=model_type,
  25. model_credential=credential_class(),
  26. model_class=model_class
  27. )
  28. def _get_tencent_icon_path():
  29. return os.path.join(PROJECT_DIR, "apps", 'models_provider', 'impl', 'tencent_model_provider',
  30. 'icon', 'tencent_icon_svg')
  31. def _initialize_model_info():
  32. model_info_list = [_create_model_info(
  33. 'hunyuan-pro',
  34. _('The most effective version of the current hybrid model, the trillion-level parameter scale MOE-32K long article model. Reaching the absolute leading level on various benchmarks, with complex instructions and reasoning, complex mathematical capabilities, support for function call, and application focus optimization in fields such as multi-language translation, finance, law, and medical care'),
  35. ModelTypeConst.LLM,
  36. TencentLLMModelCredential,
  37. TencentModel
  38. ),
  39. _create_model_info(
  40. 'hunyuan-standard',
  41. _('A better routing strategy is adopted to simultaneously alleviate the problems of load balancing and expert convergence. For long articles, the needle-in-a-haystack index reaches 99.9%'),
  42. ModelTypeConst.LLM,
  43. TencentLLMModelCredential,
  44. TencentModel),
  45. _create_model_info(
  46. 'hunyuan-lite',
  47. _('Upgraded to MOE structure, the context window is 256k, leading many open source models in multiple evaluation sets such as NLP, code, mathematics, industry, etc.'),
  48. ModelTypeConst.LLM,
  49. TencentLLMModelCredential,
  50. TencentModel),
  51. _create_model_info(
  52. 'hunyuan-role',
  53. _("Hunyuan's latest version of the role-playing model, a role-playing model launched by Hunyuan's official fine-tuning training, is based on the Hunyuan model combined with the role-playing scene data set for additional training, and has better basic effects in role-playing scenes."),
  54. ModelTypeConst.LLM,
  55. TencentLLMModelCredential,
  56. TencentModel),
  57. _create_model_info(
  58. 'hunyuan-functioncall',
  59. _("Hunyuan's latest MOE architecture FunctionCall model has been trained with high-quality FunctionCall data and has a context window of 32K, leading in multiple dimensions of evaluation indicators."),
  60. ModelTypeConst.LLM,
  61. TencentLLMModelCredential,
  62. TencentModel),
  63. _create_model_info(
  64. 'hunyuan-code',
  65. _("Hunyuan's latest code generation model, after training the base model with 200B high-quality code data, and iterating on high-quality SFT data for half a year, the context long window length has been increased to 8K, and it ranks among the top in the automatic evaluation indicators of code generation in the five major languages; the five major languages In the manual high-quality evaluation of 10 comprehensive code tasks that consider all aspects, the performance is in the first echelon."),
  66. ModelTypeConst.LLM,
  67. TencentLLMModelCredential,
  68. TencentModel),
  69. _create_model_info(
  70. 'asr-sentence',
  71. _("This interface is used to recognize short audio files within 60 seconds. Supports Mandarin Chinese, English, Cantonese, Japanese, Vietnamese, Malay, Indonesian, Filipino, Thai, Portuguese, Turkish, Arabic, Hindi, French, German, and 23 Chinese dialects."),
  72. ModelTypeConst.STT,
  73. TencentSTTModelCredential,
  74. TencentSpeechToText),
  75. ]
  76. tencent_embedding_model_info = _create_model_info(
  77. 'hunyuan-embedding',
  78. _("Tencent's Hunyuan Embedding interface can convert text into high-quality vector data. The vector dimension is 1024 dimensions."),
  79. ModelTypeConst.EMBEDDING,
  80. TencentEmbeddingCredential,
  81. TencentEmbeddingModel
  82. )
  83. model_info_embedding_list = [tencent_embedding_model_info]
  84. model_info_vision_list = [_create_model_info(
  85. 'hunyuan-vision',
  86. _('Mixed element visual model'),
  87. ModelTypeConst.IMAGE,
  88. TencentVisionModelCredential,
  89. TencentVision)]
  90. model_info_tti_list = [_create_model_info(
  91. 'hunyuan-dit',
  92. _('Hunyuan graph model'),
  93. ModelTypeConst.TTI,
  94. TencentTTIModelCredential,
  95. TencentTextToImageModel)]
  96. model_info_manage = ModelInfoManage.builder() \
  97. .append_model_info_list(model_info_list) \
  98. .append_model_info_list(model_info_embedding_list) \
  99. .append_model_info_list(model_info_vision_list) \
  100. .append_default_model_info(model_info_vision_list[0]) \
  101. .append_model_info_list(model_info_tti_list) \
  102. .append_default_model_info(model_info_tti_list[0]) \
  103. .append_default_model_info(model_info_list[0]) \
  104. .append_default_model_info(tencent_embedding_model_info) \
  105. .build()
  106. return model_info_manage
  107. class TencentModelProvider(IModelProvider):
  108. def __init__(self):
  109. self._model_info_manage = _initialize_model_info()
  110. def get_model_info_manage(self):
  111. return self._model_info_manage
  112. def get_model_provide_info(self):
  113. icon_path = _get_tencent_icon_path()
  114. icon_data = get_file_content(icon_path)
  115. return ModelProvideInfo(
  116. provider='model_tencent_provider',
  117. name=_('Tencent Hunyuan'),
  118. icon=icon_data
  119. )