-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vllm langchain: Add Document Retriever Support (#687)
* vllm langchain: Add Document Retriever Support Include SearchedDoc in /v1/chat/completions endpoint to accept document data retreived from retriever service to parse into LLM for answer generation. Signed-off-by: Yeoh, Hoong Tee <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * vllm: Update README documentation Signed-off-by: Yeoh, Hoong Tee <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Yeoh, Hoong Tee <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
574fecf
commit 0f2c2b1
Showing
3 changed files
with
185 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import re | ||
|
||
|
||
class ChatTemplate: | ||
@staticmethod | ||
def generate_rag_prompt(question, documents): | ||
context_str = "\n".join(documents) | ||
if context_str and len(re.findall("[\u4E00-\u9FFF]", context_str)) / len(context_str) >= 0.3: | ||
# chinese context | ||
template = """ | ||
### 你将扮演一个乐于助人、尊重他人并诚实的助手,你的目标是帮助用户解答问题。有效地利用来自本地知识库的搜索结果。确保你的回答中只包含相关信息。如果你不确定问题的答案,请避免分享不准确的信息。 | ||
### 搜索结果:{context} | ||
### 问题:{question} | ||
### 回答: | ||
""" | ||
else: | ||
template = """ | ||
### You are a helpful, respectful and honest assistant to help the user with questions. \ | ||
Please refer to the search results obtained from the local knowledge base. \ | ||
But be careful to not incorporate the information that you think is not relevant to the question. \ | ||
If you don't know the answer to a question, please don't share false information. \n | ||
### Search results: {context} \n | ||
### Question: {question} \n | ||
### Answer: | ||
""" | ||
return template.format(context=context_str, question=question) |