using Revise # remove when this package is completed using YiemAgent, GeneralUtils, JSON3, MQTTClient, Dates, UUIDs, LibPQ 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 # ) function executeSQL(sql::T) where {T<:AbstractString} DBconnection = LibPQ.Connection("host=192.168.88.12 port=5432 dbname=yiem_wine_assistant user=yiem password=yiem@Postgres_0.0") result = LibPQ.execute(DBconnection, sql) close(DBconnection) return result end 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=> 2048, :stop=> ["<|eot_id|>"], :temperature=> 0.2, ) ) ) _response = GeneralUtils.sendReceiveMqttMsg(outgoingMsg; timeout=120) response = _response[:response][:text] return response end # Instantiate an agent a = YiemAgent.sommelier( text2textInstructLLM, executeSQL; name="assistant", id="testingSessionID", # agent instance id ) function main() userinput = "Hello, I would like a get a bottle of wine." for i in 1:10 response = YiemAgent.conversation(a, Dict(:text=> userinput)) println("") println("--> assistant response: \n", response) userinput = "" for i in 1:3 if userinput == "" println("") println("--> user input:") userinput = readline() else break end end end 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. Well, the party is small casual with close friends and no food serving. I'm open to suggestion since I have no specific idea about wine. I'm ok with any region. """ # 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.")) # # input = "query=\"off dry, medium tannin, French Rosé\"" # input = "Search the database for wine type: white, country: France, sweetness level: 1" # YiemAgent.winestock(a, input) # input = "French dry white wines with medium body" # input = "query=\"medium-bodied dry white wine\"" # # input = "the customer is looking for a medium-bodied, dry white wine." # result = YiemAgent.checkinventory(a, input) error("test done") function run_with_timeout(f, args...; timeout=5) result = Ref{Any}() task = Threads.@spawn try result[] = f(args...) catch e println("Task interrupted: ", e) end Timer(timeout) do _ if !istaskdone(task) schedule(task, InterruptException()) println("Task did not complete in time. Aborting.") else println("Task completed within the timeout.") end end return result[] end # Example function that takes arguments and returns a value function example_function(x, y) sleep(10) # Simulate a long-running task return x + y end # Example usage result = run_with_timeout(example_function, 3, 4; timeout=5) println("Result: ", result)