Repository: xorbitsai/inference

Issue:
自定义模型Launch后无法在控制台删除，命令行也无法删除
### Describe the bug
自定义模型Launch后无法在控制台删除，命令行也无法删除且报错

### To Reproduce
To help us to reproduce this bug, please provide information below:

1. Python 3.10.12
2. xinference, version 0.7.5
3.命令行执行xinference list命令信息如下：
root@ai-gpu:/opt/devlop# xinference list
UID              Type    Name             Format      Size (in billions)  Quantization
---------------  ------  ---------------  --------  --------------------  --------------
baichuan-2-chat  LLM     baichuan-2-chat  pytorch                     13  8-bit
UID                                             Type       Name                                         Dimensions
----------------------------------------------  ---------  -----------------------------------------  ------------
text2vec-large-chinese                          embedding  text2vec-large-chinese                             1024
bge-base-zh-v1.5                                embedding  bge-base-zh-v1.5                                    768
damo/nlp_corom_sentence-embedding_chinese-base  embedding  nlp_corom_sentence-embedding_chinese-base           768

4.命令行执行停止命令报错如下：
root@ai-gpu:/opt/devlop# xinference terminate --model-uid "damo/nlp_corom_sentence-embedding_chinese-base"
Traceback (most recent call last):
  File "/usr/local/bin/xinference", line 8, in <module>
    sys.exit(cli())
  File "/usr/lib/python3/dist-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/xinference/deploy/cmdline.py", line 631, in model_terminate
    client.terminate_model(model_uid=model_uid)
  File "/usr/local/lib/python3.10/dist-packages/xinference/client/restful/restful_client.py", line 771, in terminate_model
    raise RuntimeError(
RuntimeError: Failed to terminate model, detail: Not Found 


### Additional context
服务器日志没有任何异常


### 原因猜测
可能是我的uid中有/引起的，我的uid是`damo/nlp_corom_sentence-embedding_chinese-base  embedding`



Discussion:

Resolving patch:
diff --git a/xinference/model/utils.py b/xinference/model/utils.py
--- a/xinference/model/utils.py
+++ b/xinference/model/utils.py
@@ -153,8 +153,13 @@ def is_model_cached(model_spec: Any, name_to_revisions_mapping: Dict):
 
 
 def is_valid_model_name(model_name: str) -> bool:
-    model_name = model_name.strip()
-    return 0 < len(model_name) <= 100
+    import re
+
+    if len(model_name) == 0:
+        return False
+
+    # check if contains +/?%#&=\s
+    return re.match(r"^[^+\/?%#&=\s]*$", model_name) is not None
 
 
 def parse_uri(uri: str) -> Tuple[str, str]:


Test patch:
diff --git a/xinference/model/llm/tests/test_utils.py b/xinference/model/llm/tests/test_utils.py
--- a/xinference/model/llm/tests/test_utils.py
+++ b/xinference/model/llm/tests/test_utils.py
@@ -415,8 +415,9 @@ def test_is_valid_model_name():
     assert is_valid_model_name("foo_bar")
     assert is_valid_model_name("123")
     assert is_valid_model_name("foo@bar")
-    assert is_valid_model_name("foo bar")
     assert is_valid_model_name("_foo")
     assert is_valid_model_name("-foo")
+    assert not is_valid_model_name("foo bar")
+    assert not is_valid_model_name("foo/bar")
     assert not is_valid_model_name("   ")
     assert not is_valid_model_name("")