model_config.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import torch.cuda
  2. import torch.backends
  3. import os
  4. embedding_model_dict = {
  5. "ernie-tiny": "nghuyong/ernie-3.0-nano-zh",
  6. "ernie-base": "nghuyong/ernie-3.0-base-zh",
  7. "text2vec-base": "shibing624/text2vec-base-chinese",
  8. "text2vec": "GanymedeNil/text2vec-large-chinese",
  9. }
  10. # Embedding model name
  11. EMBEDDING_MODEL = "text2vec"
  12. # Embedding running device
  13. EMBEDDING_DEVICE = "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
  14. # supported LLM models
  15. llm_model_dict = {
  16. "chatyuan": "ClueAI/ChatYuan-large-v2",
  17. "chatglm-6b-int4-qe": "THUDM/chatglm-6b-int4-qe",
  18. "chatglm-6b-int4": "THUDM/chatglm-6b-int4",
  19. "chatglm-6b-int8": "THUDM/chatglm-6b-int8",
  20. "chatglm-6b": "THUDM/chatglm-6b",
  21. }
  22. # LLM model name
  23. LLM_MODEL = "chatglm-6b"
  24. # LLM lora path,默认为空,如果有请直接指定文件夹路径
  25. LLM_LORA_PATH = ""
  26. USE_LORA = True if LLM_LORA_PATH else False
  27. # LLM streaming reponse
  28. STREAMING = True
  29. # Use p-tuning-v2 PrefixEncoder
  30. USE_PTUNING_V2 = False
  31. # LLM running device
  32. LLM_DEVICE = "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
  33. VS_ROOT_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "vector_store")
  34. UPLOAD_ROOT_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "content")
  35. # 基于上下文的prompt模版,请务必保留"{question}"和"{context}"
  36. PROMPT_TEMPLATE = """已知信息:
  37. {context}
  38. 根据上述已知信息,简洁和专业的来回答用户的问题。如果无法从中得到答案,请说 “根据已知信息无法回答该问题” 或 “没有提供足够的相关信息”,不允许在答案中添加编造成分,答案请使用中文。 问题是:{question}"""
  39. # 文本分句长度
  40. SENTENCE_SIZE = 100
  41. # 匹配后单段上下文长度
  42. CHUNK_SIZE = 250
  43. # LLM input history length
  44. LLM_HISTORY_LEN = 3
  45. # return top-k text chunk from vector store
  46. VECTOR_SEARCH_TOP_K = 5
  47. NLTK_DATA_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "nltk_data")