add qwen openapi

This commit is contained in:
waani 2024-04-19 16:05:55 +08:00
parent 3674875095
commit 2389c97fb4
2 changed files with 15 additions and 13 deletions

View File

@ -32,9 +32,9 @@ class LLM:
return llm return llm
def test_Qwen(self, question="如何应对压力?", model_path="Qwen/Qwen-1_8B-Chat"): def test_Qwen(self, question="如何应对压力?", model_path="Qwen/Qwen-1_8B-Chat", api_key=None, proxy_url=None):
llm = Qwen(self.mode, model_path) llm = Qwen(model_path=model_path, api_key=api_key, api_base=proxy_url)
answer = llm.generate(question) answer = llm.chat(question)
print(answer) print(answer)
def test_Gemini(self, question="如何应对压力?", model_path='gemini-pro', api_key=None, proxy_url=None): def test_Gemini(self, question="如何应对压力?", model_path='gemini-pro', api_key=None, proxy_url=None):
@ -43,10 +43,12 @@ class LLM:
print(answer) print(answer)
if __name__ == '__main__': if __name__ == '__main__':
# llm = LLM() llm = LLM()
# llm.test_Gemini(api_key='你的API Key', proxy_url=None) # llm.test_Gemini(api_key='你的API Key', proxy_url=None)
# llm = LLM().init_model('Gemini', model_path= 'gemini-pro',api_key='AIzaSyBWAWfT8zsyAZcRIXLS5Vzlw8KKCN9qsAg', proxy_url='http://172.31.71.58:7890') # llm = LLM().init_model('Gemini', model_path= 'gemini-pro',api_key='AIzaSyBWAWfT8zsyAZcRIXLS5Vzlw8KKCN9qsAg', proxy_url='http://172.31.71.58:7890')
# response = llm.chat("如何应对压力?") # response = llm.chat("如何应对压力?")
llm = LLM().init_model('VllmGPT', model_path= 'THUDM/chatglm3-6b') # llm = LLM().init_model('VllmGPT', model_path= 'THUDM/chatglm3-6b')
response = llm.chat("如何应对压力?") # response = llm.chat("如何应对压力?")
# print(response) # print(response)
llm.test_Qwen(api_key="none", proxy_url="http://10.1.1.113:18000/v1")

View File

@ -18,7 +18,7 @@ class Qwen:
self.local = True self.local = True
# api_base和api_key不为空时使用openapi的方式 # api_base和api_key不为空时使用openapi的方式
if api_key is not None and base_url is not None: if api_key is not None and api_base is not None:
openai.api_base = api_base openai.api_base = api_base
openai.api_key = api_key openai.api_key = api_key
self.local = False self.local = False