Added LocalAI support for rerank models (#3446)

### What problem does this PR solve?

Hi there!
LocalAI added support of rerank models
https://localai.io/features/reranker/

I've implemented LocalAIRerank class (typically copied it from
OpenAI_APIRerank class).
Also, LocalAI model response with 500 error code if len of "documents"
is less than 2 in similarity check.
So I've added the second "document" on RERANK model connection check in
`api/apps/llm_app.py`.

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
shizzgar
2024-11-18 07:05:52 +03:00
committed by GitHub
parent 70cd5c1599
commit 4b3eeaa6ef
3 changed files with 39 additions and 3 deletions

View File

@ -238,7 +238,7 @@ def add_llm():
base_url=llm["api_base"]
)
try:
arr, tc = mdl.similarity("Hello~ Ragflower!", ["Hi, there!"])
arr, tc = mdl.similarity("Hello~ Ragflower!", ["Hi, there!", "Ohh, my friend!"])
if len(arr) == 0 or tc == 0:
raise Exception("Not known.")
except Exception as e: