This commit is contained in:
2026-01-26 07:14:29 +07:00
commit 9fb5e046ce
16 changed files with 4292 additions and 0 deletions

140
app/testapp/runtests.jl Normal file
View File

@@ -0,0 +1,140 @@
# ---------------------------------------------- 100 --------------------------------------------- #
using JSON3, MQTTClient, Dates, UUIDs, PrettyPrinting, LibPQ, Base64, DataFrames
using GeneralUtils
config = copy(JSON3.read("config.json"))
msgMeta = GeneralUtils.generate_msgMeta(
"/yiem_branch_1/agent/wine/backend/db/api/v1/testing";
senderName = "wine_assistant_admin",
senderId= string(uuid4()),
mqttBrokerAddress= config[:mqttServerInfo][:broker],
mqttBrokerPort= config[:mqttServerInfo][:port],
)
outgoingMsg = Dict(
:msgMeta=> msgMeta,
:payload=> Dict(
:functioncall=> "search_materWineTable",
:args=> Dict(
:columnname=> "wine_name",
:searchkeyword=> "Yarra",
)
)
)
raw = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
sql =
"""
SELECT * FROM wine WHERE wine_name ILIKE '%yarra%';
"""
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)
LibPQ.close(DBconnection)
a = columntable(result)
""" Convert a DataFrame into a list of JSON rows.
# Arguments
- `df::DataFrame`
The input DataFrame to be converted.
# Return
- `rows::Vector{Dict{String, Any}}`
A vector of dictionaries, where each dictionary represents a row in JSON format.
# Example
```jldoctest
julia> using DataFrame, JSON3
julia> df = DataFrame(A = [1, 2, 3], B = ["apple", "banana", "cherry"])
julia> json_rows = dfToJSONRows(df)
```
# Signature
"""
function dfToJSONRows(df::DataFrame)
rows = []
for row in eachrow(df)
json_row = Dict{String, Any}()
for col in names(df)
json_row[col] = row[col]
end
push!(rows, json_row)
end
return rows
end
open("d.json", "w") do io
JSON3.pretty(io, result)
end

80
app/testapp/testing.jl Normal file
View File

@@ -0,0 +1,80 @@
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][:value] * "/1"
client, connection = MakeConnection(config[:mqttBroker][:value], 1883)
msgMeta = GeneralUtils.generate_msgMeta(
"N/A",
replyTopic = config[:servicetopic][:value] # ask frontend reply to this instance_chat_topic
)
agentConfig = Dict(
:receiveprompt=>Dict(
:mqtttopic=> config[:servicetopic][:value], # topic to receive prompt i.e. frontend send msg to this topic
),
:receiveinternal=>Dict(
:mqtttopic=> instanceInternalTopic, # receive topic for model's internal
),
:text2text=>Dict(
:mqtttopic=> config[:text2text][:value],
),
)
# 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(
client,
msgMeta,
agentConfig,
name= "testAgent",
id= "testid", # agent instance id
tools=tools,
)
response = YiemAgent.conversation(a, "hello")