feat: phase 1 more clearly
Автор
aaronmwanjala

Коммитер
aaronmwanjala
год назад 
Файлов изменено: 1
+4
–59
5f4a589
src/shoppingassistantservice/shoppingassistantservice.py
+4
–59
@@ -46,78 +46,23 @@ | ||
@app.route("/", methods=['POST']) | ||
def talkToGemini(): | ||
print("Beginning RAG call") | ||
prompt = request.json['message'] | ||
prompt = unquote(prompt) | ||
llm = ChatGoogleGenerativeAI(model="gemini-pro-vision") | ||
#Decsription prompt: | ||
#Send in the image, ask for a description of the room, search for relevant products | ||
llm_vision = ChatGoogleGenerativeAI(model="gemini-pro-vision") | ||
llm = ChatGoogleGenerativeAI(model="gemini-pro") | ||
message = HumanMessage( | ||
content=[ | ||
{ | ||
"type": "text", | ||
"text": "You are a professional interior designer, give me a detailed decsription of the style of the room in this image", | ||
"text": prompt, | ||
}, | ||
{"type": "image_url", "image_url": request.json['image']}, | ||
] | ||
) | ||
response = llm_vision.invoke([message]) | ||
print("Description step:") | ||
print(response) | ||
description_response = response.content | ||
vector_search_prompt = f""" | ||
This is the user's request: {prompt} | ||
Find the most relevant items for that prompt, while matching style | ||
of the room described here: {description_response} | ||
""" | ||
print(vector_search_prompt) | ||
docs = vectorstore.similarity_search(vector_search_prompt) | ||
print(f"Vector search: {description_response}") | ||
print(f"Retrieved documents: {len(docs)}") | ||
relevant_docs = "" | ||
for doc in docs: | ||
doc_details = doc.to_json() | ||
print(f"Adding relevant document to prompt context: {doc_details}") | ||
relevant_docs += str(doc_details) + ", " | ||
print("Relevant docs:") | ||
print(relevant_docs) | ||
design_prompt = f""" | ||
You are an interior designer that works for Online Boutique. You are | ||
tasked with providing recommendations to a customer on what they | ||
should add to a given room from our catalog. | ||
This is the description of the room: {description_response} | ||
Here are a list of products that are relevant to it: {relevant_docs} | ||
Specifically, this is what the customer has asked for, see if you | ||
can accommodate it: {prompt} | ||
Start by repeating a brief description of the room's design to the | ||
customer, then provide your recommendations. | ||
Do your best to pick the most relevant item out of the list of | ||
products provided, but if none of them seem relevant, then say that | ||
instead of inventing a new product. | ||
At the end of the response, add a list of the IDs of the relevant | ||
products in the following format for the top 3 results: | ||
[<first product ID>], [<second product ID>], [<third product ID>] | ||
""" | ||
print("Final design prompt: ") | ||
print(design_prompt) | ||
design_response = llm.invoke( | ||
design_prompt | ||
) | ||
response = llm.invoke([message]) | ||
data = {} | ||
data['content'] = design_response.content | ||
data['content'] = response.content | ||
return data | ||
return app |
Cherry-pick
Команда cherry-pick позволяет выбрать отдельные коммиты из одной ветки и применить их к другой.