in infrastructure/movie-search-app/movie_search.py [0:0]
def send_prompt(e: me.ClickEvent):
state = me.state(State)
if not state.conversations:
for model in state.models:
state.conversations.append(Conversation(model=model, messages=[]))
input = state.input
state.input = ""
yield
for conversation in state.conversations:
model = conversation.model
messages = conversation.messages
history = messages[:]
messages.append(ChatMessage(role="user", content=input))
messages.append(ChatMessage(role="model", in_progress=True))
yield
if model == Models.GEMINI_1_5_FLASH.value:
while True:
intent_str = gemini_model.classify_intent(input)
print(intent_str)
logging.info(f"MOVIES LIST: {intent_str}")
try:
json_intent = json.loads(intent_str)
except json.JSONDecodeError as e:
print(f"Error decoding JSON: {e}")
continue
break
if json_intent["shouldRecommendMovie"] is True:
search_embedding = gemini_model.generate_embedding(json_intent["summary"])
movies_list = get_movies(db, str(search_embedding["embedding"]))
logging.info(f"MOVIES LIST: {movies_list}")
print(movies_list)
persona="You are friendly assistance helping to find a movie or show based on the client's request"
safeguards="You should give information about the movie or show, year, main actors and any supplemental information. Do not invent any new movies, names and use for the answer the list of shows defined in the context"
context="""