You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #
  2. # Copyright 2019 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import time
  17. import uuid
  18. from api.db import LLMType
  19. from api.db.db_models import init_database_tables as init_web_db
  20. from api.db.services import UserService
  21. from api.db.services.llm_service import LLMFactoriesService, LLMService
  22. def init_superuser():
  23. user_info = {
  24. "id": uuid.uuid1().hex,
  25. "password": "admin",
  26. "nickname": "admin",
  27. "is_superuser": True,
  28. "email": "kai.hu@infiniflow.org",
  29. "creator": "system",
  30. "status": "1",
  31. }
  32. UserService.save(**user_info)
  33. def init_llm_factory():
  34. factory_infos = [{
  35. "name": "OpenAI",
  36. "logo": "",
  37. "tags": "LLM,TEXT EMBEDDING,SPEECH2TEXT,MODERATION",
  38. "status": "1",
  39. },{
  40. "name": "通义千问",
  41. "logo": "",
  42. "tags": "LLM,TEXT EMBEDDING,SPEECH2TEXT,MODERATION",
  43. "status": "1",
  44. },{
  45. "name": "智普AI",
  46. "logo": "",
  47. "tags": "LLM,TEXT EMBEDDING,SPEECH2TEXT,MODERATION",
  48. "status": "1",
  49. },{
  50. "name": "文心一言",
  51. "logo": "",
  52. "tags": "LLM,TEXT EMBEDDING,SPEECH2TEXT,MODERATION",
  53. "status": "1",
  54. },
  55. ]
  56. llm_infos = [{
  57. "fid": factory_infos[0]["name"],
  58. "llm_name": "gpt-3.5-turbo",
  59. "tags": "LLM,CHAT,4K",
  60. "max_tokens": 4096,
  61. "model_type": LLMType.CHAT.value
  62. },{
  63. "fid": factory_infos[0]["name"],
  64. "llm_name": "gpt-3.5-turbo-16k-0613",
  65. "tags": "LLM,CHAT,16k",
  66. "max_tokens": 16385,
  67. "model_type": LLMType.CHAT.value
  68. },{
  69. "fid": factory_infos[0]["name"],
  70. "llm_name": "text-embedding-ada-002",
  71. "tags": "TEXT EMBEDDING,8K",
  72. "max_tokens": 8191,
  73. "model_type": LLMType.EMBEDDING.value
  74. },{
  75. "fid": factory_infos[0]["name"],
  76. "llm_name": "whisper-1",
  77. "tags": "SPEECH2TEXT",
  78. "max_tokens": 25*1024*1024,
  79. "model_type": LLMType.SPEECH2TEXT.value
  80. },{
  81. "fid": factory_infos[0]["name"],
  82. "llm_name": "gpt-4",
  83. "tags": "LLM,CHAT,8K",
  84. "max_tokens": 8191,
  85. "model_type": LLMType.CHAT.value
  86. },{
  87. "fid": factory_infos[0]["name"],
  88. "llm_name": "gpt-4-32k",
  89. "tags": "LLM,CHAT,32K",
  90. "max_tokens": 32768,
  91. "model_type": LLMType.CHAT.value
  92. },{
  93. "fid": factory_infos[0]["name"],
  94. "llm_name": "gpt-4-vision-preview",
  95. "tags": "LLM,CHAT,IMAGE2TEXT",
  96. "max_tokens": 765,
  97. "model_type": LLMType.IMAGE2TEXT.value
  98. },{
  99. "fid": factory_infos[1]["name"],
  100. "llm_name": "qwen-turbo",
  101. "tags": "LLM,CHAT,8K",
  102. "max_tokens": 8191,
  103. "model_type": LLMType.CHAT.value
  104. },{
  105. "fid": factory_infos[1]["name"],
  106. "llm_name": "qwen-plus",
  107. "tags": "LLM,CHAT,32K",
  108. "max_tokens": 32768,
  109. "model_type": LLMType.CHAT.value
  110. },{
  111. "fid": factory_infos[1]["name"],
  112. "llm_name": "text-embedding-v2",
  113. "tags": "TEXT EMBEDDING,2K",
  114. "max_tokens": 2048,
  115. "model_type": LLMType.EMBEDDING.value
  116. },{
  117. "fid": factory_infos[1]["name"],
  118. "llm_name": "paraformer-realtime-8k-v1",
  119. "tags": "SPEECH2TEXT",
  120. "max_tokens": 25*1024*1024,
  121. "model_type": LLMType.SPEECH2TEXT.value
  122. },{
  123. "fid": factory_infos[1]["name"],
  124. "llm_name": "qwen_vl_chat_v1",
  125. "tags": "LLM,CHAT,IMAGE2TEXT",
  126. "max_tokens": 765,
  127. "model_type": LLMType.IMAGE2TEXT.value
  128. },
  129. ]
  130. for info in factory_infos:
  131. LLMFactoriesService.save(**info)
  132. for info in llm_infos:
  133. LLMService.save(**info)
  134. def init_web_data():
  135. start_time = time.time()
  136. if not UserService.get_all().count():
  137. init_superuser()
  138. if not LLMService.get_all().count():init_llm_factory()
  139. print("init web data success:{}".format(time.time() - start_time))
  140. if __name__ == '__main__':
  141. init_web_db()
  142. init_web_data()