evennia/docs/2.x/api/evennia.contrib.rpg.llm.llm_npc.html
Evennia docbuilder action e535f5782a Updated HTML docs.
2023-10-19 20:22:27 +00:00

318 lines
No EOL
19 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>evennia.contrib.rpg.llm.llm_npc &#8212; Evennia 2.x documentation</title>
<link rel="stylesheet" href="../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<link rel="shortcut icon" href="../_static/favicon.ico"/>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="evennia.contrib.rpg.llm.tests" href="evennia.contrib.rpg.llm.tests.html" />
<link rel="prev" title="evennia.contrib.rpg.llm.llm_client" href="evennia.contrib.rpg.llm.llm_client.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="evennia.contrib.rpg.llm.tests.html" title="evennia.contrib.rpg.llm.tests"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="evennia.contrib.rpg.llm.llm_client.html" title="evennia.contrib.rpg.llm.llm_client"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../Evennia-API.html" >API Summary</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="evennia-api.html" >evennia</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="evennia.html" >evennia</a> &#187;</li>
<li class="nav-item nav-item-4"><a href="evennia.contrib.html" >evennia.contrib</a> &#187;</li>
<li class="nav-item nav-item-5"><a href="evennia.contrib.rpg.html" >evennia.contrib.rpg</a> &#187;</li>
<li class="nav-item nav-item-6"><a href="evennia.contrib.rpg.llm.html" accesskey="U">evennia.contrib.rpg.llm</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">evennia.contrib.rpg.llm.llm_npc</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../index.html">
<img class="logo" src="../_static/evennia_logo.png" alt="Logo"/>
</a></p>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
<h4>Previous topic</h4>
<p class="topless"><a href="evennia.contrib.rpg.llm.llm_client.html"
title="previous chapter">evennia.contrib.rpg.llm.llm_client</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="evennia.contrib.rpg.llm.tests.html"
title="next chapter">evennia.contrib.rpg.llm.tests</a></p>
<div role="note" aria-label="source link">
<!--h3>This Page</h3-->
<ul class="this-page-menu">
<li><a href="../_sources/api/evennia.contrib.rpg.llm.llm_npc.md.txt"
rel="nofollow">Show Page Source</a></li>
</ul>
</div><h3>Links</h3>
<ul>
<li><a href="https://www.evennia.com/docs/latest/index.html">Documentation Top</a> </li>
<li><a href="https://www.evennia.com">Evennia Home</a> </li>
<li><a href="https://github.com/evennia/evennia">Github</a> </li>
<li><a href="http://games.evennia.com">Game Index</a> </li>
<li>
<a href="https://discord.gg/AJJpcRUhtF">Discord</a> -
<a href="https://github.com/evennia/evennia/discussions">Discussions</a> -
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Doc Versions</h3>
<ul>
<li><a href="evennia.contrib.rpg.llm.llm_npc.html">2.x (main branch)</a></li>
<ul>
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 branch)</a></li>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
<div class="body" role="main">
<section id="module-evennia.contrib.rpg.llm.llm_npc">
<span id="evennia-contrib-rpg-llm-llm-npc"></span><h1>evennia.contrib.rpg.llm.llm_npc<a class="headerlink" href="#module-evennia.contrib.rpg.llm.llm_npc" title="Permalink to this headline"></a></h1>
<p>Basic class for NPC that makes use of an LLM (Large Language Model) to generate replies.</p>
<p>It comes with a <strong>talk</strong> command; use <strong>talk npc &lt;something&gt;</strong> to talk to the NPC. The NPC will
respond using the LLM response.</p>
<p>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.</p>
<dl class="py class">
<dt id="evennia.contrib.rpg.llm.llm_npc.LLMNPC">
<em class="property">class </em><code class="sig-prename descclassname">evennia.contrib.rpg.llm.llm_npc.</code><code class="sig-name descname">LLMNPC</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">*</span><span class="n">args</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/rpg/llm/llm_npc.html#LLMNPC"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.LLMNPC" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="evennia.objects.objects.html#evennia.objects.objects.DefaultCharacter" title="evennia.objects.objects.DefaultCharacter"><code class="xref py py-class docutils literal notranslate"><span class="pre">evennia.objects.objects.DefaultCharacter</span></code></a></p>
<p>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.</p>
<dl class="py attribute">
<dt id="evennia.contrib.rpg.llm.llm_npc.LLMNPC.prompt_prefix">
<code class="sig-name descname">prompt_prefix</code><em class="property"> = None</em><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.LLMNPC.prompt_prefix" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py attribute">
<dt id="evennia.contrib.rpg.llm.llm_npc.LLMNPC.response_template">
<code class="sig-name descname">response_template</code><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.LLMNPC.response_template" title="Permalink to this definition"></a></dt>
<dd><p>AttributeProperty.</p>
</dd></dl>
<dl class="py attribute">
<dt id="evennia.contrib.rpg.llm.llm_npc.LLMNPC.thinking_timeout">
<code class="sig-name descname">thinking_timeout</code><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.LLMNPC.thinking_timeout" title="Permalink to this definition"></a></dt>
<dd><p>AttributeProperty.</p>
</dd></dl>
<dl class="py attribute">
<dt id="evennia.contrib.rpg.llm.llm_npc.LLMNPC.thinking_messages">
<code class="sig-name descname">thinking_messages</code><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.LLMNPC.thinking_messages" title="Permalink to this definition"></a></dt>
<dd><p>AttributeProperty.</p>
</dd></dl>
<dl class="py attribute">
<dt id="evennia.contrib.rpg.llm.llm_npc.LLMNPC.max_chat_memory_size">
<code class="sig-name descname">max_chat_memory_size</code><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.LLMNPC.max_chat_memory_size" title="Permalink to this definition"></a></dt>
<dd><p>AttributeProperty.</p>
</dd></dl>
<dl class="py attribute">
<dt id="evennia.contrib.rpg.llm.llm_npc.LLMNPC.chat_memory">
<code class="sig-name descname">chat_memory</code><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.LLMNPC.chat_memory" title="Permalink to this definition"></a></dt>
<dd><p>AttributeProperty.</p>
</dd></dl>
<dl class="py method">
<dt id="evennia.contrib.rpg.llm.llm_npc.LLMNPC.llm_client">
<em class="property">property </em><code class="sig-name descname">llm_client</code><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.LLMNPC.llm_client" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="evennia.contrib.rpg.llm.llm_npc.LLMNPC.llm_prompt_prefix">
<em class="property">property </em><code class="sig-name descname">llm_prompt_prefix</code><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.LLMNPC.llm_prompt_prefix" title="Permalink to this definition"></a></dt>
<dd><p>get prefix, first from Attribute, then from class variable,
then from settings, then from default</p>
</dd></dl>
<dl class="py method">
<dt id="evennia.contrib.rpg.llm.llm_npc.LLMNPC.build_prompt">
<code class="sig-name descname">build_prompt</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">character</span></em>, <em class="sig-param"><span class="n">speech</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/rpg/llm/llm_npc.html#LLMNPC.build_prompt"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.LLMNPC.build_prompt" title="Permalink to this definition"></a></dt>
<dd><p>Build the prompt to send to the LLM server.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>character</strong> (<em>Object</em>) The one talking to the NPC.</p></li>
<li><p><strong>speech</strong> (<em>str</em>) The latest speech from the character.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><em>str</em> The prompt to return.</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="evennia.contrib.rpg.llm.llm_npc.LLMNPC.at_talked_to">
<code class="sig-name descname">at_talked_to</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">speech</span></em>, <em class="sig-param"><span class="n">character</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/rpg/llm/llm_npc.html#LLMNPC.at_talked_to"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.LLMNPC.at_talked_to" title="Permalink to this definition"></a></dt>
<dd><p>Called when this NPC is talked to by a character.</p>
</dd></dl>
<dl class="py exception">
<dt id="evennia.contrib.rpg.llm.llm_npc.LLMNPC.DoesNotExist">
<em class="property">exception </em><code class="sig-name descname">DoesNotExist</code><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.LLMNPC.DoesNotExist" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="evennia.objects.objects.html#evennia.objects.objects.DefaultCharacter.DoesNotExist" title="evennia.objects.objects.DefaultCharacter.DoesNotExist"><code class="xref py py-class docutils literal notranslate"><span class="pre">evennia.objects.objects.DefaultCharacter.DoesNotExist</span></code></a></p>
</dd></dl>
<dl class="py exception">
<dt id="evennia.contrib.rpg.llm.llm_npc.LLMNPC.MultipleObjectsReturned">
<em class="property">exception </em><code class="sig-name descname">MultipleObjectsReturned</code><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.LLMNPC.MultipleObjectsReturned" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="evennia.objects.objects.html#evennia.objects.objects.DefaultCharacter.MultipleObjectsReturned" title="evennia.objects.objects.DefaultCharacter.MultipleObjectsReturned"><code class="xref py py-class docutils literal notranslate"><span class="pre">evennia.objects.objects.DefaultCharacter.MultipleObjectsReturned</span></code></a></p>
</dd></dl>
<dl class="py attribute">
<dt id="evennia.contrib.rpg.llm.llm_npc.LLMNPC.path">
<code class="sig-name descname">path</code><em class="property"> = 'evennia.contrib.rpg.llm.llm_npc.LLMNPC'</em><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.LLMNPC.path" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py attribute">
<dt id="evennia.contrib.rpg.llm.llm_npc.LLMNPC.typename">
<code class="sig-name descname">typename</code><em class="property"> = 'LLMNPC'</em><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.LLMNPC.typename" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="py class">
<dt id="evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk">
<em class="property">class </em><code class="sig-prename descclassname">evennia.contrib.rpg.llm.llm_npc.</code><code class="sig-name descname">CmdLLMTalk</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/rpg/llm/llm_npc.html#CmdLLMTalk"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="evennia.commands.command.html#evennia.commands.command.Command" title="evennia.commands.command.Command"><code class="xref py py-class docutils literal notranslate"><span class="pre">evennia.commands.command.Command</span></code></a></p>
<p>Talk to an NPC</p>
<dl class="simple">
<dt>Usage:</dt><dd><p>talk npc &lt;something&gt;
talk npc with spaces in name = &lt;something&gt;</p>
</dd>
</dl>
<dl class="py attribute">
<dt id="evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk.key">
<code class="sig-name descname">key</code><em class="property"> = 'talk'</em><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk.key" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk.parse">
<code class="sig-name descname">parse</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/rpg/llm/llm_npc.html#CmdLLMTalk.parse"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk.parse" title="Permalink to this definition"></a></dt>
<dd><p>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).</p>
</dd></dl>
<dl class="py method">
<dt id="evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk.func">
<code class="sig-name descname">func</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/rpg/llm/llm_npc.html#CmdLLMTalk.func"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk.func" title="Permalink to this definition"></a></dt>
<dd><p>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())</p>
</dd></dl>
<dl class="py attribute">
<dt id="evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk.aliases">
<code class="sig-name descname">aliases</code><em class="property"> = []</em><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk.aliases" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py attribute">
<dt id="evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk.help_category">
<code class="sig-name descname">help_category</code><em class="property"> = 'general'</em><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk.help_category" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py attribute">
<dt id="evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk.lock_storage">
<code class="sig-name descname">lock_storage</code><em class="property"> = 'cmd:all();'</em><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk.lock_storage" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py attribute">
<dt id="evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk.search_index_entry">
<code class="sig-name descname">search_index_entry</code><em class="property"> = {'aliases': '', 'category': 'general', 'key': 'talk', 'no_prefix': ' ', 'tags': '', 'text': '\n Talk to an NPC\n\n Usage:\n talk npc &lt;something&gt;\n talk npc with spaces in name = &lt;something&gt;\n\n '}</em><a class="headerlink" href="#evennia.contrib.rpg.llm.llm_npc.CmdLLMTalk.search_index_entry" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
</section>
</div>
</div>
</div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="evennia.contrib.rpg.llm.tests.html" title="evennia.contrib.rpg.llm.tests"
>next</a> |</li>
<li class="right" >
<a href="evennia.contrib.rpg.llm.llm_client.html" title="evennia.contrib.rpg.llm.llm_client"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 2.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../Evennia-API.html" >API Summary</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="evennia-api.html" >evennia</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="evennia.html" >evennia</a> &#187;</li>
<li class="nav-item nav-item-4"><a href="evennia.contrib.html" >evennia.contrib</a> &#187;</li>
<li class="nav-item nav-item-5"><a href="evennia.contrib.rpg.html" >evennia.contrib.rpg</a> &#187;</li>
<li class="nav-item nav-item-6"><a href="evennia.contrib.rpg.llm.html" >evennia.contrib.rpg.llm</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">evennia.contrib.rpg.llm.llm_npc</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
</div>
</body>
</html>