Skip to content

Commit

Permalink
Passing all address fields, faster model, icon metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabehamilton committed Nov 8, 2024
1 parent b0d06d1 commit 2d448a5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 35 deletions.
3 changes: 2 additions & 1 deletion shopper/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def process_products(self, products):
def run(self):
chat_history = self.nearai_agent_client.list_messages()
last_user_query = self.get_last_search_term(chat_history)
print(f"!!! last_user_query:", last_user_query)
self.nearai_agent_client.add_reply(f"Searching for your personalized results...")
if Agent.is_order(last_user_query):
result = self.process_order(last_user_query)
if result:
Expand Down Expand Up @@ -81,6 +81,7 @@ def run_shopping(self, last_search_term):
model=MODEL,
agent_role_name="assistant",
add_responses_to_messages=False)
self.nearai_agent_client.add_reply(f"Found results, building shopping page...")

# Format the LLM response
chat_message = llm_response.split("<")[0].replace("Shopping Assistant:", "").strip()
Expand Down
5 changes: 3 additions & 2 deletions shopper/agent/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
],
"details": {
"display_name": "NearShoppin",
"icon": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e5/Shopping-basket.svg/270px-Shopping-basket.svg.png",
"agent": {
"welcome": {
"title": "NearShoppin, your Personal Shopping assistant.",
Expand All @@ -18,10 +19,10 @@
"//initial_user_message": "init",
"defaults": {
"max_iterations": 1,
"model": "qwen2p5-72b-instruct",
"model": "llama-v3p2-3b-instruct",
"model_provider": "fireworks",
"model_temperature": 0.0,
"model_max_tokens": 20000
"model_max_tokens": 500
}
}
},
Expand Down
45 changes: 23 additions & 22 deletions shopper/agent/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@
<script>
const totalQuantity = 10; // todo pull from contract
const agent_order_id = "$agent_order_id";
var orderCompleted = false;
var placeOrderTimer;
let orderCompleted = false;
let placeOrderTimer;

setTimeout(function() {
if(agent_order_id && agent_order_id !== "" && !orderCompleted) {
Expand All @@ -169,6 +169,9 @@
preparedModal.style.display = 'flex';
completedModal.style.display = 'none';
}
else {
view();
}
}, 100)

placeOrderTimer = setTimeout(function() {
Expand Down Expand Up @@ -216,36 +219,36 @@
}
}, false);

function prepareOrder(form) {
console.log('Preparing order:', form);
function prepareOrder(id) {
console.log('Preparing order:', id);
let elements = document.getElementById("order-form-" + id).elements;
let formValues ={};
for(let i = 0 ; i < elements.length ; i++){
let item = elements.item(i);
formValues[item.name] = item.value;
}
// todo require name, address1, city, country, zip.

const productSearch = document.getElementById('product-search');
const placingOrder = document.getElementById('placing-order');
productSearch.style.display = 'none';
placingOrder.style.display = 'flex';
// todo need color, size, address

const colors = {
3: 'gold',
2: 'heather',
1: 'aqua'
}
formValues['color'] = colors[id];
delete formValues[""];

const callData = {
agent_id: "flatirons.near/shopper/0.1.0",
new_message: JSON.stringify({"order":
{
"size": "M",
"color": "gold",
"name": "Jane Smith",
"address1": "123 Main St",
"city": "Anytown",
"state": "CA",
"country": "US",
"zip": "90210"
}}),
new_message: JSON.stringify({"order": formValues}),
thread_id: "$thread_id",
max_iterations: 1
};
console.log('Sending order:', callData);

const message = {
action: "remote_agent_run",
Expand Down Expand Up @@ -311,8 +314,6 @@
document.getElementById(`order-${id}`).style.display = 'none';
}

view();

// testing states
// setTimeout(function() {
// const productSearch = document.getElementById('product-search');
Expand Down Expand Up @@ -356,8 +357,8 @@ <h1>Shopping with NEAR AI</h1>
<div class="modal_background ">
<div class="container">
<!-- <div class="emoji">&#23F3</div>-->
<h1>Preparing your Order</h1>
<p>Saving your order information</p>
<h1>Preparing the Order</h1>
<p>Saving order information</p>
<div class="order-details">
<!-- <p><strong>Size:</strong> </p>-->
</div>
Expand All @@ -370,7 +371,7 @@ <h1>Preparing your Order</h1>
<div class="container">
<!-- <div class="emoji">&#23F3</div>-->
<h1>Order Ready for Payment</h1>
<p>Requesting a signature from your wallet</p>
<p>This needs a signature from your wallet</p>
<div class="order-details">
<p><strong>Order ID:</strong> $agent_order_id</p>
<!-- <p><strong>Estimated Delivery:</strong> 3-5 business days</p>-->
Expand All @@ -384,7 +385,7 @@ <h1>Order Ready for Payment</h1>
<div class="container">
<!-- <div class="emoji">&#1F389</div>-->
<h1>Order Confirmed!</h1>
<p>Thank you for your transaction. Your order has been successfully placed!</p>
<p>I have successfully placed the order for you.</p>
<div class="order-details">
<p><strong>Order ID:</strong> $agent_order_id</p>
<!-- <p><strong>Estimated Delivery:</strong> 3-5 business days</p>-->
Expand Down
25 changes: 15 additions & 10 deletions shopper/agent/template_near_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,27 @@ <h2 style="font-size: 1.125rem; font-weight: bold; margin-bottom: 8px;">$title</
<img src='$image' style="max-width: 50%; max-height: 180px" alt="product image"/>
</div>
<br/><br/>
<form onsubmit="prepareOrder">
<form id="order-form-$id">
<label for="size">Size:</label><br/>
<select id="size" name="size" style="width: 92%;">
<option value="s">Small</option>
<option value="m">Medium</option>
<option value="l">Large</option>
<option value="xl">X-Large</option>
<option value="2xl">2X-Large</option>
<option value="3xl">3X-Large</option>
<option value="4xl">4X-Large</option>
<option value="S">Small</option>
<option value="M">Medium</option>
<option value="L">Large</option>
<option value="XL">X-Large</option>
<option value="2XL">2X-Large</option>
<option value="3XL">3X-Large</option>
<option value="4XL">4X-Large</option>
</select><br/><br/>
<label for="name">Name:</label><br/>
<input type="text" id="name" name="name" placeholder="Enter full name for shipping" style="width: 90%;"><br/><br/>
<label for="address">Shipping Address:</label><br/>
<textarea id="address" name="address" rows="6" placeholder="Enter full shipping address" style="width: 90%;"></textarea>
<div>
<input type="text" id="address" name="address1" placeholder="Street Address" style="width: 90%;"></input>
<input type="text" id="address2" name="address2" placeholder="Address2" style="width: 90%;"></input>
<input type="text" id="city" name="city" placeholder="City" style="width: 90%;"></input>
<input type="text" id="state" name="state" placeholder="State" style="width: 90%;"></input>
<input type="text" id="zip" name="zip" placeholder="Zip Code" style="width: 90%;"></input>
<input type="text" id="country" name="country" placeholder="Country" style="width: 90%;"></input>
<div>
<div style="float: left">
<button style="
display: inline-block;
Expand Down

0 comments on commit 2d448a5

Please sign in to comment.