102 lines
2.6 KiB
Julia
102 lines
2.6 KiB
Julia
using Revise # remove when this package is completed
|
|
using YiemAgent, GeneralUtils, JSON3, MQTTClient, Dates, UUIDs
|
|
using Base.Threads
|
|
|
|
# ---------------------------------------------- 100 --------------------------------------------- #
|
|
|
|
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)
|
|
println(typeof(connection))
|
|
msgMeta = GeneralUtils.generate_msgMeta(
|
|
"N/A",
|
|
replyTopic = config[:servicetopic][:mqtttopic] # ask frontend reply to this instance_chat_topic
|
|
)
|
|
|
|
# commConfig = Dict(
|
|
# :mqttServerInfo=> config[:mqttServerInfo],
|
|
# :receivemsg=> Dict(
|
|
# :prompt=> config[:servicetopic][:mqtttopic], # topic to receive prompt i.e. frontend send msg to this topic
|
|
# ),
|
|
# :externalservice=> config[:externalservice],
|
|
# )
|
|
|
|
function text2textInstructLLM(prompt::String)
|
|
msgMeta = GeneralUtils.generate_msgMeta(
|
|
config[:externalservice][:text2textinstruct][:mqtttopic],
|
|
senderName= "yiemagent",
|
|
senderId= string(uuid4()),
|
|
receiverName= "text2textinstruct",
|
|
mqttBroker= config[:mqttServerInfo][:broker],
|
|
mqttBrokerPort= config[:mqttServerInfo][:port],
|
|
)
|
|
|
|
outgoingMsg = Dict(
|
|
:msgMeta=> msgMeta,
|
|
:payload=> Dict(
|
|
:text=> prompt,
|
|
:kwargs=> Dict(
|
|
:max_tokens=> 512,
|
|
:stop=> ["<|eot_id|>"],
|
|
:temperature=> 0.2,
|
|
)
|
|
)
|
|
)
|
|
|
|
_response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
|
|
response = _response[:response][:text]
|
|
|
|
return response
|
|
end
|
|
|
|
# Instantiate an agent
|
|
a = YiemAgent.sommelier(
|
|
text2textInstructLLM,
|
|
name="assistant",
|
|
id="testingSessionID", # agent instance id
|
|
)
|
|
|
|
# response = YiemAgent.conversation(a, Dict(:text=> "newtopic",) )
|
|
|
|
response = YiemAgent.conversation(a, Dict(:text=> "Hello, I would like a get a bottle of wine."))
|
|
println("---> YiemAgent: ", response)
|
|
|
|
response = YiemAgent.conversation(a, Dict(:text=> "I'm having a graduation party this evening. I'll pay at most 30 bucks.",
|
|
:select=> nothing,
|
|
:reward=> 0,
|
|
:isterminal=> false,
|
|
) )
|
|
println("---> YiemAgent: ", response)
|
|
|
|
|
|
|
|
|
|
dummyinput = "price below 50, full-bodied red wine with sweetness level 2, low tannin level and medium acidity level, Thai dishes"
|
|
response = YiemAgent.winestock(a, dummyinput)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|