wenxin_model_provider.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # coding=utf-8
  2. """
  3. @project: maxkb
  4. @Author:虎
  5. @file: wenxin_model_provider.py
  6. @date:2023/10/31 16:19
  7. @desc:
  8. """
  9. import os
  10. from common.utils.common import get_file_content
  11. from models_provider.base_model_provider import ModelProvideInfo, ModelTypeConst, ModelInfo, IModelProvider, \
  12. ModelInfoManage
  13. from models_provider.impl.wenxin_model_provider.credential.embedding import QianfanEmbeddingCredential
  14. from models_provider.impl.wenxin_model_provider.credential.llm import WenxinLLMModelCredential
  15. from models_provider.impl.wenxin_model_provider.credential.reranker import QfRerankerCredential
  16. from models_provider.impl.wenxin_model_provider.model.embedding import QianfanEmbeddings
  17. from models_provider.impl.wenxin_model_provider.model.llm import QianfanChatModel
  18. from maxkb.conf import PROJECT_DIR
  19. from django.utils.translation import gettext as _
  20. from models_provider.impl.wenxin_model_provider.model.reranker import QfBgeReranker
  21. win_xin_llm_model_credential = WenxinLLMModelCredential()
  22. qianfan_embedding_credential = QianfanEmbeddingCredential()
  23. qf_reranker_credential = QfRerankerCredential()
  24. model_info_list = [ModelInfo('ERNIE-Bot-4',
  25. _('ERNIE-Bot-4 is a large language model independently developed by Baidu. It covers massive Chinese data and has stronger capabilities in dialogue Q&A, content creation and generation.'),
  26. ModelTypeConst.LLM, win_xin_llm_model_credential, QianfanChatModel),
  27. ModelInfo('ERNIE-Bot',
  28. _('ERNIE-Bot is a large language model independently developed by Baidu. It covers massive Chinese data and has stronger capabilities in dialogue Q&A, content creation and generation.'),
  29. ModelTypeConst.LLM, win_xin_llm_model_credential, QianfanChatModel),
  30. ModelInfo('ERNIE-Bot-turbo',
  31. _('ERNIE-Bot-turbo is a large language model independently developed by Baidu. It covers massive Chinese data, has stronger capabilities in dialogue Q&A, content creation and generation, and has a faster response speed.'),
  32. ModelTypeConst.LLM, win_xin_llm_model_credential, QianfanChatModel),
  33. ModelInfo('qianfan-chinese-llama-2-13b',
  34. '',
  35. ModelTypeConst.LLM, win_xin_llm_model_credential, QianfanChatModel),
  36. ModelInfo('ernie-4.5-turbo-32k', '', ModelTypeConst.LLM, win_xin_llm_model_credential,
  37. QianfanChatModel),
  38. ModelInfo('ernie-speed-8k', '', ModelTypeConst.LLM, win_xin_llm_model_credential, QianfanChatModel),
  39. ModelInfo('ernie-4.5-0.3b', '', ModelTypeConst.LLM, win_xin_llm_model_credential, QianfanChatModel)
  40. ]
  41. embedding_model_info_list = [ModelInfo('Embedding-V1',
  42. _('Embedding-V1 is a text representation model based on Baidu Wenxin large model technology. It can convert text into a vector form represented by numerical values and can be used in text retrieval, information recommendation, knowledge mining and other scenarios. Embedding-V1 provides the Embeddings interface, which can generate corresponding vector representations based on input content. You can call this interface to input text into the model and obtain the corresponding vector representation for subsequent text processing and analysis.'),
  43. ModelTypeConst.EMBEDDING, qianfan_embedding_credential, QianfanEmbeddings),
  44. ModelInfo('tao-8k', '', ModelTypeConst.EMBEDDING, qianfan_embedding_credential,
  45. QianfanEmbeddings),
  46. ModelInfo('bge-large-zh', '', ModelTypeConst.EMBEDDING, qianfan_embedding_credential,
  47. QianfanEmbeddings)
  48. ]
  49. rerank_model_info_list = [ModelInfo('bce-reranker-base',
  50. _(''),
  51. ModelTypeConst.RERANKER, qf_reranker_credential, QfBgeReranker),
  52. ]
  53. model_info_manage = (ModelInfoManage.builder().append_model_info_list(model_info_list).append_default_model_info(
  54. ModelInfo('ERNIE-Bot-4',
  55. _('ERNIE-Bot-4 is a large language model independently developed by Baidu. It covers massive Chinese data and has stronger capabilities in dialogue Q&A, content creation and generation.'),
  56. ModelTypeConst.LLM,
  57. win_xin_llm_model_credential,
  58. QianfanChatModel)).append_model_info_list(embedding_model_info_list).append_default_model_info(
  59. embedding_model_info_list[0]).
  60. append_model_info_list(rerank_model_info_list).append_default_model_info(
  61. rerank_model_info_list[0]).build())
  62. class WenxinModelProvider(IModelProvider):
  63. def get_model_info_manage(self):
  64. return model_info_manage
  65. def get_model_provide_info(self):
  66. return ModelProvideInfo(provider='model_wenxin_provider', name=_('Thousand sails large model'),
  67. icon=get_file_content(
  68. os.path.join(PROJECT_DIR, "apps", 'models_provider', 'impl',
  69. 'wenxin_model_provider', 'icon',
  70. 'azure_icon_svg')))