Skip to content

Commit 6acdf41

Browse files
committed
fix bugs in webui
2 parents 4d4ebc4 + 42a7d01 commit 6acdf41

File tree

24 files changed

+1733
-389
lines changed

24 files changed

+1733
-389
lines changed

MANIFEST.in

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
recursive-include ms_agent/tools/code_interpreter *.ttf
2-
recursive-include ms_agent/utils *.tiktoken
3-
recursive-include ms_agent/utils/nltk *.zip
4-
recursive-include ms_agent/ *.yaml
1+
include README.md
2+
include LICENSE
3+
include requirements.txt
4+
recursive-include requirements *.txt
5+
6+
# Include projects
7+
recursive-include projects *
8+
9+
# Include webui backend
510
recursive-include webui/backend *.py
11+
12+
# Include webui frontend dist (will be built during setup)
613
recursive-include webui/frontend/dist *
14+
15+
# Exclude development files
16+
global-exclude *.pyc
17+
global-exclude __pycache__
18+
global-exclude .DS_Store
19+
global-exclude *.so

ms_agent/cli/run.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,44 @@
22
import argparse
33
import asyncio
44
import os
5+
from importlib import resources as importlib_resources
56

67
from ms_agent.config import Config
7-
from ms_agent.utils import strtobool
8+
from ms_agent.utils import get_logger, strtobool
89
from ms_agent.utils.constants import AGENT_CONFIG_FILE, MS_AGENT_ASCII
910

1011
from .base import CLICommand
1112

13+
logger = get_logger()
14+
1215

1316
def subparser_func(args):
1417
""" Function which will be called for a specific sub parser.
1518
"""
1619
return RunCMD(args)
1720

1821

22+
def list_builtin_projects():
23+
try:
24+
root = importlib_resources.files('ms_agent').joinpath('projects')
25+
if not root.exists():
26+
return []
27+
return sorted([p.name for p in root.iterdir() if p.is_dir()])
28+
except Exception as e:
29+
# Fallback: don't let help crash just because a resource is unavailable.
30+
logger.warning(f'Could not list built-in projects: {e}')
31+
return []
32+
33+
34+
def project_help_text():
35+
projects = list_builtin_projects()
36+
if projects:
37+
return (
38+
'Built-in bundled project name under package ms_agent/projects. '
39+
f'Available: {", ".join(projects)}')
40+
return 'Built-in bundled project name under package ms_agent/projects.'
41+
42+
1943
class RunCMD(CLICommand):
2044
name = 'run'
2145

@@ -25,6 +49,8 @@ def __init__(self, args):
2549
@staticmethod
2650
def define_args(parsers: argparse.ArgumentParser):
2751
"""Define args for run command."""
52+
projects = list_builtin_projects()
53+
2854
parser: argparse.ArgumentParser = parsers.add_parser(RunCMD.name)
2955
parser.add_argument(
3056
'--query',
@@ -39,6 +65,14 @@ def define_args(parsers: argparse.ArgumentParser):
3965
type=str,
4066
default=None,
4167
help='The directory or the repo id of the config file')
68+
parser.add_argument(
69+
'--project',
70+
required=False,
71+
type=str,
72+
default=None,
73+
choices=projects,
74+
help=project_help_text(),
75+
)
4276
parser.add_argument(
4377
'--trust_remote_code',
4478
required=False,
@@ -89,6 +123,33 @@ def define_args(parsers: argparse.ArgumentParser):
89123
parser.set_defaults(func=subparser_func)
90124

91125
def execute(self):
126+
if getattr(self.args, 'project', None):
127+
if self.args.config:
128+
raise ValueError(
129+
'Please specify only one of --config or --project')
130+
131+
project = self.args.project
132+
project_trav = importlib_resources.files('ms_agent').joinpath(
133+
'projects', project)
134+
135+
if not project_trav.exists():
136+
projects_root = importlib_resources.files('ms_agent').joinpath(
137+
'projects')
138+
available = []
139+
if projects_root.exists():
140+
available = [
141+
p.name for p in projects_root.iterdir() if p.is_dir()
142+
]
143+
raise ValueError(
144+
f'Unknown project: {project}. Available: {available}')
145+
146+
# as_file ensures we get a real filesystem path even if installed as zip
147+
with importlib_resources.as_file(project_trav) as project_dir:
148+
self.args.config = str(project_dir)
149+
return self._execute_with_config()
150+
return self._execute_with_config()
151+
152+
def _execute_with_config(self):
92153
if not self.args.config:
93154
current_dir = os.getcwd()
94155
if os.path.exists(os.path.join(current_dir, AGENT_CONFIG_FILE)):

ms_agent/cli/ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def execute(self):
5959

6060
if not webui_dir.exists():
6161
import ms_agent
62-
ms_agent_path = Path(ms_agent.__file__).parent.parent
62+
ms_agent_path = Path(ms_agent.__file__).parent
6363
webui_dir = ms_agent_path / 'webui'
6464

6565
if not webui_dir.exists():

ms_agent/config/config.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,23 @@ def traverse_config(_config: Union[DictConfig, ListConfig, Any],
201201
_config[idx] = extra[value[1:-1]]
202202

203203
traverse_config(config)
204+
205+
for key, value in extra.items():
206+
if '.' in key and not key.startswith('tools.'):
207+
parts = key.split('.')
208+
current = config
209+
# Navigate/create nested structure
210+
for i, part in enumerate(parts[:-1]):
211+
if not hasattr(current,
212+
part) or getattr(current, part) is None:
213+
setattr(current, part, DictConfig({}))
214+
current = getattr(current, part)
215+
final_key = parts[-1]
216+
if not hasattr(current, final_key) or getattr(
217+
current, final_key) is None:
218+
logger.info(f'Adding new config key: {key}')
219+
setattr(current, final_key, value)
220+
204221
return None
205222

206223
@staticmethod

ms_agent/llm/openai_llm.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ def __init__(
4242
self.model: str = config.llm.model
4343
self.max_continue_runs = getattr(config.llm, 'max_continue_runs',
4444
None) or MAX_CONTINUE_RUNS
45-
base_url = base_url or config.llm.openai_base_url or get_service_config(
46-
'openai').base_url
47-
api_key = api_key or config.llm.openai_api_key
45+
base_url = base_url or getattr(
46+
config.llm, 'openai_base_url',
47+
None) or get_service_config('openai').base_url
48+
api_key = api_key or getattr(config.llm, 'openai_api_key', None)
4849

4950
self.client = openai.OpenAI(
5051
api_key=api_key,

0 commit comments

Comments
 (0)