We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
FEAT: support  WizardMath v1.0
### Is your feature request related to a problem? Please describe
https://huggingface.co/WizardLM/WizardMath-13B-V1.0



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `xinference/model/llm/utils.py`
Content:
```
1 # Copyright 2022-2023 XProbe Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 from typing import Iterator, List
16 
17 from xinference.model.llm.llm_family import PromptStyleV1
18 
19 from ...types import (
20     ChatCompletion,
21     ChatCompletionChunk,
22     ChatCompletionMessage,
23     Completion,
24     CompletionChunk,
25 )
26 
27 
28 class ChatModelMixin:
29     @staticmethod
30     def get_prompt(
31         prompt: str,
32         chat_history: List[ChatCompletionMessage],
33         prompt_style: PromptStyleV1,
34     ) -> str:
35         """
36         Inspired by FastChat. Format chat history into a prompt according to the prompty style of
37         different models.
38         """
39         assert prompt_style.roles is not None
40         chat_history.append(
41             ChatCompletionMessage(role=prompt_style.roles[0], content=prompt)
42         )
43         chat_history.append(
44             ChatCompletionMessage(role=prompt_style.roles[1], content="")
45         )
46 
47         if prompt_style.style_name == "ADD_COLON_SINGLE":
48             ret = prompt_style.system_prompt + prompt_style.intra_message_sep
49             for message in chat_history:
50                 role = message["role"]
51                 content = message["content"]
52                 if content:
53                     ret += role + ": " + content + prompt_style.intra_message_sep
54                 else:
55                     ret += role + ":"
56             return ret
57         elif prompt_style.style_name == "ADD_COLON_TWO":
58             seps = [prompt_style.intra_message_sep, prompt_style.inter_message_sep]
59             ret = prompt_style.system_prompt + seps[0]
60             for i, message in enumerate(chat_history):
61                 role = message["role"]
62                 content = message["content"]
63                 if content:
64                     ret += role + ": " + content + seps[i % 2]
65                 else:
66                     ret += role + ":"
67             return ret
68         elif prompt_style.style_name == "NO_COLON_TWO":
69             seps = [prompt_style.intra_message_sep, prompt_style.inter_message_sep]
70             ret = prompt_style.system_prompt
71             for i, message in enumerate(chat_history):
72                 role = message["role"]
73                 content = message["content"]
74                 if content:
75                     ret += role + content + seps[i % 2]
76                 else:
77                     ret += role
78             return ret
79         elif prompt_style.style_name == "LLAMA2":
80             seps = [prompt_style.intra_message_sep, prompt_style.inter_message_sep]
81             ret = ""
82             for i, message in enumerate(chat_history):
83                 role = message["role"]
84                 content = message["content"]
85                 if content:
86                     if i == 0:
87                         ret += prompt_style.system_prompt + content
88                     else:
89                         ret += role + " " + content + seps[i % 2]
90                 else:
91                     ret += role
92             return ret
93         elif prompt_style.style_name == "FALCON":
94             ret = prompt_style.system_prompt
95             for message in chat_history:
96                 role = message["role"]
97                 content = message["content"]
98                 if content:
99                     ret += (
100                         role
101                         + ": "
102                         + content.replace("\r\n", "\n").replace("\n\n", "\n")
103                     )
104                     ret += "\n\n"
105                 else:
106                     ret += role + ":"
107             return ret
108         elif prompt_style.style_name == "CHATGLM":
109             round_add_n = 1 if prompt_style.intra_message_sep == "\n\n" else 0
110             if prompt_style.system_prompt:
111                 ret = prompt_style.system_prompt + prompt_style.intra_message_sep
112             else:
113                 ret = ""
114             for i, message in enumerate(chat_history):
115                 role = message["role"]
116                 content = message["content"]
117                 if i % 2 == 0:
118                     ret += f"[Round {i // 2 + round_add_n}]{prompt_style.intra_message_sep}"
119                 if content:
120                     ret += role + "：" + content + prompt_style.intra_message_sep
121                 else:
122                     ret += role + "："
123             return ret
124         elif prompt_style.style_name == "QWEN":
125             ret = f"<|im_start|>system\n{prompt_style.system_prompt}<|im_end|>"
126             for message in chat_history:
127                 role = message["role"]
128                 content = message["content"]
129 
130                 ret += prompt_style.intra_message_sep
131                 if content:
132                     ret += f"<|im_start|>{role}\n{content}<|im_end|>"
133                 else:
134                     ret += f"<|im_start|>{role}\n"
135             return ret
136         elif prompt_style.style_name == "CHATML":
137             ret = (
138                 ""
139                 if prompt_style.system_prompt == ""
140                 else prompt_style.system_prompt + prompt_style.intra_message_sep + "\n"
141             )
142             for message in chat_history:
143                 role = message["role"]
144                 content = message["content"]
145 
146                 if content:
147                     ret += role + "\n" + content + prompt_style.intra_message_sep + "\n"
148                 else:
149                     ret += role + "\n"
150             return ret
151         elif prompt_style.style_name == "INTERNLM":
152             seps = [prompt_style.intra_message_sep, prompt_style.inter_message_sep]
153             ret = ""
154             for i, message in enumerate(chat_history[:-2]):
155                 if i % 2 == 0:
156                     ret += "<s>"
157                 role = message["role"]
158                 content = message["content"]
159                 ret += role + ":" + content + seps[i % 2]
160             if len(ret) == 0:
161                 ret += "<s>"
162             ret += (
163                 chat_history[-2]["role"] + ":" + chat_history[-2]["content"] + seps[0]
164             )
165             ret += chat_history[-1]["role"] + ":"
166             return ret
167         else:
168             raise ValueError(f"Invalid prompt style: {prompt_style.style_name}")
169 
170     @staticmethod
171     def _convert_chat_completion_chunks_to_chat(
172         chunks: Iterator[CompletionChunk],
173     ) -> Iterator[ChatCompletionChunk]:
174         for i, chunk in enumerate(chunks):
175             if i == 0:
176                 yield {
177                     "id": "chat" + chunk["id"],
178                     "model": chunk["model"],
179                     "created": chunk["created"],
180                     "object": "chat.completion.chunk",
181                     "choices": [
182                         {
183                             "index": 0,
184                             "delta": {
185                                 "role": "assistant",
186                             },
187                             "finish_reason": None,
188                         }
189                     ],
190                 }
191             yield {
192                 "id": "chat" + chunk["id"],
193                 "model": chunk["model"],
194                 "created": chunk["created"],
195                 "object": "chat.completion.chunk",
196                 "choices": [
197                     {
198                         "index": 0,
199                         "delta": {
200                             "content": chunk["choices"][0]["text"],
201                         },
202                         "finish_reason": chunk["choices"][0]["finish_reason"],
203                     }
204                 ],
205             }
206 
207     @staticmethod
208     def _convert_text_completion_to_chat(completion: Completion) -> ChatCompletion:
209         return {
210             "id": "chat" + completion["id"],
211             "object": "chat.completion",
212             "created": completion["created"],
213             "model": completion["model"],
214             "choices": [
215                 {
216                     "index": 0,
217                     "message": {
218                         "role": "assistant",
219                         "content": completion["choices"][0]["text"],
220                     },
221                     "finish_reason": completion["choices"][0]["finish_reason"],
222                 }
223             ],
224             "usage": completion["usage"],
225         }
226 
227 
228 def is_valid_model_name(model_name: str) -> bool:
229     import re
230 
231     return re.match(r"^[A-Za-z0-9][A-Za-z0-9_\-]*$", model_name) is not None
232
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/xinference/model/llm/utils.py b/xinference/model/llm/utils.py
--- a/xinference/model/llm/utils.py
+++ b/xinference/model/llm/utils.py
@@ -164,6 +164,16 @@
             )
             ret += chat_history[-1]["role"] + ":"
             return ret
+        elif prompt_style.style_name == "ADD_COLON_SINGLE_COT":
+            ret = prompt_style.system_prompt + prompt_style.intra_message_sep
+            for message in chat_history:
+                role = message["role"]
+                content = message["content"]
+                if content:
+                    ret += role + ": " + content + prompt_style.intra_message_sep
+                else:
+                    ret += role + ": Let's think step by step."
+            return ret
         else:
             raise ValueError(f"Invalid prompt style: {prompt_style.style_name}")

{"golden_diff": "diff --git a/xinference/model/llm/utils.py b/xinference/model/llm/utils.py\n--- a/xinference/model/llm/utils.py\n+++ b/xinference/model/llm/utils.py\n@@ -164,6 +164,16 @@\n             )\n             ret += chat_history[-1][\"role\"] + \":\"\n             return ret\n+        elif prompt_style.style_name == \"ADD_COLON_SINGLE_COT\":\n+            ret = prompt_style.system_prompt + prompt_style.intra_message_sep\n+            for message in chat_history:\n+                role = message[\"role\"]\n+                content = message[\"content\"]\n+                if content:\n+                    ret += role + \": \" + content + prompt_style.intra_message_sep\n+                else:\n+                    ret += role + \": Let's think step by step.\"\n+            return ret\n         else:\n             raise ValueError(f\"Invalid prompt style: {prompt_style.style_name}\")\n", "issue": "FEAT: support  WizardMath v1.0\n### Is your feature request related to a problem? Please describe\r\nhttps://huggingface.co/WizardLM/WizardMath-13B-V1.0\r\n\r\n\n", "before_files": [{"content": "# Copyright 2022-2023 XProbe Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom typing import Iterator, List\n\nfrom xinference.model.llm.llm_family import PromptStyleV1\n\nfrom ...types import (\n    ChatCompletion,\n    ChatCompletionChunk,\n    ChatCompletionMessage,\n    Completion,\n    CompletionChunk,\n)\n\n\nclass ChatModelMixin:\n    @staticmethod\n    def get_prompt(\n        prompt: str,\n        chat_history: List[ChatCompletionMessage],\n        prompt_style: PromptStyleV1,\n    ) -> str:\n        \"\"\"\n        Inspired by FastChat. Format chat history into a prompt according to the prompty style of\n        different models.\n        \"\"\"\n        assert prompt_style.roles is not None\n        chat_history.append(\n            ChatCompletionMessage(role=prompt_style.roles[0], content=prompt)\n        )\n        chat_history.append(\n            ChatCompletionMessage(role=prompt_style.roles[1], content=\"\")\n        )\n\n        if prompt_style.style_name == \"ADD_COLON_SINGLE\":\n            ret = prompt_style.system_prompt + prompt_style.intra_message_sep\n            for message in chat_history:\n                role = message[\"role\"]\n                content = message[\"content\"]\n                if content:\n                    ret += role + \": \" + content + prompt_style.intra_message_sep\n                else:\n                    ret += role + \":\"\n            return ret\n        elif prompt_style.style_name == \"ADD_COLON_TWO\":\n            seps = [prompt_style.intra_message_sep, prompt_style.inter_message_sep]\n            ret = prompt_style.system_prompt + seps[0]\n            for i, message in enumerate(chat_history):\n                role = message[\"role\"]\n                content = message[\"content\"]\n                if content:\n                    ret += role + \": \" + content + seps[i % 2]\n                else:\n                    ret += role + \":\"\n            return ret\n        elif prompt_style.style_name == \"NO_COLON_TWO\":\n            seps = [prompt_style.intra_message_sep, prompt_style.inter_message_sep]\n            ret = prompt_style.system_prompt\n            for i, message in enumerate(chat_history):\n                role = message[\"role\"]\n                content = message[\"content\"]\n                if content:\n                    ret += role + content + seps[i % 2]\n                else:\n                    ret += role\n            return ret\n        elif prompt_style.style_name == \"LLAMA2\":\n            seps = [prompt_style.intra_message_sep, prompt_style.inter_message_sep]\n            ret = \"\"\n            for i, message in enumerate(chat_history):\n                role = message[\"role\"]\n                content = message[\"content\"]\n                if content:\n                    if i == 0:\n                        ret += prompt_style.system_prompt + content\n                    else:\n                        ret += role + \" \" + content + seps[i % 2]\n                else:\n                    ret += role\n            return ret\n        elif prompt_style.style_name == \"FALCON\":\n            ret = prompt_style.system_prompt\n            for message in chat_history:\n                role = message[\"role\"]\n                content = message[\"content\"]\n                if content:\n                    ret += (\n                        role\n                        + \": \"\n                        + content.replace(\"\\r\\n\", \"\\n\").replace(\"\\n\\n\", \"\\n\")\n                    )\n                    ret += \"\\n\\n\"\n                else:\n                    ret += role + \":\"\n            return ret\n        elif prompt_style.style_name == \"CHATGLM\":\n            round_add_n = 1 if prompt_style.intra_message_sep == \"\\n\\n\" else 0\n            if prompt_style.system_prompt:\n                ret = prompt_style.system_prompt + prompt_style.intra_message_sep\n            else:\n                ret = \"\"\n            for i, message in enumerate(chat_history):\n                role = message[\"role\"]\n                content = message[\"content\"]\n                if i % 2 == 0:\n                    ret += f\"[Round {i // 2 + round_add_n}]{prompt_style.intra_message_sep}\"\n                if content:\n                    ret += role + \"\uff1a\" + content + prompt_style.intra_message_sep\n                else:\n                    ret += role + \"\uff1a\"\n            return ret\n        elif prompt_style.style_name == \"QWEN\":\n            ret = f\"<|im_start|>system\\n{prompt_style.system_prompt}<|im_end|>\"\n            for message in chat_history:\n                role = message[\"role\"]\n                content = message[\"content\"]\n\n                ret += prompt_style.intra_message_sep\n                if content:\n                    ret += f\"<|im_start|>{role}\\n{content}<|im_end|>\"\n                else:\n                    ret += f\"<|im_start|>{role}\\n\"\n            return ret\n        elif prompt_style.style_name == \"CHATML\":\n            ret = (\n                \"\"\n                if prompt_style.system_prompt == \"\"\n                else prompt_style.system_prompt + prompt_style.intra_message_sep + \"\\n\"\n            )\n            for message in chat_history:\n                role = message[\"role\"]\n                content = message[\"content\"]\n\n                if content:\n                    ret += role + \"\\n\" + content + prompt_style.intra_message_sep + \"\\n\"\n                else:\n                    ret += role + \"\\n\"\n            return ret\n        elif prompt_style.style_name == \"INTERNLM\":\n            seps = [prompt_style.intra_message_sep, prompt_style.inter_message_sep]\n            ret = \"\"\n            for i, message in enumerate(chat_history[:-2]):\n                if i % 2 == 0:\n                    ret += \"<s>\"\n                role = message[\"role\"]\n                content = message[\"content\"]\n                ret += role + \":\" + content + seps[i % 2]\n            if len(ret) == 0:\n                ret += \"<s>\"\n            ret += (\n                chat_history[-2][\"role\"] + \":\" + chat_history[-2][\"content\"] + seps[0]\n            )\n            ret += chat_history[-1][\"role\"] + \":\"\n            return ret\n        else:\n            raise ValueError(f\"Invalid prompt style: {prompt_style.style_name}\")\n\n    @staticmethod\n    def _convert_chat_completion_chunks_to_chat(\n        chunks: Iterator[CompletionChunk],\n    ) -> Iterator[ChatCompletionChunk]:\n        for i, chunk in enumerate(chunks):\n            if i == 0:\n                yield {\n                    \"id\": \"chat\" + chunk[\"id\"],\n                    \"model\": chunk[\"model\"],\n                    \"created\": chunk[\"created\"],\n                    \"object\": \"chat.completion.chunk\",\n                    \"choices\": [\n                        {\n                            \"index\": 0,\n                            \"delta\": {\n                                \"role\": \"assistant\",\n                            },\n                            \"finish_reason\": None,\n                        }\n                    ],\n                }\n            yield {\n                \"id\": \"chat\" + chunk[\"id\"],\n                \"model\": chunk[\"model\"],\n                \"created\": chunk[\"created\"],\n                \"object\": \"chat.completion.chunk\",\n                \"choices\": [\n                    {\n                        \"index\": 0,\n                        \"delta\": {\n                            \"content\": chunk[\"choices\"][0][\"text\"],\n                        },\n                        \"finish_reason\": chunk[\"choices\"][0][\"finish_reason\"],\n                    }\n                ],\n            }\n\n    @staticmethod\n    def _convert_text_completion_to_chat(completion: Completion) -> ChatCompletion:\n        return {\n            \"id\": \"chat\" + completion[\"id\"],\n            \"object\": \"chat.completion\",\n            \"created\": completion[\"created\"],\n            \"model\": completion[\"model\"],\n            \"choices\": [\n                {\n                    \"index\": 0,\n                    \"message\": {\n                        \"role\": \"assistant\",\n                        \"content\": completion[\"choices\"][0][\"text\"],\n                    },\n                    \"finish_reason\": completion[\"choices\"][0][\"finish_reason\"],\n                }\n            ],\n            \"usage\": completion[\"usage\"],\n        }\n\n\ndef is_valid_model_name(model_name: str) -> bool:\n    import re\n\n    return re.match(r\"^[A-Za-z0-9][A-Za-z0-9_\\-]*$\", model_name) is not None\n", "path": "xinference/model/llm/utils.py"}], "after_files": [{"content": "# Copyright 2022-2023 XProbe Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom typing import Iterator, List\n\nfrom xinference.model.llm.llm_family import PromptStyleV1\n\nfrom ...types import (\n    ChatCompletion,\n    ChatCompletionChunk,\n    ChatCompletionMessage,\n    Completion,\n    CompletionChunk,\n)\n\n\nclass ChatModelMixin:\n    @staticmethod\n    def get_prompt(\n        prompt: str,\n        chat_history: List[ChatCompletionMessage],\n        prompt_style: PromptStyleV1,\n    ) -> str:\n        \"\"\"\n        Inspired by FastChat. Format chat history into a prompt according to the prompty style of\n        different models.\n        \"\"\"\n        assert prompt_style.roles is not None\n        chat_history.append(\n            ChatCompletionMessage(role=prompt_style.roles[0], content=prompt)\n        )\n        chat_history.append(\n            ChatCompletionMessage(role=prompt_style.roles[1], content=\"\")\n        )\n\n        if prompt_style.style_name == \"ADD_COLON_SINGLE\":\n            ret = prompt_style.system_prompt + prompt_style.intra_message_sep\n            for message in chat_history:\n                role = message[\"role\"]\n                content = message[\"content\"]\n                if content:\n                    ret += role + \": \" + content + prompt_style.intra_message_sep\n                else:\n                    ret += role + \":\"\n            return ret\n        elif prompt_style.style_name == \"ADD_COLON_TWO\":\n            seps = [prompt_style.intra_message_sep, prompt_style.inter_message_sep]\n            ret = prompt_style.system_prompt + seps[0]\n            for i, message in enumerate(chat_history):\n                role = message[\"role\"]\n                content = message[\"content\"]\n                if content:\n                    ret += role + \": \" + content + seps[i % 2]\n                else:\n                    ret += role + \":\"\n            return ret\n        elif prompt_style.style_name == \"NO_COLON_TWO\":\n            seps = [prompt_style.intra_message_sep, prompt_style.inter_message_sep]\n            ret = prompt_style.system_prompt\n            for i, message in enumerate(chat_history):\n                role = message[\"role\"]\n                content = message[\"content\"]\n                if content:\n                    ret += role + content + seps[i % 2]\n                else:\n                    ret += role\n            return ret\n        elif prompt_style.style_name == \"LLAMA2\":\n            seps = [prompt_style.intra_message_sep, prompt_style.inter_message_sep]\n            ret = \"\"\n            for i, message in enumerate(chat_history):\n                role = message[\"role\"]\n                content = message[\"content\"]\n                if content:\n                    if i == 0:\n                        ret += prompt_style.system_prompt + content\n                    else:\n                        ret += role + \" \" + content + seps[i % 2]\n                else:\n                    ret += role\n            return ret\n        elif prompt_style.style_name == \"FALCON\":\n            ret = prompt_style.system_prompt\n            for message in chat_history:\n                role = message[\"role\"]\n                content = message[\"content\"]\n                if content:\n                    ret += (\n                        role\n                        + \": \"\n                        + content.replace(\"\\r\\n\", \"\\n\").replace(\"\\n\\n\", \"\\n\")\n                    )\n                    ret += \"\\n\\n\"\n                else:\n                    ret += role + \":\"\n            return ret\n        elif prompt_style.style_name == \"CHATGLM\":\n            round_add_n = 1 if prompt_style.intra_message_sep == \"\\n\\n\" else 0\n            if prompt_style.system_prompt:\n                ret = prompt_style.system_prompt + prompt_style.intra_message_sep\n            else:\n                ret = \"\"\n            for i, message in enumerate(chat_history):\n                role = message[\"role\"]\n                content = message[\"content\"]\n                if i % 2 == 0:\n                    ret += f\"[Round {i // 2 + round_add_n}]{prompt_style.intra_message_sep}\"\n                if content:\n                    ret += role + \"\uff1a\" + content + prompt_style.intra_message_sep\n                else:\n                    ret += role + \"\uff1a\"\n            return ret\n        elif prompt_style.style_name == \"QWEN\":\n            ret = f\"<|im_start|>system\\n{prompt_style.system_prompt}<|im_end|>\"\n            for message in chat_history:\n                role = message[\"role\"]\n                content = message[\"content\"]\n\n                ret += prompt_style.intra_message_sep\n                if content:\n                    ret += f\"<|im_start|>{role}\\n{content}<|im_end|>\"\n                else:\n                    ret += f\"<|im_start|>{role}\\n\"\n            return ret\n        elif prompt_style.style_name == \"CHATML\":\n            ret = (\n                \"\"\n                if prompt_style.system_prompt == \"\"\n                else prompt_style.system_prompt + prompt_style.intra_message_sep + \"\\n\"\n            )\n            for message in chat_history:\n                role = message[\"role\"]\n                content = message[\"content\"]\n\n                if content:\n                    ret += role + \"\\n\" + content + prompt_style.intra_message_sep + \"\\n\"\n                else:\n                    ret += role + \"\\n\"\n            return ret\n        elif prompt_style.style_name == \"INTERNLM\":\n            seps = [prompt_style.intra_message_sep, prompt_style.inter_message_sep]\n            ret = \"\"\n            for i, message in enumerate(chat_history[:-2]):\n                if i % 2 == 0:\n                    ret += \"<s>\"\n                role = message[\"role\"]\n                content = message[\"content\"]\n                ret += role + \":\" + content + seps[i % 2]\n            if len(ret) == 0:\n                ret += \"<s>\"\n            ret += (\n                chat_history[-2][\"role\"] + \":\" + chat_history[-2][\"content\"] + seps[0]\n            )\n            ret += chat_history[-1][\"role\"] + \":\"\n            return ret\n        elif prompt_style.style_name == \"ADD_COLON_SINGLE_COT\":\n            ret = prompt_style.system_prompt + prompt_style.intra_message_sep\n            for message in chat_history:\n                role = message[\"role\"]\n                content = message[\"content\"]\n                if content:\n                    ret += role + \": \" + content + prompt_style.intra_message_sep\n                else:\n                    ret += role + \": Let's think step by step.\"\n            return ret\n        else:\n            raise ValueError(f\"Invalid prompt style: {prompt_style.style_name}\")\n\n    @staticmethod\n    def _convert_chat_completion_chunks_to_chat(\n        chunks: Iterator[CompletionChunk],\n    ) -> Iterator[ChatCompletionChunk]:\n        for i, chunk in enumerate(chunks):\n            if i == 0:\n                yield {\n                    \"id\": \"chat\" + chunk[\"id\"],\n                    \"model\": chunk[\"model\"],\n                    \"created\": chunk[\"created\"],\n                    \"object\": \"chat.completion.chunk\",\n                    \"choices\": [\n                        {\n                            \"index\": 0,\n                            \"delta\": {\n                                \"role\": \"assistant\",\n                            },\n                            \"finish_reason\": None,\n                        }\n                    ],\n                }\n            yield {\n                \"id\": \"chat\" + chunk[\"id\"],\n                \"model\": chunk[\"model\"],\n                \"created\": chunk[\"created\"],\n                \"object\": \"chat.completion.chunk\",\n                \"choices\": [\n                    {\n                        \"index\": 0,\n                        \"delta\": {\n                            \"content\": chunk[\"choices\"][0][\"text\"],\n                        },\n                        \"finish_reason\": chunk[\"choices\"][0][\"finish_reason\"],\n                    }\n                ],\n            }\n\n    @staticmethod\n    def _convert_text_completion_to_chat(completion: Completion) -> ChatCompletion:\n        return {\n            \"id\": \"chat\" + completion[\"id\"],\n            \"object\": \"chat.completion\",\n            \"created\": completion[\"created\"],\n            \"model\": completion[\"model\"],\n            \"choices\": [\n                {\n                    \"index\": 0,\n                    \"message\": {\n                        \"role\": \"assistant\",\n                        \"content\": completion[\"choices\"][0][\"text\"],\n                    },\n                    \"finish_reason\": completion[\"choices\"][0][\"finish_reason\"],\n                }\n            ],\n            \"usage\": completion[\"usage\"],\n        }\n\n\ndef is_valid_model_name(model_name: str) -> bool:\n    import re\n\n    return re.match(r\"^[A-Za-z0-9][A-Za-z0-9_\\-]*$\", model_name) is not None\n", "path": "xinference/model/llm/utils.py"}]}