描述
Somnium 是一款以魔法为核心的 Minecraft 模组,其游戏机制和代码逻辑均在运行时动态生成。这是通过一个智能体链框架(一系列顺序调用的 LLM)实现的,其输入和输出受到预存应用程序接口的约束。
免责声明:即使物品有特定的描述,也不意味着它们一定会执行描述中所述的功能。目前仅官方支持单人游戏。
问题可以在 Github 或 Discord 上提交。
玩法(截至当前版本)
在山羊角被用于在正确的位置进行仪式时,可以启动仪式。燃烧某些物品也可能产生效果。其他会发生什么则尚不明确。
硬件要求
为了让 LLM 不至于花费极其漫长的时间来处理,建议使用至少拥有 8GB VRAM 的 GPU。或者,建议至少拥有 16GB RAM。
模型总共需要 16.11 GB 的存储空间。
安装
模组需要在主机上运行 Ollama 服务(使用默认配置时)。要下载 Ollama,请访问官方 网站。安装 Ollama 后,需要安装以下三个模型:
- qwen2.5vl:7b
- ALIENTELLIGENCE/gamemasterroleplaying:latest
- qwen3:8b
- snowflake-arctic-embed:110m
可以通过运行 ollama pull <model name> 来安装模型。要检查 GPU 驱动程序是否正确设置以及 Ollama 能否利用它们,请运行任意模型 ollama run <model name>,并在单独的 CLI 实例中运行 ollama ps。如果可以使用 GPU,它应显示该模型正在完全或部分于 GPU 上运行。更多详情请查看 Ollama FAQ。
如果一切设置正确,加入世界时聊天栏中应发送消息 Ollama server is online!。
技术细节
如果你希望在尝试之前不知道模组的精确机制,请将此视为剧透警告。
模组的事件处理器监听玩家的一些活动,这些活动作为仪式的触发器。截至目前,这些活动包括:
当执行上述任何操作时,由 4 个 LLM 组成的智能体链将被用来生成所需的结果。这 4 个 LLM 分类如下:
- 描述模型 (Descriptor Model)
- 过滤模型 (Filter Model)
- 上下文生成模型 (Context Generation Model)
- 编码模型 (Coder Model)
过程遵循以下步骤:
- 渲染数据 + 初始提示词由描述模型处理,生成图像的自然语言描述
- 生成的描述 + 初始提示词由过滤模型处理,其任务是确定环境是否相关。在这种情况下,相关的环境是指玩家似乎处于某种类似于神庙的结构中。
- 如果描述是相关的,则将玩家活动日志(玩家最近烧毁了哪些物品)附加并提示给上下文生成器。该模型充当游戏主持人,负责决定游戏的叙事。它生成包含游戏中应该发生什么的描述的响应。
- 编码模型的任务是使用预定义的 API 将生成的描述最好地实现为代码。
Python 代码、解释与链接
在 Ollama 托管的代码生成器完成后,代码需要在服务器上运行。这基本上等同于从远程位置执行任意代码。即使没有恶意参与者参与,接收到的代码也是由 LLM 生成的,因此通常不应信任。为了缓解这个问题,选择了一个尽可能简单的代码解释器的决定。这使得情况有所改善,因为代码解释器可以设置为只能访问原始代码库中的一组特定函数。剩下的唯一问题是应该解释哪种语言。
尽管 Minecraft 是用 Java 编写的,但选择了 Python 作为 LLM 必须生成以实现游戏功能的语言。这样做的原因如下:
- 语法轻量,使得编写解释器更容易
- Python 代码在互联网上比其他编程语言更常见,使其在使用于 LLM 的数据集中具有较大的影响力。
- 它不是强类型的,因此 LLM 犯错的可能性较低
模组中包含的 Python 解释器仅具备以下功能:
- 运算符
- 变量
- 函数
- 循环
- if 语句
- 三元运算符
- lambda 表达式
- 列表
- 元组
为了使被解释的 Python 代码能够调用 Java 方法,添加了一个函数链接功能。这允许将 Python 函数调用和参数路由到预定义的 Java 方法,其中 Java 方法的返回值也会路由回 Python 代码的返回值。一组属于解释器的函数默认被链接(例如函数 print 的实现)。属于模组功能的其他函数(创建效果、物品、治疗实体等)通过用 @PythonMethodLink 注解静态方法来链接。该注解还接受一个 docs 参数,其中应保存函数的文档。这份文档很重要,因为它会被提示给编码模型。
Description
Somnium is a magic focused Minecraft mod in which game mechanics and code logic is generated dynamically at runtime. This is performed by using a chain of agents framework (a series of sequential LLMs) where its input and output is constrained by a preexisting application interface.
Disclaimer: Even if items have a certain description it does not mean that they do what the description says it does. Only singleplayer is officially supported for now.
Issues can either be posted on Github or on Discord.
Gameplay (as of current version)
A Goat Horn can be used to initiate a ritual if it is done in the right place. Burning items may also do something. What else happens is unknown.
Hardware Requirements
In order for the LLMs to not take an excruciatingly long time to process a GPU with at least 8GB of VRAM is recommended. Alternatively at least 16GB of RAM is recommended.
The models require a total of 16.11 GB of storage.
Installation
The mod requires an Ollama service to be running on the host machine (when using a default configuration). In order to download Ollama check the official website. After installing Ollama the following three models need to be installed
- qwen2.5vl:7b
- ALIENTELLIGENCE/gamemasterroleplaying:latest
- qwen3:8b
- snowflake-arctic-embed:110m
A model can be installed by running ollama pull <model name>. To check if GPU drivers are set up correctly and Ollama can make use of them, run any model using ollama run <model name> and in a separate CLI instance run ollama ps. If the GPU can be used it should show that the model is running either fully or partially on the GPU. For more details check the Ollama FAQ.
If everything was set up correctly the message Ollama server is online! should be sent in the chat when joining a world.
Technical Details
If you wish to not know the exact mechanisms of the mod before you try it consider this a spoiler warning.
The mod's event handler is listening for certain activities of the player that act as triggers for a ritual. As of now these activities include:
When any of the above actions are performed a chain of agents composed of 4 LLMs is used to generate the required outcome. The 4 LLMs are classified as:
- Descriptor Model
- Filter Model
- Context Generation Model
- Coder Model
The process takes the following steps
- Render data + a priming prompt is processed by the descriptor model generating a natural language description of the image
- The generated description + a priming prompt is processed by the filter model which is tasked to determine if the environment is relevant. In this case a relevant environment is whether the player seems to be in a structure resembling a temple of sorts.
- If the description is relevant then a log of player activities (what items the player has burned recently) is attached and prompted to the context generator. This model acts as the game master, it being in charge of determining the narrative of game. It generates responses containing descriptions of what should happen in the game.
- The coder model is tasked to best implement the generate descriptions into code, using a predefined API.
Python Code, Interpretation & Linking
After the Ollama hosted code generator is done, the code needs to be ran on the server. This basically amounts to arbitrary code execution from a remote location. Even if there is no bad actor involved, the received code is generated by an LLM, so it should generally not be trusted. In order to ameliorate this issue the decision for an, as simple as possible, code interpreter was chosen. This makes the situation better since the code interpreter can be set up to only have access to a certain set of functions that it can call from the original code base. The only question left is what language should be interpreted.
Even if Minecraft is coded in java, python was chosen to be the language that the LLMs have to generate in order to implement features in the game. This was done for the following reasons:
- Light syntax making it easier to code the interpreter
- Python code is more common on the internet than other programming languages, making it have a large footprint in the datasets that were used for the LLMs.
- It is not strongly typed, thus there is a lower chance for the LLM to make a mistake
The Python interpreter that is part of the mod only has the following features coded in
- operators
- variables
- functions
- loops
- if statements
- ternary operators
- lambda expressions
- lists
- tuples
In order for the interpreted Python code to be able to call Java methods, a function linking feature was added. This allows for Python function calls and parameters to be routed to pre-defined Java methods, where the return value of the Java method is also routed back to the return value of the Python code. A set of functions that are part of the interpreter are linked by default (such as the implementation for the function print). Additional functions that are part of the mod's functionality (creating effects, items, healing entities etc) are linked by annotating static methods with @PythonMethodLink. This annotation also takes in a docs parameter which should hold the documentation of the functon. This documentation is important as that is what is prompted to the coder model.
评论 0
登录后参与评分
还没有评论,来抢沙发吧