first commit

This commit is contained in:
2025-03-02 20:36:57 -03:00
parent e4b49ab52d
commit 6602baa487

View File

@@ -7,8 +7,8 @@ from langchain_community.chat_models.oci_generative_ai import ChatOCIGenAI
import requests
from requests.auth import HTTPBasicAuth
user_name = ""
password = ""
user_name = "#######################"
password = "#######################"
order_list = [] # Peristence for Order
@@ -45,7 +45,7 @@ def post_request(url, data, headers=None):
@tool
def insert_order(items):
"""Create an order with items. The customer can ask for items of a restaurant. The customer want to include an item"""
"""Create an order with items. The customer can ask for items of a restaurant. The customer want to include an item."""
global order_list
order_list.extend(items) # Adiciona os novos itens ao pedido
print("Item(s) incluído(s):", items)
@@ -53,7 +53,9 @@ def insert_order(items):
@tool
def delete_order(item):
"""Delete an Item in the order. The customer can regret about one or more items. The customer can ask for delete item of a restaurant. The customer can request to 'Remove the item' or 'I don't want anymore the item' or 'Delete the item'."""
"""Delete an Item in the order. The customer can regret about one or more items.
The customer can ask for delete item of a restaurant.
The customer can request to 'Remove the item' or 'I don't want anymore the item' or 'Delete the item'."""
global order_list
print("Trying to remove:", item)
for global_item in order_list:
@@ -71,7 +73,8 @@ def search_order():
@tool
def order_cost():
"""This service gives the total of the order, summarizing the items. If the customer says 'give me the bill' or 'summarize the order' or 'what is the total' or 'how much is it'."""
"""This service gives the total of the order, summarizing the items.
If the customer says 'give me the bill' or 'summarize the order' or 'what is the total' or 'how much is it'."""
global order_list
if not order_list:
return {"message": "No items in the order"}
@@ -80,34 +83,47 @@ def order_cost():
print("Total: $", total)
return {"total_cost": total, "order_items": order_list}
@tool
def find_address(postalCode: str, number: str = "", complement: str = "") -> str:
"Find the complete address of a postal code to delivery, along with the building number and complement. postalCode normally is the postal code or CEP, number is the number of buiding and complenent is the apartment or other complement for the address"
url = f"https://xxxxxxxxxxxxxxxxxxxxxxxxxx.apigateway.us-ashburn-1.oci.customer-oci.com/cep/cep?cep={postalCode}"
response = get_rest_service_auth(url)
address = response["frase"]
full_address = f"{address}, Number: {number}, Complement: {complement}"
print(full_address)
return str(full_address)
# @tool
# def find_address(postalCode: str, number: str = "", complement: str = "") -> str:
# """Find the complete address of a postal code to delivery, along with the building number and complement. The customer can ask for 'delivery to' or 'my address is'. postalCode normally is the postal code or CEP, number is the number of buiding and complenent is the apartment or other complement for the address. always confirm the address and the total cost of order."""
# def delivery_address(postalCode: str, number: str = "", complement: str = "") -> str:
# """Find the complete address of a postal code to delivery, along with the building number and complement.
# The customer can ask for 'delivery to' or 'my address is'. postalCode normally is the postal code or CEP,
# number is the number of buiding and complenent is the apartment or other complement for the address. always confirm the address
# and the total cost of order."""
#
# full_address = f"Avenida Paulista, 100 Sao Paulo SP 01310-000"
# url = f"https://cihjkhlijtmunsiiokgrhetowu.apigateway.us-ashburn-1.oci.customer-oci.com/cep/cep?cep={postalCode}"
# response = get_rest_service_auth(url)
#
# address = response["frase"]
# full_address = f"{address}, Number: {number}, Complement: {complement}"
# print(full_address)
# return str(full_address)
tools = [insert_order, order_cost, search_order, find_address, delete_order]
@tool
def delivery_address(postalCode: str, number: str = "", complement: str = "") -> str:
"""Find the complete address of a postal code to delivery, along with the building number and complement.
The customer can ask for 'delivery to' or 'my address is'. postalCode normally is the postal code or CEP,
number is the number of buiding and complenent is the apartment or other complement for the address. always confirm the address
and the total cost of order."""
full_address = f"Avenida Paulista, 1000 - 01310-000 - São Paulo - SP"
print(full_address)
return str(full_address)
#--------------------------------------------------------------------------
tools = [insert_order, order_cost, search_order, delivery_address, delete_order]
# PROMPT AND CONTEXT
prompt = ChatPromptTemplate.from_messages(
[
("system", "Você é um assistente que ajuda clientes a fazer pedidos em um restaurante. Depois que o cliente adiciona um item ao pedido, sempre informe o total. Se o cliente fornecer um código postal (ou CEP), use a ferramenta find_address para obter o endereço completo. O cliente pode consultar a qualquer momento os items pedidos. o cliente pode solicitar a entrega no endereco dizendo 'me entregue no endereco ou no cep', 'meu endereço é e digitar o codigo postal ou cep ou rua'"),
("system", """Você é um assistente que ajuda clientes a fazer pedidos em um restaurante.
Depois que o cliente adiciona um item ao pedido, sempre informe o total.
Se o cliente fornecer um código postal (ou CEP), use a ferramenta find_address para obter o endereço completo.
O cliente pode consultar a qualquer momento os items pedidos. o cliente pode solicitar a entrega no endereco
dizendo 'me entregue no endereco ou no cep', 'meu endereço é e digitar o codigo postal ou cep ou rua'"""),
("placeholder", "{chat_history}"),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
@@ -120,7 +136,7 @@ prompt = ChatPromptTemplate.from_messages(
llm = ChatOCIGenAI(
model_id="cohere.command-r-08-2024",
service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
compartment_id="ocid1.compartment.oc1..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
compartment_id="ocid1.compartment.oc1..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
auth_profile="LATINOAMERICA", # replace with your profile name,
model_kwargs={"temperature": 0.1, "top_p": 0.75, "max_tokens": 2000}
)