Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions conf/conf.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@
$MAGIC_EVENT_BLACKLIST=""; //Comma-separated list of magic events to exclude from logging.
$LOCATION_BLACKLIST="Dark Brotherhood Sanctuary, Twilight Sepulcher"; //Comma-separated list of location names to exclude from Points of Interest context.
$ITEM_BLACKLIST=""; //Comma-separated list of item/armor names to exclude from dynamic context.
$CARRIAGE_DRIVERS="Bjorlam, Alfarinn, Kibell, Sigaar, Thaer, Engar, Gunjar, Markus"; //Comma-separated NPC names that can offer carriage fast travel.
$FERRY_DRIVERS="Gort, Harlaug, Jolf"; //Comma-separated NPC names that can offer ferry fast travel.
$EVENT_TYPE_FILTER=""; //Comma-separated list of event types to exclude from context generation.
$GROUND_ITEMS_DESCRIPTIONS_ONLY=false; //Only show nearby ground items that have descriptions in the database.
$INVENTORY_ITEMS_DESCRIPTIONS_ONLY=false; //Only show inventory items that have descriptions in the database.
Expand Down
6 changes: 3 additions & 3 deletions conf/conf_loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ function conf_loader_load() {

foreach ($confSchema as $name=>$definition) {
if (isset($definition["type"])) {
$definition["currentValue"] = isset($GLOBALS[$name]) ? $GLOBALS[$name] : '';
$definition["currentValue"] = isset($GLOBALS[$name]) ? $GLOBALS[$name] : ($definition["default"] ?? '');
$confMap[$name]=$definition;
}
else {
if (is_array($definition)) {
foreach ($definition as $name2=>$definition2) {
if (isset($definition2["type"])) {
$definition2["currentValue"] = isset($GLOBALS[$name][$name2]) ? $GLOBALS[$name][$name2] : '';
$definition2["currentValue"] = isset($GLOBALS[$name][$name2]) ? $GLOBALS[$name][$name2] : ($definition2["default"] ?? '');
$confMap["$name $name2"]=$definition2;
}
else if (is_array($definition2)) {
foreach ($definition2 as $name3=>$definition3) {
if (isset($definition3["type"])) {
$definition3["currentValue"] = isset($GLOBALS[$name][$name2][$name3]) ? $GLOBALS[$name][$name2][$name3] : '';
$definition3["currentValue"] = isset($GLOBALS[$name][$name2][$name3]) ? $GLOBALS[$name][$name2][$name3] : ($definition3["default"] ?? '');
$confMap["$name $name2 $name3"]=$definition3;
}

Expand Down
2 changes: 0 additions & 2 deletions conf/conf_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
"MAGIC_EVENT_BLACKLIST": {"userlvl":"basic","type":"longstring","scope":"global","description":"Comma-separated list of magic event names to exclude from logging (e.g. 'Administer Mixture, [BFCO-AttackSwingFX] 0.5/1.5, Healing')."},
"LOCATION_BLACKLIST": {"userlvl":"basic","type":"longstring","scope":"global","description":"Comma-separated list of location names to exclude from Points of Interest context (e.g. 'Dark Brotherhood Sanctuary, Twilight Sepulcher')."},
"ITEM_BLACKLIST": {"userlvl":"basic","type":"longstring","scope":"global","description":"Comma-separated list of item/armor names to exclude from dynamic context (e.g. 'Iron Sword, Leather Armor, Health Potion')."},
"CARRIAGE_DRIVERS": {"userlvl":"basic","type":"longstring","scope":"global","description":"Comma-separated NPC names that can offer carriage fast travel (e.g. 'Bjorlam, Alfarinn, Kibell')."},
"FERRY_DRIVERS": {"userlvl":"basic","type":"longstring","scope":"global","description":"Comma-separated NPC names that can offer ferry fast travel (e.g. 'Gort, Harlaug, Jolf')."},
"EVENT_TYPE_FILTER": {"userlvl":"basic","type":"longstring","scope":"global","description":"Comma-separated list of event types to exclude from context generation (e.g. 'death, itemfound, spellcast')."},
"GROUND_ITEMS_DESCRIPTIONS_ONLY": {"userlvl":"basic","type":"boolean","scope":"global","description":"Only show nearby ground items in context that have descriptions in the description manager."},
"INVENTORY_ITEMS_DESCRIPTIONS_ONLY": {"userlvl":"basic","type":"boolean","scope":"global","description":"Only show inventory items in context that have descriptions in the description manager."},
Expand Down
47 changes: 13 additions & 34 deletions connector/google_openaijson.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ public function open($contextData, $customParms)
$lastActionName=$element["tool_calls"][0]["function"]["name"];
$localFuncCodeName=getFunctionCodeName($element["tool_calls"][0]["function"]["name"]);
$localArguments=json_decode($element["tool_calls"][0]["function"]["arguments"],true);
$lastAction=strtr($GLOBALS["F_RETURNMESSAGES"][$localFuncCodeName],[
"#TARGET#"=>current($localArguments),
]);
$lastAction=herikaFormatReturnMessageTemplate($localFuncCodeName, current($localArguments));

$contextDataCopy[]=[
"role"=>"assistant",
Expand Down Expand Up @@ -414,6 +412,10 @@ public function process()
$finalData["message"]=implode(",",$finalData["message"]);
}

if (isset($finalData["action"]) && chimActionShouldSuppressImmediateMessage($finalData["action"] ?? '')) {
$finalData["message"] = "";
}

if (isset($finalData["message"])) {
if (is_array($finalData)&&isset($finalData["message"])) {
$mangledBuffer = str_replace($this->_extractedbuffer, "", $finalData["message"]);
Expand Down Expand Up @@ -466,15 +468,17 @@ public function processActions()
$parameterArr = json_decode($this->_parameterBuff, true);
if (is_array($parameterArr)) {
$parameter = current($parameterArr); // Only support for one parameter
$functionCodeName = getFunctionCodeName($this->_functionName);
$parameter = buildFunctionExecutionParameter($functionCodeName, $parameter);
$commandStr = "{$GLOBALS["HERIKA_NAME"]}|command|$functionCodeName@$parameter\r\n";

if (!isset($alreadysent[md5("{$GLOBALS["HERIKA_NAME"]}|command|{$this->_functionName}@$parameter\r\n")])) {
$functionCodeName=getFunctionCodeName($this->_functionName);
$this->_commandBuffer[]="{$GLOBALS["HERIKA_NAME"]}|command|$functionCodeName@$parameter\r\n";
if (!isset($alreadysent[md5($commandStr)])) {
$this->_commandBuffer[] = $commandStr;
//echo "Herika|command|$functionCodeName@$parameter\r\n";

}

$alreadysent[md5("{$GLOBALS["HERIKA_NAME"]}|command|{$this->_functionName}@$parameter\r\n")] = "{$GLOBALS["HERIKA_NAME"]}|command|{$this->_functionName}@$parameter\r\n";
$alreadysent[md5($commandStr)] = $commandStr;
if (ob_get_level()) @ob_flush();
} else
return null;
Expand All @@ -483,33 +487,8 @@ public function processActions()
$parsedResponse=__jpd_decode_lazy($this->_buffer); // USE JPD_LAZY?
if (is_array($parsedResponse)) {
if (!empty($parsedResponse["action"])) {
if (!isset($alreadysent[md5("{$GLOBALS["HERIKA_NAME"]}|command|{$parsedResponse["action"]}@{$parsedResponse["target"]}\r\n")])) {

$functionDef=findFunctionByName($parsedResponse["action"]);
if ($functionDef) {
$functionCodeName=getFunctionCodeName($parsedResponse["action"]);
if (strlen($functionDef["parameters"]["required"][0] ?? '')>0) {
if (!empty($parsedResponse["target"])) {
$this->_commandBuffer[]="{$GLOBALS["HERIKA_NAME"]}|command|$functionCodeName@{$parsedResponse["target"]}\r\n";
}
else {
Logger::warn("Missing required parameter");
}

} else {
$this->_commandBuffer[]="{$GLOBALS["HERIKA_NAME"]}|command|$functionCodeName@{$parsedResponse["target"]}\r\n";
}
} elseif ($parsedResponse["action"] != "Talk") {
Logger::warn("Function not found for {$parsedResponse["action"]}");
}

//$functionCodeName=getFunctionCodeName($parsedResponse["action"]);
//$this->_commandBuffer[]="{$GLOBALS["HERIKA_NAME"]}|command|{$parsedResponse["action"]}@{$parsedResponse["target"]}\r\n";
//echo "Herika|command|$functionCodeName@$parameter\r\n";
$alreadysent[md5("{$GLOBALS["HERIKA_NAME"]}|command|{$parsedResponse["action"]}@{$parsedResponse["target"]}\r\n")]=end($this->_commandBuffer);

}

$executionContext = buildFunctionExecutionContextFromResponse($parsedResponse);
queueFunctionExecutionCommand($this->_commandBuffer, $alreadysent, $executionContext, "google_openaijson");
}

if (ob_get_level()) @ob_flush();
Expand Down
82 changes: 14 additions & 68 deletions connector/groqjson.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ public function open($contextData, $customParms)
$localFuncCodeName=getFunctionCodeName($element["tool_calls"][0]["function"]["name"]);
$localArguments=json_decode($element["tool_calls"][0]["function"]["arguments"],true);
if (isset($GLOBALS["F_RETURNMESSAGES"][$localFuncCodeName])) {
$lastAction=strtr($GLOBALS["F_RETURNMESSAGES"][$localFuncCodeName],[
"#TARGET#"=>current($localArguments),
]);
$lastAction=herikaFormatReturnMessageTemplate($localFuncCodeName, current($localArguments));
}
$contextDataCopy[]=[
"role"=>"assistant",
Expand Down Expand Up @@ -481,6 +479,10 @@ public function process()
$finalData["message"]=implode(",",$finalData["message"]);
}

if (isset($finalData["action"]) && chimActionShouldSuppressImmediateMessage($finalData["action"] ?? '')) {
$finalData["message"] = "";
}

if (isset($finalData["message"])) {
if (is_array($finalData)&&isset($finalData["message"])) {
$mangledBuffer = str_replace($this->_extractedbuffer, "", $finalData["message"]);
Expand Down Expand Up @@ -567,13 +569,15 @@ public function processActions()
$parameterArr = json_decode($this->_parameterBuff, true);
if (is_array($parameterArr)) {
$parameter = current($parameterArr);
$functionCodeName = getFunctionCodeName($this->_functionName);
$parameter = buildFunctionExecutionParameter($functionCodeName, $parameter);
$commandStr = "{$GLOBALS["HERIKA_NAME"]}|command|$functionCodeName@$parameter\r\n";

if (!isset($alreadysent[md5("{$GLOBALS["HERIKA_NAME"]}|command|{$this->_functionName}@$parameter\r\n")])) {
$functionCodeName=getFunctionCodeName($this->_functionName);
$this->_commandBuffer[]="{$GLOBALS["HERIKA_NAME"]}|command|$functionCodeName@$parameter\r\n";
if (!isset($alreadysent[md5($commandStr)])) {
$this->_commandBuffer[] = $commandStr;
}

$alreadysent[md5("{$GLOBALS["HERIKA_NAME"]}|command|{$this->_functionName}@$parameter\r\n")] = "{$GLOBALS["HERIKA_NAME"]}|command|{$this->_functionName}@$parameter\r\n";
$alreadysent[md5($commandStr)] = $commandStr;
if (ob_get_level()) @ob_flush();
} else
return null;
Expand All @@ -584,67 +588,9 @@ public function processActions()
if (!empty($parsedResponse["action"])) {
if (!isset($parsedResponse["target"]))
$parsedResponse["target"] = "";

$functionDef=findFunctionByName($parsedResponse["action"]);
$paramString = "";
$functionCodeName = "";
if (isset($functionDef)) {
$functionCodeName=getFunctionCodeName($parsedResponse["action"]);
$paramCount = count($functionDef["parameters"]["properties"] ?? []);

if ($paramCount > 1) {
$params = [];
foreach (array_keys($functionDef["parameters"]["properties"] ?? []) as $paramName) {
if (isset($parsedResponse[$paramName])) {
$paramValue = $parsedResponse[$paramName];
$paramType = $functionDef["parameters"]["properties"][$paramName]["type"] ?? "string";
if ($paramType === "integer" && is_numeric($paramValue)) {
$paramValue = intval($paramValue);
}
$params[$paramName] = $paramValue;
}
}

$requiredParams = $functionDef["parameters"]["required"] ?? [];
foreach ($requiredParams as $reqParam) {
if (!isset($parsedResponse[$reqParam]) || $parsedResponse[$reqParam] === "") {
Logger::warn("groqjson: Missing required parameter '{$reqParam}' for function {$parsedResponse["action"]}");
}
}

$paramString = json_encode($params);
} else {
$paramString = $parsedResponse["target"] ?? "";
}
} else {
$paramString = $parsedResponse["target"] ?? "";
$functionCodeName = $parsedResponse["action"] ?? "";
}

$commandStr = "{$GLOBALS["HERIKA_NAME"]}|command|$functionCodeName@{$paramString}\r\n";
if (!isset($alreadysent[md5($commandStr)])) {

if (isset($functionDef)) {
if (strlen($functionDef["parameters"]["required"][0] ?? '')>0) {
if (!empty($paramString)) {
$this->_commandBuffer[]=$commandStr;
}
else {
Logger::warn("groqjson: Missing required parameters");
$this->_commandBuffer[]="{$GLOBALS["HERIKA_NAME"]}|command|$functionCodeName@\r\n";
}

} else {
$this->_commandBuffer[]=$commandStr;
}
} elseif ($parsedResponse["action"] != "Talk") {
Logger::warn("groqjson: Function not found for {$parsedResponse["action"]}");
}

$alreadysent[md5($commandStr)]=end($this->_commandBuffer);

}


$executionContext = buildFunctionExecutionContextFromResponse($parsedResponse);
queueFunctionExecutionCommand($this->_commandBuffer, $alreadysent, $executionContext, "groqjson");
}

if (ob_get_level()) @ob_flush();
Expand Down
5 changes: 2 additions & 3 deletions connector/koboldcpp.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public function processActions()
else if ($intent=="WriteIntoQuestJournal"||$intent=="UpdateQuestJournal") {
// bypass reponse.
if (isset($jsonData["topic"])) {
$this->_functionRawName="SetCurrentTask@{$jsonData["topic"]}";
$this->_functionRawName="";
$GLOBALS["db"]->insert(
'currentmission',
array(
Expand Down Expand Up @@ -524,7 +524,7 @@ public function processActions()

else if ($kobParsed[0]=="SetCurrentPlan") {
// bypass reponse.
$this->_functionRawName="SetCurrentTask@{$kobParsed[1]}";
$this->_functionRawName="";
$GLOBALS["db"]->insert(
'currentmission',
array(
Expand All @@ -535,7 +535,6 @@ public function processActions()
'localts' => time()
)
);
$alreadysent[md5("Herika|command|{$this->_functionRawName}\r\n")] = "Herika|command|{$this->_functionRawName}\r\n";
}
else if ($kobParsed[0]=="ExchangeItems") {
// bypass reponse.
Expand Down
Loading