fix some problem for qwen
This commit is contained in:
parent
fafa862ba1
commit
54fcbb8cc7
|
@ -26,7 +26,7 @@ class LLM:
|
||||||
elif model_name == 'ChatGPT':
|
elif model_name == 'ChatGPT':
|
||||||
llm = ChatGPT(model_path, api_key=api_key)
|
llm = ChatGPT(model_path, api_key=api_key)
|
||||||
elif model_name == 'Qwen':
|
elif model_name == 'Qwen':
|
||||||
llm = Qwen(self.mode, model_path)
|
llm = Qwen(model_path)
|
||||||
elif model_name == 'VllmGPT':
|
elif model_name == 'VllmGPT':
|
||||||
llm = VllmGPT()
|
llm = VllmGPT()
|
||||||
return llm
|
return llm
|
||||||
|
|
|
@ -8,6 +8,7 @@ class Qwen:
|
||||||
def __init__(self, model_path="Qwen/Qwen-1_8B-Chat") -> None:
|
def __init__(self, model_path="Qwen/Qwen-1_8B-Chat") -> None:
|
||||||
'''暂时不写api版本,与Linly-api相类似,感兴趣可以实现一下'''
|
'''暂时不写api版本,与Linly-api相类似,感兴趣可以实现一下'''
|
||||||
self.model, self.tokenizer = self.init_model(model_path)
|
self.model, self.tokenizer = self.init_model(model_path)
|
||||||
|
self.data = {}
|
||||||
|
|
||||||
def init_model(self, path="Qwen/Qwen-1_8B-Chat"):
|
def init_model(self, path="Qwen/Qwen-1_8B-Chat"):
|
||||||
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-1_8B-Chat",
|
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-1_8B-Chat",
|
||||||
|
@ -19,7 +20,7 @@ class Qwen:
|
||||||
|
|
||||||
def chat(self, question):
|
def chat(self, question):
|
||||||
|
|
||||||
self.data["question"] = f"{self.prompt} ### Instruction:{question} ### Response:"
|
self.data["question"] = f"{question} ### Instruction:{question} ### Response:"
|
||||||
try:
|
try:
|
||||||
response, history = self.model.chat(self.tokenizer, self.data["question"], history=None)
|
response, history = self.model.chat(self.tokenizer, self.data["question"], history=None)
|
||||||
print(history)
|
print(history)
|
||||||
|
@ -30,7 +31,7 @@ class Qwen:
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
llm = Qwen(model_path="Qwen/Qwen-1_8B-Chat")
|
llm = Qwen(model_path="Qwen/Qwen-1_8B-Chat")
|
||||||
answer = llm.generate("如何应对压力?")
|
answer = llm.chat(question="如何应对压力?")
|
||||||
print(answer)
|
print(answer)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue