-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/Moemu/Muice-Chatbot
- Loading branch information
Showing
10 changed files
with
250 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import requests as r | ||
import json | ||
|
||
class llm(): | ||
''' | ||
|
||
class llm: | ||
""" | ||
使用已经存在的API, 这个API应该接受prompt和history两个参数, 返回response | ||
''' | ||
def __init__(self,url:str,*args,**kwargs): | ||
""" | ||
|
||
def __init__(self, url: str, *args, **kwargs): | ||
self.url = url | ||
|
||
def ask(self,user_text:str, history:list,): | ||
response = r.post(self.url,json={"prompt": user_text, "history": history}) | ||
def ask(self, user_text: str, history: list, ): | ||
response = r.post(self.url, json={"prompt": user_text, "history": history}) | ||
response = json.loads(response.text) | ||
return response['response'] | ||
return response['response'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
from llmtuner.chat import ChatModel | ||
|
||
class llm(): | ||
''' | ||
|
||
class llm: | ||
""" | ||
使用LLaMA-Factory方案加载, 适合通过其他微调方案微调的模型加载 | ||
''' | ||
def __init__(self, model_name_or_path:str, adapter_name_or_path:str): | ||
""" | ||
|
||
def __init__(self, model_name_or_path: str, adapter_name_or_path: str): | ||
self.model = ChatModel(dict( | ||
model_name_or_path = model_name_or_path, | ||
adapter_name_or_path = adapter_name_or_path, | ||
template="qwen" | ||
model_name_or_path=model_name_or_path, | ||
adapter_name_or_path=adapter_name_or_path, | ||
template="qwen" | ||
)) | ||
def ask(self,user_text:str, history:list,): | ||
|
||
def ask(self, user_text: str, history: list, ): | ||
messages = [] | ||
if history != []: | ||
if history: | ||
for chat in history: | ||
messages.append({"role": "user", "content":chat[0]}) | ||
messages.append({"role": "assistant", "content":chat[1]}) | ||
messages.append({"role": "user", "content": chat[0]}) | ||
messages.append({"role": "assistant", "content": chat[1]}) | ||
messages.append({"role": "user", "content": user_text}) | ||
response = self.model.chat(messages) | ||
return response[0].response_text | ||
return response[0].response_text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.