update newAgent

This commit is contained in:
2023-11-01 04:11:03 +00:00
parent 12110e54c1
commit 28e624fe54
3 changed files with 40 additions and 23 deletions

View File

@@ -4,7 +4,8 @@ module interface
export agent, addNewMessage, clearMessage, removeLatestMsg, generatePrompt_tokenPrefix,
generatePrompt_tokenSuffix
using JSON3, DataStructures, Dates
using JSON3, DataStructures, Dates, UUIDs
using CommUtils
# ---------------------------------------------------------------------------- #
# pythoncall setting #
@@ -18,16 +19,16 @@ using JSON3, DataStructures, Dates
# systemPython = split(read(`which python`, String), "\n")[1]
# ENV["JULIA_PYTHONCALL_EXE"] = systemPython # find python location with $> which python ex. raw"/root/conda/bin/python"
using PythonCall
const py_agents = PythonCall.pynew()
const py_llms = PythonCall.pynew()
function __init__()
# PythonCall.pycopy!(py_cv2, pyimport("cv2"))
# using PythonCall
# const py_agents = PythonCall.pynew()
# const py_llms = PythonCall.pynew()
# function __init__()
# # PythonCall.pycopy!(py_cv2, pyimport("cv2"))
# equivalent to from urllib.request import urlopen in python
PythonCall.pycopy!(py_agents, pyimport("langchain.agents"))
PythonCall.pycopy!(py_llms, pyimport("langchain.llms"))
end
# # equivalent to from urllib.request import urlopen in python
# PythonCall.pycopy!(py_agents, pyimport("langchain.agents"))
# PythonCall.pycopy!(py_llms, pyimport("langchain.llms"))
# end
#------------------------------------------------------------------------------------------------100
@@ -35,11 +36,11 @@ end
@kwdef mutable struct agent
availableRole=["system", "user", "assistant"]
agentName="assistant"
agentName::String="assistant"
maxUserMsg::Int= 10
llmAIRequestMqttTopic_openblas= "llm/openblas/request"
llmAIRequestMqttTopic_gpu= "llm/api/v0.0.1/gpu/request"
self_llmReceiveMqttTopic= "chatbothub/llm/respond"
earlierConversation::String="" # summary of earlier conversation
thoughts::String= "" # internal thinking area
mqttClient::Union{mqttClient, Nothing}= nothing
""" Dict(Role=> Content) ; Role can be system, user, assistant
Example:
@@ -56,20 +57,16 @@ end
function agent(
agentName::String,
systemMessage::String, # system message of an agent
llmAIRequestMqttTopic_openblas::String,
llmAIRequestMqttTopic_gpu::String,
self_llmReceiveMqttTopic::String;
availableRole::AbstractArray=["system", "user", "assistant"],
maxUserMsg::Int=10)
maxUserMsg::Int=10,
mqttClientSpec::Tuple;
availableRole::AbstractArray=["system", "user", "assistant"],)
newAgent= agent()
newAgent.llmAIRequestMqttTopic_openblas= llmAIRequestMqttTopic_openblas
newAgent.llmAIRequestMqttTopic_gpu= llmAIRequestMqttTopic_gpu
newAgent.self_llmReceiveMqttTopic= self_llmReceiveMqttTopic
newAgent.availableRole= availableRole
newAgent.maxUserMsg= maxUserMsg
systemMessage= "Your name is $agentName. " * systemMessage
newAgent.messages= [Dict(:role=>"system", :content=> systemMessage, :timestamp=> Dates.now()),]
newAgent.mqttClient= mqttClient(mqttClientSpec)
return newAgent
end