初始化项目,由ModelHub XC社区提供模型
Model: thirdExec/Qwen2.5-1.5B-Instruct-ThaiFakeNews-bnb-4bit Source: Original Platform
This commit is contained in:
27
handler.py
Normal file
27
handler.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from typing import Dict,List,Any
|
||||
from transformers import pipeline
|
||||
|
||||
class EndpointHandler:
|
||||
def __init__(self, path:str=""):
|
||||
self.model = pipeline('text-generation',model=path)
|
||||
self.PROMPT_TEMPLATE = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
||||
|
||||
### Instruction:
|
||||
คุณเป็น AI ผู้เชี่ยวชาญด้านการตรวจสอบข่าวภาษาไทย กรุณาวิเคราะห์หัวข้อข่าวต่อไปนี้และตอบว่าเป็น "ข่าวจริง" หรือ "ข่าวปลอม" เท่านั้น
|
||||
|
||||
### Input:
|
||||
{}
|
||||
|
||||
### Response:
|
||||
"""
|
||||
def __call__(self, data:Dict[str,Any]):
|
||||
|
||||
inputs = data.pop("inputs",data)
|
||||
|
||||
prompt = self.PROMPT_TEMPLATE.format(inputs)
|
||||
|
||||
prediction = self.model(prompt)
|
||||
prediction = prediction[0]
|
||||
return prediction
|
||||
|
||||
|
||||
Reference in New Issue
Block a user