MCPcopy Create free account
hub / github.com/modelscope/ms-agent / Programmer

Class Programmer

projects/code_genesis/workflow/coding.py:56–523  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54
55
56class Programmer(LLMAgent):
57
58 def __init__(self,
59 config: DictConfig = DictConfig({}),
60 tag: str = DEFAULT_TAG,
61 trust_remote_code: bool = False,
62 code_file: str = None,
63 **kwargs):
64 # Validate and adjust config before passing to parent
65 config = self._validate_config(config)
66 super().__init__(config, tag, trust_remote_code, **kwargs)
67 self.code_file = code_file
68 index_dir: str = getattr(config, 'index_cache_dir', DEFAULT_INDEX_DIR)
69 self.pre_import_check = getattr(config, 'pre_import_check', True)
70 self.post_import_check = getattr(config, 'post_import_check', True)
71 self.lsp_check = getattr(config, 'lsp_check', True)
72 self.index_dir = os.path.join(self.output_dir, index_dir)
73 self.lock_dir = os.path.join(self.output_dir, DEFAULT_LOCK_DIR)
74 # self.code_condenser = CodeCondenser(config)
75 self.code_files = []
76 self.shared_lsp_context = kwargs.get('shared_lsp_context', {})
77 self.unchecked_files = {}
78 self.unchecked_issues = {}
79 self.stop_words = [stop_words, []]
80 self.find_all_files()
81 self.error_counter = 0
82
83 def _validate_config(self, config: DictConfig) -> DictConfig:
84 """Validate config and disable edit_file if credentials are missing."""
85 from omegaconf import OmegaConf
86
87 # Make config mutable for modifications
88 config = OmegaConf.to_container(config, resolve=True)
89
90 # Check edit_file_config.api_key
91 edit_file_api_key = None
92 try:
93 edit_file_api_key = config.get('tools', {}).get(
94 'file_system', {}).get('edit_file_config', {}).get('api_key')
95 except Exception:
96 pass
97
98 if not edit_file_api_key:
99 # Remove edit_file from include list
100 try:
101 include_list = config.get('tools',
102 {}).get('file_system',
103 {}).get('include', [])
104 if include_list and 'edit_file' in include_list:
105 include_list.remove('edit_file')
106 logger.warning(
107 '[coding] edit_file_config.api_key not set, removing edit_file from tools'
108 )
109 except Exception:
110 pass
111 else:
112 logger.info('[coding] edit_file_config.api_key is configured')
113

Callers 1

write_codeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected