Creating Bot to Answer frequently ask questions and also able to do chitchat

Hi,

I am building a bot where i will use frequently ask questions as input, so when user ask any question, bot will answer from given dataset.

but then also I want it to able to make chitchat, but when user tries to make chitchat, still trying to answer from dataset.

I created below code for trying and tuning, but I don’t know if this is correct approach for it.

Because some times gemini starts with sentence “based on text you give”, but it should say this, it should use text file for information lookup.

import google.generativeai as genai
import pathlib
media = pathlib.Path(file).parents[1] / “geminibot”
model = genai.GenerativeModel(model_name=“gemini-1.5-flash-002”)
myfile = genai.upload_file(media / “faq.txt”)

def automated_conversation():
while True:
user_input = input("You: ")
print(“You Typed: {}”.format(user_input))
if user_input.lower() == “exit”:
print(“Conversation ended.”)
break
response = model.generate_content([user_input, myfile])
print(“AI:”, response.text)

automated_conversation()

Thanks a lot for your help in advance.