This commit is contained in:
narawat lamaiin
2024-08-27 13:22:53 +07:00
parent a80b8e0260
commit ca0f9cd53f
5 changed files with 70 additions and 141 deletions

View File

@@ -195,7 +195,7 @@ end
main()
"""
I'm joining a graduation party this evening. I want a bottle of dry white wine from the US. I'm ok with any price range.
I'm joining a graduation party this evening. I want to get a bottle of white wine from the US. I'm ok with any price range.
Well, the party is small casual with close friends and no food serving.
I'm open to suggestion since I have no specific idea.
I'm ok with any region.
@@ -207,6 +207,12 @@ main()
"""
wines =
"""
Summary: This table contains two wine records, both from the United States, with white wine types, moderate sweetness (2), and high intensity (5).
More details: 1) wine_id: add9824f-81b0-47da-a08a-ee20498bc6c8, wine_name: Belle Cote Chardonnay, brand: Peter Michael, manufacturer: Peter Michael, region: Californian, country: United States, wine_type: white, grape_variety: Chardonnay, serving_temperature: 11 to 13 Celsius, intensity: 5, sweetness: 2, tannin: missing, acidity: 3, fizziness: missing, tasting_notes: oak, butter, vanilla, cream, oil, lemon curd, pear, peach, apple
2) wine_id: ff9a494c-e916-44c4-9385-1c18b23aa825, wine_name: Ma Belle-Fille Chardonnay, brand: Peter Michael, manufacturer: Peter Michael, region: Californian, country: United States, wine_type: white, grape_variety: Chardonnay, serving_temperature: 11 to 13 Celsius, intensity: 5, sweetness: 2, tannin: missing, acidity: 3, fizziness: missing, tasting_notes: oak, butter, vanilla, cream, banana, cheese, apricot, peach, apple
"""
@@ -275,4 +281,8 @@ result = run_with_timeout(example_function, 3, 4; timeout=5)
println("Result: ", result)
a = `$"hello\nworld"`
a = $"hello\nworld"
a = """$("hello\nworld")"""

View File

@@ -1,116 +1,20 @@
using Revise # remove when this package is completed
using YiemAgent, GeneralUtils, JSON3, MQTTClient, Dates, UUIDs, DataStructures
using Base.Threads
import requests
# ---------------------------------------------- 100 --------------------------------------------- #
# URL of the API endpoint
url = 'https://api.yiem.cc/wine/agent/sommelier/prompt/apiv1'
config = copy(JSON3.read("config.json"))
instanceInternalTopic = config[:serviceInternalTopic][:mqtttopic] * "/1"
client, connection = MakeConnection(config[:mqttServerInfo][:broker],
config[:mqttServerInfo][:port])
receiveUserMsgChannel = Channel{Dict}(4)
receiveInternalMsgChannel = Channel{Dict}(4)
msgMeta = GeneralUtils.generate_msgMeta(
"N/A",
replyTopic = config[:servicetopic][:mqtttopic] # ask frontend reply to this instance_chat_topic
)
agentConfig = Dict(
:mqttServerInfo=> config[:mqttServerInfo],
:receivemsg=> Dict(
:prompt=> config[:servicetopic][:mqtttopic], # topic to receive prompt i.e. frontend send msg to this topic
:internal=> instanceInternalTopic,
),
:externalservice=> config[:externalservice],
)
# Instantiate an agent
tools=Dict( # update input format
"askbox"=> Dict(
:description => "<askbox tool description>Useful for when you need to ask the user for more context. Do not ask the user their own question.</askbox tool description>",
:input => """<input>Input is a text in JSON format.</input><input example>{\"Q1\": \"How are you doing?\", \"Q2\": \"How may I help you?\"}</input example>""",
:output => "" ,
:func => nothing,
),
# "winestock"=> Dict(
# :description => "<winestock tool description>A handy tool for searching wine in your inventory that match the user preferences.</winestock tool description>",
# :input => """<input>Input is a JSON-formatted string that contains a detailed and precise search query.</input><input example>{\"wine type\": \"rose\", \"price\": \"max 35\", \"sweetness level\": \"sweet\", \"intensity level\": \"light bodied\", \"Tannin level\": \"low\", \"Acidity level\": \"low\"}</input example>""",
# :output => """<output>Output are wines that match the search query in JSON format.""",
# :func => ChatAgent.winestock,
# ),
"finalanswer"=> Dict(
:description => "<tool description>Useful for when you are ready to recommend wines to the user.</tool description>",
:input => """<input format>{\"finalanswer\": \"some text\"}.</input format><input example>{\"finalanswer\": \"I recommend Zena Crown Vista\"}</input example>""",
:output => "" ,
:func => nothing,
),
)
a = YiemAgent.sommelier(
receiveUserMsgChannel,
receiveInternalMsgChannel,
agentConfig,
name= "assistant",
id= "testingSessionID", # agent instance id
tools=tools,
)
input =
OrderedDict{Symbol, Any}(
:question => "Hello, I would like a get a bottle of wine",
:thought_1 => "A customer wants to buy a bottle of wine. Before making a recommendation, I need to know more about their preferences.",
:action_1 => Dict{Symbol, Any}(
:name => "chatbox",
:input => "What is the occasion for which you're buying this wine?"
),
:observation_1 => "We are holding a wedding party",
:thought_2 => "A wedding party, that's a great occasion! The customer might be looking for a celebratory drink. Let me ask some more questions to narrow down the options.",
:action_2 => Dict{Symbol, Any}(
:name => "chatbox",
:input => "What type of food will you be serving at the wedding?"
),
:observation_2 => "It will be Thai dishes.",
:thought_3 => "With Thai food, I should recommend a wine that complements its spicy and savory flavors. And since it's a celebratory occasion, the customer might prefer a full-bodied wine.",
:action_3 => Dict{Symbol, Any}(
:name => "chatbox",
:input => "What is your budget for this bottle of wine?"
),
:observation_3 => "I would spend up to 50 bucks.",
:thought_4 => "Now that I have some more information, it's time to narrow down the options.",
:action_4 => Dict{Symbol, Any}(
:name => "winestock",
:input => "red wine with full body, pairs well with spicy food, budget \$50"),
:observation_4 => "I found the following wines in our stock: \n{\n 1: El Enemigo Cabernet Franc 2019\n2: Tantara Chardonnay 2017\n\n}\n",
:thought_5 => "Now that I have a list of potential wines, I need to know more about the customer's taste preferences.",
:action_5 => Dict{Symbol, Any}(
:name => "chatbox",
:input => "What type of wine characteristics are you looking for? (e.g. t.e.g. tannin level, sweetness, intensity, acidity)"
),
:observation_5 => "I like full-bodied Red wine with low tannin.",
:thought_6 => "Now that I have more information about the customer's preferences, it's time to make a recommendation.",
:action_6 => Dict{Symbol, Any}(
:name => "recommendbox",
:input => "El Enemigo Cabernet Franc 2019"
),
:observation_6 => "I don't like the one you recommend. I want dry wine."
)
result = YiemAgent.reflector(a, input)
# Data to be sent in the JSON request
data = {
'sid': 'dummySID',
'txt': 'hello'
}
# Sending the POST request
response = requests.post(url, json=data)
# Displaying the response
print('Status Code:', response.status_code)
print('Response JSON:', response.json())