From 03de659c9b2996829a0a18aed937178cf794679d Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Wed, 30 Apr 2025 12:58:32 +0700 Subject: [PATCH] update companion --- src/interface.jl | 12 +++++------- src/type.jl | 13 +++++-------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index 684b28a..5af3aec 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -1509,10 +1509,6 @@ end # modify it to work with customer object function generatechat(a::companion; converPartnerName::Union{String, Nothing}=nothing, maxattempt=10) - - # header = ["Dialogue:"] - # dictkey = ["dialogue"] - response = nothing # placeholder for show when error msg show up errornote = "N/A" llmkwargs=Dict( @@ -1540,13 +1536,15 @@ function generatechat(a::companion; converPartnerName::Union{String, Nothing}=no end # put in model format - _prompt = GeneralUtils.formatLLMtext(_prompt, "granite3") + _prompt = GeneralUtils.formatLLMtext(_prompt, a.llmFormatName) + + # replace user and assistant with partner name prompt = replace(_prompt, "|>user"=>"|>$(converPartnerName)") prompt = replace(prompt, "|>assistant"=>"|>$(a.name)") - response = a.func[:text2textInstructLLM](prompt; llmkwargs=llmkwargs) + response = a.func[:text2textInstructLLM](prompt; llmkwargs=llmkwargs, senderId=a.id) response = replace(response, "<|im_start|>"=> "") - response = GeneralUtils.deFormatLLMtext(response, "granite3") + response = GeneralUtils.deFormatLLMtext(response, a.llmFormatName) # check whether LLM just repeat the previous dialogue for msg in a.chathistory diff --git a/src/type.jl b/src/type.jl index 89faa71..0207b89 100644 --- a/src/type.jl +++ b/src/type.jl @@ -18,6 +18,7 @@ mutable struct companion <: agent chathistory::Vector{Dict{Symbol, Any}} memory::Dict{Symbol, Any} func::NamedTuple # NamedTuple of functions + llmFormatName::String end function companion( @@ -25,9 +26,10 @@ function companion( ; systemmsg::Union{String, Nothing}= nothing, name::String= "Assistant", - id::String= string(uuid4()), + id::String= GeneralUtils.uuid4snakecase(), maxHistoryMsg::Integer= 20, chathistory::Vector{Dict{Symbol, String}} = Vector{Dict{Symbol, String}}(), + llmFormatName::String= "granite3" ) if systemmsg === nothing @@ -41,12 +43,6 @@ function companion( - Focus on the latest conversation. - Your like to be short and concise. - You should then respond to the user with: - Dialogue: Given the situation, what would you say to the user? - - You should only respond format as described below: - Dialogue: ... - Let's begin! """ end @@ -79,7 +75,8 @@ function companion( maxHistoryMsg, chathistory, memory, - func + func, + llmFormatName ) return newAgent