From 6d4f10145b6ff59d8d46f0446cc65141bd561166 Mon Sep 17 00:00:00 2001 From: XingWu_UCAS <1160386409@qq.com> Date: Fri, 27 Dec 2024 02:33:19 +0800 Subject: [PATCH 1/2] add gemini api support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 参考 https://developers.googleblog.com/zh-hans/gemini-is-now-accessible-from-the-openai-library/ --- server/llm_utils.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/llm_utils.py b/server/llm_utils.py index 8f94692..5f9be8f 100644 --- a/server/llm_utils.py +++ b/server/llm_utils.py @@ -5,9 +5,12 @@ from openai import OpenAI -model_name = "qwen2.5-72b-instruct" # qwen-plus, 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models -url = "https://dashscope.aliyuncs.com/compatible-mode/v1" -api_key = "" # 阿里云 API Key +model_name = "gemini-1.5-flash" # gemini model; 更多参考:https://ai.google.dev/gemini-api/docs/models/gemini-v2?hl=zh-cn +api_key = "" # Gemini API Key +url = "https://generativelanguage.googleapis.com/v1beta/" +# model_name = "qwen2.5-72b-instruct" # qwen-plus, 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models +# url = "https://dashscope.aliyuncs.com/compatible-mode/v1" +# api_key = "" # 阿里云 API Key class LLMClient(object): @@ -53,4 +56,4 @@ def walk_to_random_item( if __name__ == "__main__": res = LLMClient.get_response_by_api("你好") - print(res) \ No newline at end of file + print(res) From 5184baa2d9dbcb192bae696354122c23c4a8902a Mon Sep 17 00:00:00 2001 From: XingWu_UCAS <1160386409@qq.com> Date: Fri, 27 Dec 2024 02:37:20 +0800 Subject: [PATCH 2/2] update sys prompt for gemini --- server/llm_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/llm_utils.py b/server/llm_utils.py index 5f9be8f..d2cbaf6 100644 --- a/server/llm_utils.py +++ b/server/llm_utils.py @@ -20,7 +20,7 @@ def get_response_by_api( prompt: str, ) -> str: messages = [ - {"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."}, + {"role": "system", "content": "You are Gemini, created by Google. You are a helpful assistant."}, {"role": "user", "content": prompt} ] client = OpenAI(