nonebot-plugin-marshoai/assets/dev_api_plugin_register.md.CWy7Efmw.js

11 lines
8.9 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{_ as i,c as a,o as n,ae as t}from"./chunks/framework.BHrE6nLq.js";const g=JSON.parse('{"title":"register","description":"","frontmatter":{"title":"register"},"headers":[],"relativePath":"dev/api/plugin/register.md","filePath":"zh/dev/api/plugin/register.md","lastUpdated":1734175019000}'),l={name:"dev/api/plugin/register.md"};function e(h,s,p,k,r,o){return n(),a("div",null,s[0]||(s[0]=[t(`<h1 id="模块-nonebot-plugin-marshoai-plugin-register" tabindex="-1"><strong>模块</strong> <code>nonebot_plugin_marshoai.plugin.register</code> <a class="header-anchor" href="#模块-nonebot-plugin-marshoai-plugin-register" aria-label="Permalink to &quot;**模块** \`nonebot_plugin_marshoai.plugin.register\`&quot;"></a></h1><p>此模块用于获取function call中函数定义信息以及注册函数</p><hr><h3 id="func-async-wrapper-func-sync-function-call-func-async-function-call-func" tabindex="-1"><em><strong>func</strong></em> <code>async_wrapper(func: SYNC_FUNCTION_CALL_FUNC) -&gt; ASYNC_FUNCTION_CALL_FUNC</code> <a class="header-anchor" href="#func-async-wrapper-func-sync-function-call-func-async-function-call-func" aria-label="Permalink to &quot;***func*** \`async_wrapper(func: SYNC_FUNCTION_CALL_FUNC) -&gt; ASYNC_FUNCTION_CALL_FUNC\`&quot;"></a></h3><p><strong>说明</strong>: 将同步函数包装为异步函数,但是不会真正异步执行,仅用于统一调用及函数签名</p><p><strong>参数</strong>:</p><blockquote><ul><li>func: 同步函数</li></ul></blockquote><p><strong>返回</strong>: ASYNC_FUNCTION_CALL: 异步函数</p><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/plugin/register.py#L20" target="_blank">在GitHub上查看</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> async_wrapper</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(func: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">SYNC_FUNCTION_CALL_FUNC</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) -&gt; </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">ASYNC_FUNCTION_CALL_FUNC</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> async</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> wrapper</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">args, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">**</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">kwargs) -&gt; </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">str</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> func(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">args, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">**</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">kwargs)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> wrapper</span></span></code></pre></div></details><hr><h3 id="func-function-call-funcs-function-call-func-none" tabindex="-1"><em><strong>func</strong></em> <code>function_call(*funcs: FUNCTION_CALL_FUNC) -&gt; None</code> <a class="header-anchor" href="#func-function-call-funcs-function-call-func-none" aria-label="Permalink to &quot;***func*** \`function_call(*funcs: FUNCTION_CALL_FUNC) -&gt; None\`&quot;"></a></h3><p><strong>参数</strong>:</p><blockquote><ul><li>func: 函数对象,要有完整的 Google Style Docstring</li></ul></blockquote><p><strong>返回</strong>: str: 函数定义信息</p><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/plugin/register.py#L36" target="_blank">在GitHub上查看</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> function_call</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">funcs: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">FUNCTION_CALL_FUNC</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) -&gt; </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">None</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> func </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> funcs:</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> function_call </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> get_function_info(func)</span></span></code></pre></div></details><hr><h3 id="func-get-function-info-func-function-call-func" tabindex="-1"><em><strong>func</strong></em> <code>get_function_info(func: FUNCTION_CALL_FUNC)</code> <a class="header-anchor" href="#func-get-function-info-func-function-call-func" aria-label="Permalink to &quot;***func*** \`get_function_info(func: FUNCTION_CALL_FUNC)\`&quot;"></a></h3><p><strong>说明</strong>: 获取函数信息</p><p><strong>参数</strong>:</p><blockquote><ul><li>func: 函数对象</li></ul></blockquote><p><strong>返回</strong>: FunctionCall: 函数信息对象模型</p><details><summary><b>源代码</b> 或 <a href="https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/plugin/register.py#L50" target="_blank">在GitHub上查看</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> get_function_info</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(func: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">FUNCTION_CALL_FUNC</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">):</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> name </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> func.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">__name__</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> description </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> func.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">__doc__</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> logger.info(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">f</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;注册函数: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">{</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">name</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">}</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> {</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">description</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">}</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre></div></details>`,22)]))}const u=i(l,[["render",e]]);export{g as __pageData,u as default};