From 6637e679a686dbfe992c88bf3afbe8a635d4c326 Mon Sep 17 00:00:00 2001 From: csunny Date: Tue, 28 Nov 2023 15:20:48 +0800 Subject: [PATCH 1/3] feat: unified proxyllm apisecret --- pilot/configs/config.py | 4 ++-- pilot/model/proxy/llms/wenxin.py | 37 +++----------------------------- 2 files changed, 5 insertions(+), 36 deletions(-) diff --git a/pilot/configs/config.py b/pilot/configs/config.py index f93cd7b83..25e1bac53 100644 --- a/pilot/configs/config.py +++ b/pilot/configs/config.py @@ -66,7 +66,7 @@ def __init__(self) -> None: # wenxin self.wenxin_proxy_api_key = os.getenv("WEN_XIN_API_KEY") - self.wenxin_proxy_api_secret = os.getenv("WEN_XIN_SECRET_KEY") + self.wenxin_proxy_api_secret = os.getenv("WEN_XIN_API_SECRET") self.wenxin_model_version = os.getenv("WEN_XIN_MODEL_VERSION") if self.wenxin_proxy_api_key and self.wenxin_proxy_api_secret: os.environ["wenxin_proxyllm_proxy_api_key"] = self.wenxin_proxy_api_key @@ -84,7 +84,7 @@ def __init__(self) -> None: os.environ["spark_proxyllm_proxy_api_key"] = self.spark_proxy_api_key os.environ["spark_proxyllm_proxy_api_secret"] = self.spark_proxy_api_secret os.environ["spark_proxyllm_proxyllm_backend"] = self.spark_api_version - os.environ["spark_proxyllm_proxy_app_id"] = self.spark_proxy_api_appid + os.environ["spark_proxyllm_proxy_api_app_id"] = self.spark_proxy_api_appid # baichuan proxy self.bc_proxy_api_key = os.getenv("BAICHUAN_PROXY_API_KEY") diff --git a/pilot/model/proxy/llms/wenxin.py b/pilot/model/proxy/llms/wenxin.py index cfd47fd18..4f4ee7606 100644 --- a/pilot/model/proxy/llms/wenxin.py +++ b/pilot/model/proxy/llms/wenxin.py @@ -75,9 +75,8 @@ def wenxin_generate_stream( if not model_version: yield f"Unsupport model version {model_name}" - keys: [] = model_params.proxy_api_key.split(";") - proxy_api_key = keys[0] - proxy_api_secret = keys[1] + proxy_api_key = model_params.proxy_api_key + proxy_api_secret = model_params.proxy_api_secret access_token = _build_access_token(proxy_api_key, proxy_api_secret) headers = {"Content-Type": "application/json", "Accept": "application/json"} @@ -88,37 +87,7 @@ def wenxin_generate_stream( yield "Failed to get access token. please set the correct api_key and secret key." messages: List[ModelMessage] = params["messages"] - # Add history conversation - # system = "" - # if len(messages) > 1 and messages[0].role == ModelMessageRoleType.SYSTEM: - # role_define = messages.pop(0) - # system = role_define.content - # else: - # message = messages.pop(0) - # if message.role == ModelMessageRoleType.HUMAN: - # history.append({"role": "user", "content": message.content}) - # for message in messages: - # if message.role == ModelMessageRoleType.SYSTEM: - # history.append({"role": "user", "content": message.content}) - # # elif message.role == ModelMessageRoleType.HUMAN: - # # history.append({"role": "user", "content": message.content}) - # elif message.role == ModelMessageRoleType.AI: - # history.append({"role": "assistant", "content": message.content}) - # else: - # pass - # - # # temp_his = history[::-1] - # temp_his = history - # last_user_input = None - # for m in temp_his: - # if m["role"] == "user": - # last_user_input = m - # break - # - # if last_user_input: - # history.remove(last_user_input) - # history.append(last_user_input) - # + history, systems = __convert_2_wenxin_messages(messages) system = "" if systems and len(systems) > 0: From b19795d453c2aa736037c829aef93e7ddf3b6837 Mon Sep 17 00:00:00 2001 From: csunny Date: Tue, 28 Nov 2023 15:51:37 +0800 Subject: [PATCH 2/3] pylint: exec black format codeStyle --- pilot/model/proxy/llms/wenxin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pilot/model/proxy/llms/wenxin.py b/pilot/model/proxy/llms/wenxin.py index 4f4ee7606..701b35ea0 100644 --- a/pilot/model/proxy/llms/wenxin.py +++ b/pilot/model/proxy/llms/wenxin.py @@ -87,7 +87,7 @@ def wenxin_generate_stream( yield "Failed to get access token. please set the correct api_key and secret key." messages: List[ModelMessage] = params["messages"] - + history, systems = __convert_2_wenxin_messages(messages) system = "" if systems and len(systems) > 0: From cf8831702f5a57283a3b635104b00c6011f9d542 Mon Sep 17 00:00:00 2001 From: csunny Date: Thu, 30 Nov 2023 14:27:08 +0800 Subject: [PATCH 3/3] fix(llmproxy): fix openai api error --- pilot/model/proxy/llms/chatgpt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pilot/model/proxy/llms/chatgpt.py b/pilot/model/proxy/llms/chatgpt.py index d0adaf606..c3605ec36 100644 --- a/pilot/model/proxy/llms/chatgpt.py +++ b/pilot/model/proxy/llms/chatgpt.py @@ -175,7 +175,7 @@ def chatgpt_generate_stream( # logger.info(str(r)) # Azure Openai reponse may have empty choices body in the first chunk # to avoid index out of range error - if not r.get("choices"): + if len(r.choices) == 0: continue if r.choices[0].delta.content is not None: content = r.choices[0].delta.content @@ -191,7 +191,7 @@ def chatgpt_generate_stream( text = "" for r in res: - if not r.get("choices"): + if len(r.choices) == 0: continue if r["choices"][0]["delta"].get("content") is not None: content = r["choices"][0]["delta"]["content"]