How can I add prompt for the index based chatbot? here is the index based chatbot
import openai
import os
from flask import session
from llama_index import StorageContext, load_index_from_storage
from llama_index.prompts.base import Prompt
from llama_index.prompts.prompt_type import PromptType
def answer_question(query, query_engine):
response = query_engine.query(query)
return response
def generate_response_kbase(message, session):
api_key = session.get('OPENAI_API_KEY')
if api_key is None:
raise ValueError("OpenAI API key not found in session.")
openai.api_key = api_key
os.environ["OPENAI_API_KEY"] = openai.api_key
# query kbase ---------------------------------------
index = load_index_from_storage(StorageContext.from_defaults(persist_dir="storage/knowledge_base/"))
query_engine = index.as_query_engine()
response = answer_question(message, query_engine)
assistant_message = response.response.replace('\n', '').replace('"', '')
return assistant_message