MCPcopy Create free account
hub / github.com/nlweb-ai/NLWeb / compare_items

Method compare_items

AskAgent/python/methods/compare_items.py:117–153  ·  view source on GitHub ↗

Compare the two items and return the results.

(self, item1, item2, details_requested)

Source from the content-addressed store, hash-verified

115 return {"score": 0, "explanation": f"Error: {e}"}
116
117 async def compare_items(self, item1, item2, details_requested):
118 """Compare the two items and return the results."""
119 try:
120 if (len(details_requested) > 0):
121 prompt_str, ans_struc = find_prompt(self.handler.site, self.handler.item_type, "CompareItemDetailsPrompt")
122 else:
123 prompt_str, ans_struc = find_prompt(self.handler.site, self.handler.item_type, "CompareItemsPrompt")
124 if not prompt_str:
125 logger.error("CompareItemsPrompt or CompareItemDetailsPrompt not found")
126 return {"score": 0, "explanation": "Prompt not found"}
127 desc1 = trim_json(item1[1])
128 desc2 = trim_json(item2[1])
129 pr_dict = {"request.item1_description": desc1, "request.item2_description": desc2, "request.details_requested": details_requested}
130 prompt = fill_prompt(prompt_str, self.handler, pr_dict)
131 response = await ask_llm(prompt, ans_struc, level="high", query_params=self.handler.query_params)
132
133 if response :
134 message = {
135 "message_type": "compare_items",
136 "comparison" : response.get("comparison", ""),
137 "item1":
138 {"name" : item1[2],
139 "schema_object" : item1[1],
140 "url" : item1[0]
141 },
142 "item2" :
143 {"name" : item2[2],
144 "schema_object" : item2[1],
145 "url" : item2[0]
146 }
147 }
148 asyncio.create_task(self.handler.send_message(message))
149 return message
150
151 except Exception as e:
152 logger.error(f"Error evaluating item match: {e}")
153 return {"score": 0, "explanation": f"Error: {e}"}
154
155 async def _get_item_by_url(self, item_url, item_name):
156 """Get item using URL-based retrieval."""

Callers 1

doMethod · 0.95

Calls 7

find_promptFunction · 0.90
trim_jsonFunction · 0.90
fill_promptFunction · 0.90
ask_llmFunction · 0.90
getMethod · 0.80
errorMethod · 0.45
send_messageMethod · 0.45

Tested by

no test coverage detected