update
This commit is contained in:
+1
-1
@@ -179,7 +179,7 @@ function _process_message(agent::yiemAgent)::assistantMessage
|
|||||||
# call agent.prepareContext()
|
# call agent.prepareContext()
|
||||||
preparedContext = agent.prepareContext(agent._state)
|
preparedContext = agent.prepareContext(agent._state)
|
||||||
|
|
||||||
#WORKING Call agent.formatMsgForLLM(agent._state) to format for LLM
|
# Call agent.formatMsgForLLM(agent._state) to format for LLM
|
||||||
formatted_messages = agent.formatMsgForLLM(preparedContext)
|
formatted_messages = agent.formatMsgForLLM(preparedContext)
|
||||||
|
|
||||||
# Call llmCall() (blocking — the task waits here)
|
# Call llmCall() (blocking — the task waits here)
|
||||||
|
|||||||
+38
-51
@@ -115,60 +115,47 @@ end
|
|||||||
|
|
||||||
""" convert preparedcontext into openai message format ready to be used by LLM
|
""" convert preparedcontext into openai message format ready to be used by LLM
|
||||||
"""
|
"""
|
||||||
function formatMsgForLLM(messages::Vector{agentMessage})::Vector{Dict{String, Any}}
|
function formatMsgForLLM(preparedContext::Vector{agentMessage})::Dict{String, Any}
|
||||||
|
""" openai message format example
|
||||||
openai_messages = Vector{Dict{String, Any}}()
|
msg = Dict(
|
||||||
|
"model" => "gemma-4-E4B-it-UD-Q4_K_XL",
|
||||||
for msg in messages
|
"messages" => [
|
||||||
if msg isa userMessage
|
Dict(
|
||||||
push!(openai_messages, _toOpenAIUserMsg(msg))
|
"role" => "system",
|
||||||
elseif msg isa assistantMessage
|
"content" => [
|
||||||
push!(openai_messages, _toOpenAIAssistantMsg(msg))
|
Dict("type" => "text", "text" => systemmsg),
|
||||||
elseif msg isa toolResultMessage
|
]
|
||||||
push!(openai_messages, _toOpenAIToolResultMsg(msg))
|
),
|
||||||
end
|
Dict(
|
||||||
end
|
"role" => "user",
|
||||||
|
"content" => [
|
||||||
return openai_messages
|
Dict("type" => "text", "text" => "Do you have something similar to the one in the image?"),
|
||||||
end
|
Dict(
|
||||||
|
"type" => "image_url",
|
||||||
function _toOpenAIUserMsg(msg::userMessage)::Dict{String, Any}
|
"image_url" => Dict("url" => data1_uri)
|
||||||
return Dict{String, Any}(
|
)
|
||||||
"role" => "user",
|
]
|
||||||
"content" => _toOpenAIBlocks(msg.content),
|
),
|
||||||
|
Dict(
|
||||||
|
"role" => "assistant",
|
||||||
|
"content" => [
|
||||||
|
Dict("type" => "text", "text" => "let me check."),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
Dict(
|
||||||
|
"role" => "toolResult",
|
||||||
|
"content" => [
|
||||||
|
Dict("type" => "text", "text" => "name: Chateau Montelena ..."),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
],
|
||||||
|
"temperature" => 0.7
|
||||||
)
|
)
|
||||||
end
|
"""
|
||||||
|
|
||||||
function _toOpenAIAssistantMsg(msg::assistantMessage)::Dict{String, Any}
|
# convert various messages to openai message format
|
||||||
return Dict{String, Any}(
|
|
||||||
"role" => "assistant",
|
|
||||||
"content" => _toOpenAIBlocks(msg.content),
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
function _toOpenAIToolResultMsg(msg::toolResultMessage)::Dict{String, Any}
|
return openai_message
|
||||||
return Dict{String, Any}(
|
|
||||||
"role" => "tool",
|
|
||||||
"tool_call_id" => msg.toolCallId,
|
|
||||||
"name" => msg.toolName,
|
|
||||||
"content" => _toOpenAIBlocks(msg.content),
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
function _toOpenAIBlocks(contents::Vector{messageContent})::Vector{Dict{String, Any}}
|
|
||||||
blocks = Vector{Dict{String, Any}}()
|
|
||||||
for c in contents
|
|
||||||
if c isa textContent
|
|
||||||
push!(blocks, Dict("type" => "text", "text" => c.text))
|
|
||||||
elseif c isa imageContent
|
|
||||||
data_uri = "data:$(c.mimeType);base64,$(c.data)"
|
|
||||||
push!(blocks, Dict(
|
|
||||||
"type" => "image_url",
|
|
||||||
"image_url" => Dict("url" => data_uri),
|
|
||||||
))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return blocks
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user