File size: 662 Bytes
f30715f
 
088c9cc
f30715f
fe31f10
 
cc8eed6
f30715f
f370b92
fe31f10
 
 
9fd3b68
fe31f10
 
eb224c5
 
9fd3b68
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from typing import Dict, List, Any
from transformers import pipeline

class EndpointHandler():
     def __init__(self, path="zemuwen/14B_lora_ze"):
        # 初始化方法,加载问答模型
        self.pipeline = pipeline("question-answering", model=path)

    def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
        # 确保输入数据包含 "question" 和 "context"
        question = data.get("question", "")
        context = data.get("context", "")
        
        # 使用问答模型生成响应
        results = self.pipeline(question=question, context=context)
        
        # 返回模型的响应
        return results