### What problem does this PR solve? Issue link:#264 ### Type of change - [x] Documentation Update - [x] Refactoringtags/v0.1.0
| - CPU >= 2 cores | - CPU >= 2 cores | ||||
| - RAM >= 8 GB | - RAM >= 8 GB | ||||
| - Docker >= 24.0.0 | |||||
| - Docker >= 24.0.0 & Docker Compose >= v2.26.1 | |||||
| > If you have not installed Docker on your local machine (Windows, Mac, or Linux), see [Install Docker Engine](https://docs.docker.com/engine/install/). | > If you have not installed Docker on your local machine (Windows, Mac, or Linux), see [Install Docker Engine](https://docs.docker.com/engine/install/). | ||||
| ### 🚀 Start up the server | ### 🚀 Start up the server |
| - CPU >= 2 cores | - CPU >= 2 cores | ||||
| - RAM >= 8 GB | - RAM >= 8 GB | ||||
| - Docker >= 24.0.0 | |||||
| - Docker >= 24.0.0 & Docker Compose >= v2.26.1 | |||||
| > ローカルマシン(Windows、Mac、または Linux)に Docker をインストールしていない場合は、[Docker Engine のインストール](https://docs.docker.com/engine/install/) を参照してください。 | > ローカルマシン(Windows、Mac、または Linux)に Docker をインストールしていない場合は、[Docker Engine のインストール](https://docs.docker.com/engine/install/) を参照してください。 | ||||
| ### 🚀 サーバーを起動 | ### 🚀 サーバーを起動 |
| - CPU >= 2 核 | - CPU >= 2 核 | ||||
| - RAM >= 8 GB | - RAM >= 8 GB | ||||
| - Docker >= 24.0.0 | |||||
| - Docker >= 24.0.0 & Docker Compose >= v2.26.1 | |||||
| > 如果你并没有在本机安装 Docker(Windows、Mac,或者 Linux), 可以参考文档 [Install Docker Engine](https://docs.docker.com/engine/install/) 自行安装。 | > 如果你并没有在本机安装 Docker(Windows、Mac,或者 Linux), 可以参考文档 [Install Docker Engine](https://docs.docker.com/engine/install/) 自行安装。 | ||||
| ### 🚀 启动服务器 | ### 🚀 启动服务器 |
| language = CharField( | language = CharField( | ||||
| max_length=32, | max_length=32, | ||||
| null=True, | null=True, | ||||
| default="English", | |||||
| default="Chinese", | |||||
| help_text="English|Chinese") | help_text="English|Chinese") | ||||
| llm_id = CharField(max_length=32, null=False, help_text="default llm ID") | llm_id = CharField(max_length=32, null=False, help_text="default llm ID") | ||||
| llm_setting = JSONField(null=False, default={"temperature": 0.1, "top_p": 0.3, "frequency_penalty": 0.7, | llm_setting = JSONField(null=False, default={"temperature": 0.1, "top_p": 0.3, "frequency_penalty": 0.7, |
| # See the License for the specific language governing permissions and | # See the License for the specific language governing permissions and | ||||
| # limitations under the License. | # limitations under the License. | ||||
| # | # | ||||
| import logging | |||||
| from rag.utils import ELASTICSEARCH | |||||
| from rag.nlp import search | |||||
| import os | import os | ||||
| from enum import IntEnum, Enum | from enum import IntEnum, Enum | ||||
| from api.utils import get_base_config, decrypt_database_config | |||||
| from api.utils.file_utils import get_project_base_directory | from api.utils.file_utils import get_project_base_directory | ||||
| from api.utils.log_utils import LoggerFactory, getLogger | from api.utils.log_utils import LoggerFactory, getLogger | ||||
| "logs", | "logs", | ||||
| "api")) | "api")) | ||||
| # {CRITICAL: 50, FATAL:50, ERROR:40, WARNING:30, WARN:30, INFO:20, DEBUG:10, NOTSET:0} | # {CRITICAL: 50, FATAL:50, ERROR:40, WARNING:30, WARN:30, INFO:20, DEBUG:10, NOTSET:0} | ||||
| LoggerFactory.LEVEL = 10 | |||||
| LoggerFactory.LEVEL = 30 | |||||
| stat_logger = getLogger("stat") | stat_logger = getLogger("stat") | ||||
| access_logger = getLogger("access") | access_logger = getLogger("access") | ||||
| database_logger = getLogger("database") | database_logger = getLogger("database") | ||||
| chat_logger = getLogger("chat") | chat_logger = getLogger("chat") | ||||
| database_logger.setLevel(logging.WARNING) | |||||
| from rag.utils import ELASTICSEARCH | |||||
| from rag.nlp import search | |||||
| from api.utils import get_base_config, decrypt_database_config | |||||
| API_VERSION = "v1" | API_VERSION = "v1" | ||||
| RAG_FLOW_SERVICE_NAME = "ragflow" | RAG_FLOW_SERVICE_NAME = "ragflow" | ||||
| "image2text_model": "glm-4v", | "image2text_model": "glm-4v", | ||||
| "asr_model": "", | "asr_model": "", | ||||
| }, | }, | ||||
| "Local": { | |||||
| "Ollama": { | |||||
| "chat_model": "qwen-14B-chat", | "chat_model": "qwen-14B-chat", | ||||
| "embedding_model": "flag-embedding", | "embedding_model": "flag-embedding", | ||||
| "image2text_model": "", | "image2text_model": "", |
| class LoggerFactory(object): | class LoggerFactory(object): | ||||
| TYPE = "FILE" | TYPE = "FILE" | ||||
| LOG_FORMAT = "[%(levelname)s] [%(asctime)s] [jobId] [%(process)s:%(thread)s] - [%(module)s.%(funcName)s] [line:%(lineno)d]: %(message)s" | |||||
| LOG_FORMAT = "[%(levelname)s] [%(asctime)s] [%(module)s.%(funcName)s] [line:%(lineno)d]: %(message)s" | |||||
| logging.basicConfig(format=LOG_FORMAT) | |||||
| LEVEL = logging.DEBUG | LEVEL = logging.DEBUG | ||||
| logger_dict = {} | logger_dict = {} | ||||
| global_handler_dict = {} | global_handler_dict = {} |
| [t for t in random_choices([t for t, _ in sections], k=100)]) | [t for t in random_choices([t for t, _ in sections], k=100)]) | ||||
| if bull >= 0: | if bull >= 0: | ||||
| chunks = ["\n".join(ck) | chunks = ["\n".join(ck) | ||||
| for ck in hierarchical_merge(bull, sections, 3)] | |||||
| for ck in hierarchical_merge(bull, sections, 5)] | |||||
| else: | else: | ||||
| sections = [s.split("@") for s, _ in sections] | sections = [s.split("@") for s, _ in sections] | ||||
| sections = [(pr[0], "@" + pr[1]) for pr in sections if len(pr) == 2] | sections = [(pr[0], "@" + pr[1]) for pr in sections if len(pr) == 2] |
| make_colon_as_title(sections) | make_colon_as_title(sections) | ||||
| bull = bullets_category(sections) | bull = bullets_category(sections) | ||||
| chunks = hierarchical_merge(bull, sections, 3) | |||||
| chunks = hierarchical_merge(bull, sections, 5) | |||||
| if not chunks: | if not chunks: | ||||
| callback(0.99, "No chunk parsed out.") | callback(0.99, "No chunk parsed out.") | ||||
| tk_count = 0 | tk_count = 0 | ||||
| if response.status_code == HTTPStatus.OK: | if response.status_code == HTTPStatus.OK: | ||||
| ans += response.output.choices[0]['message']['content'] | ans += response.output.choices[0]['message']['content'] | ||||
| tk_count += response.usage.output_tokens | |||||
| tk_count += response.usage.total_tokens | |||||
| if response.output.choices[0].get("finish_reason", "") == "length": | if response.output.choices[0].get("finish_reason", "") == "length": | ||||
| ans += "...\nFor the content length reason, it stopped, continue?" if is_english( | ans += "...\nFor the content length reason, it stopped, continue?" if is_english( | ||||
| [ans]) else "······\n由于长度的原因,回答被截断了,要继续吗?" | [ans]) else "······\n由于长度的原因,回答被截断了,要继续吗?" |