LLMプロンプト
検索結果が手元にあるので、LLM に送信するプロンプトを生成できるようになりました。プロンプトには、ユーザーが送信した元の質問、検索フェーズで取得された関連文章、および回答が含まれている文章から取得する必要があることを示す LLM への指示が含まれている必要があります。
プロンプトをレンダリングするために、アプリケーションは Flask のrender_template()関数を使用します。
qa_prompt = render_template('rag_prompt.txt', question=question, docs=docs)この呼び出しで参照されるテンプレート ファイルは、 api/templates/rag_prompt.txtにあります。
Use the following passages to answer the user's question.
Each passage has a NAME which is the title of the document.
When answering, give the source name of the passages you are answering from at the end.
Put them in a comma separated list, prefixed with SOURCES:.
Example:
Question: What is the meaning of life?
Response:
The meaning of life is 42.
SOURCES: Hitchhiker's Guide to the Galaxy
If you don't know the answer, just say that you don't know, don't try to make up an answer.
----
{% for doc in docs -%}
---
NAME: {{ doc.metadata.name }}
PASSAGE:
{{ doc.page_content }}
---
{% endfor -%}
----
Question: {{ question }}
Response:チャットボットの応答の品質への影響を確認したい場合は、このテンプレートに変更を加えることができます。ただし、取得した文章をレンダリングする for ループを必ず保持するようにしてください。