52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
from abc import ABC
|
|
import requests
|
|
from typing import Optional, List
|
|
from langchain.llms.base import LLM
|
|
|
|
from models.loader import LoaderCheckPoint
|
|
from models.base import (BaseAnswer,
|
|
AnswerResult)
|
|
|
|
|
|
class FastChatLLM(BaseAnswer, LLM, ABC):
|
|
max_token: int = 10000
|
|
temperature: float = 0.01
|
|
top_p = 0.9
|
|
checkPoint: LoaderCheckPoint = None
|
|
# history = []
|
|
history_len: int = 10
|
|
|
|
def __init__(self, checkPoint: LoaderCheckPoint = None):
|
|
super().__init__()
|
|
self.checkPoint = checkPoint
|
|
|
|
@property
|
|
def _llm_type(self) -> str:
|
|
return "FastChat"
|
|
|
|
@property
|
|
def _check_point(self) -> LoaderCheckPoint:
|
|
return self.checkPoint
|
|
|
|
@property
|
|
def _history_len(self) -> int:
|
|
return self.history_len
|
|
|
|
def set_history_len(self, history_len: int = 10) -> None:
|
|
self.history_len = history_len
|
|
|
|
def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:
|
|
pass
|
|
|
|
def generatorAnswer(self, prompt: str,
|
|
history: List[List[str]] = [],
|
|
streaming: bool = False):
|
|
|
|
response = "fastchat 响应结果"
|
|
history += [[prompt, response]]
|
|
answer_result = AnswerResult()
|
|
answer_result.history = history
|
|
answer_result.llm_output = {"answer": response}
|
|
|
|
yield answer_result
|