@ -441,72 +441,10 @@ String8List dump_memory_as_json(Arena *arena, Memory *it)
return current_list ;
return current_list ;
}
}
// outputs json which is parsed by the server
String8List memory_description ( Arena * arena , Entity * e , Memory * it )
String8 generate_chatgpt_prompt ( Arena * arena , GameState * gs , Entity * e , CanTalkTo can_talk_to )
{
assert ( e - > is_npc ) ;
assert ( e - > npc_kind < ARRLEN ( characters ) ) ;
ArenaTemp scratch = GetScratch ( & arena , 1 ) ;
String8List list = { 0 } ;
PushWithLint ( scratch . arena , & list , " [ " ) ;
# define AddFmt(...) PushWithLint(scratch.arena, ¤t_list, __VA_ARGS__)
# define AddNewNode(node_type) { S8ListPush(scratch.arena, &list, make_json_node(scratch.arena, node_type, S8ListJoin(scratch.arena, current_list, &(StringJoin){0}))); current_list = (String8List){0}; }
// make first system node
{
String8List current_list = { 0 } ;
AddFmt ( " %s \n \n " , global_prompt ) ;
AddFmt ( " %s \n \n " , characters [ e - > npc_kind ] . prompt ) ;
AddFmt ( " The characters who are near you, that you can target: \n " ) ;
BUFF_ITER ( Entity * , & can_talk_to )
{
assert ( ( * it ) - > is_npc ) ;
String8 info = S8Lit ( " " ) ;
if ( ( * it ) - > killed )
{
info = S8Lit ( " - they're currently dead, they were murdered " ) ;
}
AddFmt ( " %s%.*s \n " , characters [ ( * it ) - > npc_kind ] . name , S8VArg ( info ) ) ;
}
AddFmt ( " \n " ) ;
// @TODO unhardcode this, this will be a description of where the character is right now
//AddFmt("You're currently standing in Daniel's farm's barn, a run-down structure that barely serves its purpose. Daniel's mighty protective of it though.\n");
AddFmt ( " You and everybody you're talking to is in a small sparse forest near Daniel's farm. There are some mysterious mechanical parts strewn about on the floor that Daniel seems relunctant and fearful to talk about. \n " ) ;
AddFmt ( " \n " ) ;
AddFmt ( " The actions you can perform, what they do, and the arguments they expect: \n " ) ;
AvailableActions can_perform ;
fill_available_actions ( gs , e , & can_perform ) ;
BUFF_ITER ( ActionKind , & can_perform )
{
{
AddFmt ( " %s - %s - %s \n " , actions [ * it ] . name , actions [ * it ] . description , actions [ * it ] . argument_description ) ;
}
AddNewNode ( MSG_SYSTEM ) ;
}
String8List current_list = { 0 } ;
String8List current_list = { 0 } ;
bool in_drama_memories = true ;
# define AddFmt(...) PushWithLint(arena, ¤t_list, __VA_ARGS__)
assert ( e - > memories_first - > context . drama_memory ) ;
for ( Memory * it = e - > memories_first ; it ; it = it - > next )
{
// going through memories, I'm going to accumulate human understandable sentences for what happened in current_list.
// when I see an 'i_said_this' memory, that means I flush. and add a new assistant node.
// write a new human understandable sentence or two to current_list
if ( ! it - > context . i_said_this ) {
if ( in_drama_memories & & ! it - > context . drama_memory )
{
in_drama_memories = false ;
AddFmt ( " Some time passed... \n " ) ;
}
// dump a human understandable sentence description of what happened in this memory
// dump a human understandable sentence description of what happened in this memory
bool no_longer_wants_to_converse = false ; // add the no longer wants to converse text after any speech, it makes more sense reading it
bool no_longer_wants_to_converse = false ; // add the no longer wants to converse text after any speech, it makes more sense reading it
if ( it - > action_taken ! = ACT_none )
if ( it - > action_taken ! = ACT_none )
@ -577,6 +515,78 @@ String8 generate_chatgpt_prompt(Arena *arena, GameState *gs, Entity *e, CanTalkT
}
}
}
}
# undef HUMAN
# undef HUMAN
# undef AddFmt
return current_list ;
}
// outputs json which is parsed by the server
String8 generate_chatgpt_prompt ( Arena * arena , GameState * gs , Entity * e , CanTalkTo can_talk_to )
{
assert ( e - > is_npc ) ;
assert ( e - > npc_kind < ARRLEN ( characters ) ) ;
ArenaTemp scratch = GetScratch ( & arena , 1 ) ;
String8List list = { 0 } ;
PushWithLint ( scratch . arena , & list , " [ " ) ;
# define AddFmt(...) PushWithLint(scratch.arena, ¤t_list, __VA_ARGS__)
# define AddNewNode(node_type) { S8ListPush(scratch.arena, &list, make_json_node(scratch.arena, node_type, S8ListJoin(scratch.arena, current_list, &(StringJoin){0}))); current_list = (String8List){0}; }
// make first system node
{
String8List current_list = { 0 } ;
AddFmt ( " %s \n \n " , global_prompt ) ;
AddFmt ( " %s \n \n " , characters [ e - > npc_kind ] . prompt ) ;
AddFmt ( " The characters who are near you, that you can target: \n " ) ;
BUFF_ITER ( Entity * , & can_talk_to )
{
assert ( ( * it ) - > is_npc ) ;
String8 info = S8Lit ( " " ) ;
if ( ( * it ) - > killed )
{
info = S8Lit ( " - they're currently dead, they were murdered " ) ;
}
AddFmt ( " %s%.*s \n " , characters [ ( * it ) - > npc_kind ] . name , S8VArg ( info ) ) ;
}
AddFmt ( " \n " ) ;
// @TODO unhardcode this, this will be a description of where the character is right now
//AddFmt("You're currently standing in Daniel's farm's barn, a run-down structure that barely serves its purpose. Daniel's mighty protective of it though.\n");
AddFmt ( " You and everybody you're talking to is in a small sparse forest near Daniel's farm. There are some mysterious mechanical parts strewn about on the floor that Daniel seems relunctant and fearful to talk about. \n " ) ;
AddFmt ( " \n " ) ;
AddFmt ( " The actions you can perform, what they do, and the arguments they expect: \n " ) ;
AvailableActions can_perform ;
fill_available_actions ( gs , e , & can_perform ) ;
BUFF_ITER ( ActionKind , & can_perform )
{
AddFmt ( " %s - %s - %s \n " , actions [ * it ] . name , actions [ * it ] . description , actions [ * it ] . argument_description ) ;
}
AddNewNode ( MSG_SYSTEM ) ;
}
String8List current_list = { 0 } ;
bool in_drama_memories = true ;
assert ( e - > memories_first - > context . drama_memory ) ;
for ( Memory * it = e - > memories_first ; it ; it = it - > next )
{
// going through memories, I'm going to accumulate human understandable sentences for what happened in current_list.
// when I see an 'i_said_this' memory, that means I flush. and add a new assistant node.
// write a new human understandable sentence or two to current_list
if ( ! it - > context . i_said_this ) {
if ( in_drama_memories & & ! it - > context . drama_memory )
{
in_drama_memories = false ;
AddFmt ( " Some time passed... \n " ) ;
}
String8List desc_list = memory_description ( scratch . arena , e , it ) ;
S8ListConcat ( & current_list , & desc_list ) ;
}
}
// if I said this, or it's the last memory, flush the current list as a user node
// if I said this, or it's the last memory, flush the current list as a user node