evennia.contrib.rpg.llm.llm_npc

Basic class for NPC that makes use of an LLM (Large Language Model) to generate replies.

It comes with a talk command; use talk npc <something> to talk to the NPC. The NPC will respond using the LLM response.

Makes use of the LLMClient for communicating with the server. The NPC will also echo a ‘thinking…’ message if the LLM server takes too long to respond.

class evennia.contrib.rpg.llm.llm_npc.LLMNPC(*args, **kwargs)[source]

Bases: evennia.objects.objects.DefaultCharacter

An NPC that uses the LLM server to generate its responses. If the server is slow, it will echo a thinking message to the character while it waits for a response.

prompt_prefix = None
response_template

AttributeProperty.

thinking_timeout

AttributeProperty.

thinking_messages

AttributeProperty.

max_chat_memory_size

AttributeProperty.

chat_memory

AttributeProperty.

property llm_client
property llm_prompt_prefix

get prefix, first from Attribute, then from class variable, then from settings, then from default

build_prompt(character, speech)[source]

Build the prompt to send to the LLM server.

Parameters
  • character (Object) – The one talking to the NPC.

  • speech (str) – The latest speech from the character.

Returns

str – The prompt to return.

at_talked_to(speech, character)[source]

Called when this NPC is talked to by a character.

exception DoesNotExist

Bases: evennia.objects.objects.DefaultCharacter.DoesNotExist

exception MultipleObjectsReturned

Bases: evennia.objects.objects.DefaultCharacter.MultipleObjectsReturned

path = 'evennia.contrib.rpg.llm.llm_npc.LLMNPC'
typename = 'LLMNPC'
class evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk(**kwargs)[source]

Bases: evennia.commands.command.Command

Talk to an NPC

Usage:

talk npc <something> talk npc with spaces in name = <something>

key = 'talk'
parse()[source]

Once the cmdhandler has identified this as the command we want, this function is run. If many of your commands have a similar syntax (for example ‘cmd arg1 = arg2’) you should simply define this once and just let other commands of the same form inherit from this. See the docstring of this module for which object properties are available to use (notably self.args).

func()[source]

This is the actual executing part of the command. It is called directly after self.parse(). See the docstring of this module for which object properties are available (beyond those set in self.parse())

aliases = []
help_category = 'general'
lock_storage = 'cmd:all();'
search_index_entry = {'aliases': '', 'category': 'general', 'key': 'talk', 'no_prefix': ' ', 'tags': '', 'text': '\n Talk to an NPC\n\n Usage:\n talk npc <something>\n talk npc with spaces in name = <something>\n\n '}