mirror of
https://github.com/katanemo/plano.git
synced 2026-06-11 15:05:14 +02:00
Cotran/hallucination integration (#115)
* fix fc integration * fix integration * remove file * Update arch_fc.py * create model server hallucination detection class
This commit is contained in:
parent
dc57f119a0
commit
7d38ef9719
2 changed files with 35 additions and 1 deletions
|
|
@ -190,6 +190,40 @@ async def zeroshot(req: ZeroShotRequest, res: Response):
|
|||
"model": req.model,
|
||||
}
|
||||
|
||||
|
||||
class HallucinationRequest(BaseModel):
|
||||
prompt: str
|
||||
parameters: dict
|
||||
model: str
|
||||
|
||||
|
||||
@app.post("/hallucination")
|
||||
async def hallucination(req: HallucinationRequest, res: Response):
|
||||
"""
|
||||
Hallucination API, take input as text and return the prediction of hallucination for each parameter
|
||||
parameters: dictionary of parameters and values
|
||||
example {"name": "John", "age": "25"}
|
||||
prompt: input prompt from the user
|
||||
"""
|
||||
if req.model not in zero_shot_models:
|
||||
raise HTTPException(status_code=400, detail="unknown model: " + req.model)
|
||||
|
||||
classifier = zero_shot_models[req.model]
|
||||
candidate_labels = [f"{k} is {v}" for k, v in req.parameters.items()]
|
||||
hypothesis_template = "{}"
|
||||
result = classifier(
|
||||
req.prompt, candidate_labels=candidate_labels, hypothesis_template=hypothesis_template, multi_label=True
|
||||
)
|
||||
result_score = result['scores']
|
||||
result_params = {k[0]: s for k, s in zip(req.parameters.items(), result_score)}
|
||||
|
||||
return {
|
||||
"params_scores": result_params,
|
||||
"raw_result": result,
|
||||
"model": req.model,
|
||||
}
|
||||
|
||||
|
||||
@app.post("/v1/chat/completions")
|
||||
async def chat_completion(req: ChatMessage, res: Response):
|
||||
result = await arch_fc_chat_completion(req, res)
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@ params:
|
|||
temperature: 0.01
|
||||
top_p : 0.5
|
||||
top_k: 50
|
||||
max_tokens: 512
|
||||
max_tokens: 2024
|
||||
stop_token_ids: [151645, 151643]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue