2023-06-30 17:10:48 +08:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time : 2023 / 5 / 1 11 : 59
@Author : alexanderwu
@File : const . py
2023-11-27 15:49:05 +08:00
@Modified By : mashenquan , 2023 - 11 - 1. According to Section 2.2 .1 and 2.2 .2 of RFC 116 , added key definitions for
2023-11-03 11:12:59 +08:00
common properties in the Message .
2023-11-27 15:49:05 +08:00
@Modified By : mashenquan , 2023 - 11 - 27. Defines file repository paths according to Section 2.2 .3 .4 of RFC 135.
2023-12-04 23:04:07 +08:00
@Modified By : mashenquan , 2023 / 12 / 5. Add directories for code summarization . .
2023-06-30 17:10:48 +08:00
"""
2023-11-20 11:24:46 +08:00
import os
2023-06-30 17:10:48 +08:00
from pathlib import Path
2023-12-14 22:59:41 +08:00
2023-11-08 19:42:30 +08:00
from loguru import logger
2023-12-14 22:59:41 +08:00
2023-11-20 11:24:46 +08:00
import metagpt
2023-06-30 17:10:48 +08:00
2023-11-28 18:16:50 +08:00
2023-11-20 11:24:46 +08:00
def get_metagpt_package_root ( ) :
""" Get the root directory of the installed package. """
package_root = Path ( metagpt . __file__ ) . parent . parent
2023-12-17 00:23:21 +08:00
for i in ( " .git " , " .project_root " , " .gitignore " ) :
if ( package_root / i ) . exists ( ) :
break
else :
package_root = Path . cwd ( )
2023-11-20 11:24:46 +08:00
logger . info ( f " Package root set to { str ( package_root ) } " )
return package_root
def get_metagpt_root ( ) :
""" Get the project root directory. """
# Check if a project root is specified in the environment variable
2023-11-28 18:16:50 +08:00
project_root_env = os . getenv ( " METAGPT_PROJECT_ROOT " )
2023-11-20 11:24:46 +08:00
if project_root_env :
project_root = Path ( project_root_env )
logger . info ( f " PROJECT_ROOT set from environment variable to { str ( project_root ) } " )
else :
# Fallback to package root if no environment variable is set
project_root = get_metagpt_package_root ( )
return project_root
# METAGPT PROJECT ROOT AND VARS
2024-01-11 22:30:26 +08:00
CONFIG_ROOT = Path . home ( ) / " .metagpt "
2023-12-14 15:06:04 +08:00
METAGPT_ROOT = get_metagpt_root ( ) # Dependent on METAGPT_PROJECT_ROOT
2023-11-20 11:24:46 +08:00
DEFAULT_WORKSPACE_ROOT = METAGPT_ROOT / " workspace "
2023-12-25 21:47:27 +08:00
EXAMPLE_PATH = METAGPT_ROOT / " examples "
2023-11-20 11:24:46 +08:00
DATA_PATH = METAGPT_ROOT / " data "
2023-12-28 22:32:40 +08:00
TEST_DATA_PATH = METAGPT_ROOT / " tests/data "
2023-08-08 22:59:26 +08:00
RESEARCH_PATH = DATA_PATH / " research "
2023-09-06 14:43:24 +08:00
TUTORIAL_PATH = DATA_PATH / " tutorial_docx "
2023-10-10 14:26:03 +08:00
INVOICE_OCR_TABLE_PATH = DATA_PATH / " invoice_table "
2023-07-24 09:44:03 +08:00
2023-11-20 11:24:46 +08:00
UT_PATH = DATA_PATH / " ut "
SWAGGER_PATH = UT_PATH / " files/api/ "
UT_PY_PATH = UT_PATH / " files/ut/ "
API_QUESTIONS_PATH = UT_PATH / " files/question/ "
2023-07-24 09:44:03 +08:00
2023-11-27 21:12:50 +08:00
SERDESER_PATH = DEFAULT_WORKSPACE_ROOT / " storage " # TODO to store `storage` under the individual generated project
2023-11-28 09:29:00 +08:00
2023-11-20 11:24:46 +08:00
TMP = METAGPT_ROOT / " tmp "
2023-07-24 09:44:03 +08:00
2023-11-20 11:24:46 +08:00
SOURCE_ROOT = METAGPT_ROOT / " metagpt "
PROMPT_PATH = SOURCE_ROOT / " prompts "
SKILL_DIRECTORY = SOURCE_ROOT / " skills "
# REAL CONSTS
2023-09-18 12:46:15 +08:00
2023-07-24 09:44:03 +08:00
MEM_TTL = 24 * 30 * 3600
2023-11-01 20:08:58 +08:00
2023-11-08 20:27:18 +08:00
MESSAGE_ROUTE_FROM = " sent_from "
MESSAGE_ROUTE_TO = " send_to "
2023-11-01 20:08:58 +08:00
MESSAGE_ROUTE_CAUSE_BY = " cause_by "
MESSAGE_META_ROLE = " role "
2023-11-06 22:38:43 +08:00
MESSAGE_ROUTE_TO_ALL = " <all> "
2023-11-23 23:04:41 +08:00
MESSAGE_ROUTE_TO_NONE = " <none> "
2023-11-22 17:08:00 +08:00
REQUIREMENT_FILENAME = " requirement.txt "
2023-12-12 21:32:03 +08:00
BUGFIX_FILENAME = " bugfix.txt "
2023-11-27 19:32:33 +08:00
PACKAGE_REQUIREMENTS_FILENAME = " requirements.txt "
2023-11-22 17:08:00 +08:00
DOCS_FILE_REPO = " docs "
2024-01-08 22:15:43 +08:00
PRDS_FILE_REPO = " docs/prd "
2023-11-22 20:40:42 +08:00
SYSTEM_DESIGN_FILE_REPO = " docs/system_design "
2024-01-08 22:15:43 +08:00
TASK_FILE_REPO = " docs/task "
2023-11-22 21:45:44 +08:00
COMPETITIVE_ANALYSIS_FILE_REPO = " resources/competitive_analysis "
DATA_API_DESIGN_FILE_REPO = " resources/data_api_design "
SEQ_FLOW_FILE_REPO = " resources/seq_flow "
SYSTEM_DESIGN_PDF_FILE_REPO = " resources/system_design "
PRD_PDF_FILE_REPO = " resources/prd "
2024-01-08 22:15:43 +08:00
TASK_PDF_FILE_REPO = " resources/api_spec_and_task "
2023-11-23 22:41:44 +08:00
TEST_CODES_FILE_REPO = " tests "
2023-11-24 19:56:27 +08:00
TEST_OUTPUTS_FILE_REPO = " test_outputs "
2024-01-08 22:15:43 +08:00
CODE_SUMMARIES_FILE_REPO = " docs/code_summary "
CODE_SUMMARIES_PDF_FILE_REPO = " resources/code_summary "
2023-12-14 22:59:41 +08:00
RESOURCES_FILE_REPO = " resources "
2024-01-08 22:15:43 +08:00
SD_OUTPUT_FILE_REPO = " resources/sd_output "
2023-12-21 12:09:39 +08:00
GRAPH_REPO_FILE_REPO = " docs/graph_repo "
2024-01-08 22:15:43 +08:00
CLASS_VIEW_FILE_REPO = " docs/class_view "
2023-11-28 18:16:50 +08:00
2023-11-20 11:24:46 +08:00
YAPI_URL = " http://yapi.deepwisdomai.com/ "
2023-12-14 15:06:04 +08:00
2023-08-28 19:26:21 +08:00
DEFAULT_LANGUAGE = " English "
2023-08-28 19:47:57 +08:00
DEFAULT_MAX_TOKENS = 1500
COMMAND_TOKENS = 500
BRAIN_MEMORY = " BRAIN_MEMORY "
2023-08-30 19:21:36 +08:00
SKILL_PATH = " SKILL_PATH "
SERPER_API_KEY = " SERPER_API_KEY "
2023-12-22 16:40:04 +08:00
DEFAULT_TOKEN_SIZE = 500
2023-09-02 14:30:45 +08:00
# format
BASE64_FORMAT = " base64 "
2023-09-04 13:21:29 +08:00
# REDIS
REDIS_KEY = " REDIS_KEY "
2023-12-23 19:48:01 +08:00
LLM_API_TIMEOUT = 300
2023-12-25 12:42:23 +08:00
# Message id
IGNORED_MESSAGE_ID = " 0 "
2024-01-02 18:42:59 +08:00
# Class Relationship
GENERALIZATION = " Generalize "
COMPOSITION = " Composite "
AGGREGATION = " Aggregate "
2024-01-22 21:55:54 +08:00
2024-01-24 20:16:04 +08:00
# For Android App Agent
2024-01-22 21:55:54 +08:00
ADB_EXEC_FAIL = " FAILED "
2024-01-24 20:16:04 +08:00
# For Mincraft Game Agent
MC_CKPT_DIR = METAGPT_ROOT / " data/mincraft/ckpt "
MC_LOG_DIR = METAGPT_ROOT / " logs "
MC_DEFAULT_WARMUP = {
" context " : 15 ,
" biome " : 10 ,
" time " : 15 ,
" nearby_blocks " : 0 ,
" other_blocks " : 10 ,
" nearby_entities " : 5 ,
" health " : 15 ,
" hunger " : 15 ,
" position " : 0 ,
" equipment " : 0 ,
" inventory " : 0 ,
" optional_inventory_items " : 7 ,
" chests " : 0 ,
" completed_tasks " : 0 ,
" failed_tasks " : 0 ,
}
MC_CURRICULUM_OB = [
" context " ,
" biome " ,
" time " ,
" nearby_blocks " ,
" other_blocks " ,
" nearby_entities " ,
" health " ,
" hunger " ,
" position " ,
" equipment " ,
" inventory " ,
" chests " ,
" completed_tasks " ,
" failed_tasks " ,
]
MC_CORE_INVENTORY_ITEMS = r " .*_log|.*_planks|stick|crafting_table|furnace "
2024-01-26 15:16:33 +08:00
r " |cobblestone|dirt|coal|.*_pickaxe|.*_sword|.*_axe " , # curriculum_agent: only show these items in inventory before optional_inventory_items reached in warm up