{"id":439,"date":"2023-10-22T22:31:14","date_gmt":"2023-10-22T14:31:14","guid":{"rendered":"http:\/\/blog.cyasylum.top\/?p=439"},"modified":"2023-11-05T16:19:06","modified_gmt":"2023-11-05T08:19:06","slug":"unitychattychan-1bzt1f","status":"publish","type":"post","link":"http:\/\/blog.cyasylum.top\/index.php\/2023\/10\/22\/unitychattychan-1bzt1f\/","title":{"rendered":"ChattyChan &#8211; Unity \u4e2d\u4f7f\u7528 OpenAI FunctionCall \u5c0f\u4f8b"},"content":{"rendered":"<h1>UnityChattyChan<\/h1>\n<p>\u200d<\/p>\n<\/p>\n<p><a href=\"https:\/\/github.com\/syan2018\/UnityChattyChan\" target=\"_blank\"  rel=\"nofollow\" >syan2018\/UnityChattyChan: An example of driving character dialogue and expressions through the function call feature of the OpenAI ChatGPT API, invoked via Unity (github.com)<\/a><\/p>\n<p>\u5199\u4e86\u4e00\u4e2a\u73a9\u5177\u4ed3\u5e93\uff0c\u63d0\u4f9b\u4e00\u4e2a\u4f7f\u7528Function Call\u529f\u80fd\u7a33\u5b9a\u9a71\u52a8Chatbot\u52a8\u753b\u8868\u73b0\u7684\u6837\u4f8b<\/p>\n<p>\u96be\u5f97\u60f3\u53c2\u52a0\u4e00\u6b21GameJam\uff0c\u559c\u63d0\u4e09\u9633\uff0c\u505a\u4e86\u4e00\u70b9\u901a\u7528\u811a\u624b\u67b6\u5c31\u5352\u4e86\uff08\u60b2<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/kodo.cyasylum.top\/siyuan\/202311041031845.png\" alt=\"image\" \/>\u200b<\/p>\n<p>An example of driving character dialogue and expressions through the function call feature of the OpenAI ChatGPT API, invoked via Unity<\/p>\n<p>\u5c1d\u8bd5\u5728 Unity \u4e2d\u4f7f\u7528 OpenAI API \u7684 function call \u529f\u80fd\uff0c\u63d0\u4f9b\u4e00\u4e2a\u9a71\u52a8 ChatBot \u5bf9\u8bdd\u548c\u5c55\u793a\u8868\u60c5\u7684\u7b80\u5355\u5b9e\u4f8b\u3002\u662f\u6b3e GameJam \u53bb\u4e16\u4f5c\u54c1\u4e2d\u7684\u6a21\u5757\u3002<\/p>\n<p>\u539f\u59cb\u8bf7\u6c42\u5b9e\u73b0\u53c2\u8003 <a href=\"https:\/\/github.com\/zhangliwei7758\/unity-AI-Chat-Toolkit\" target=\"_blank\"  rel=\"nofollow\" >zhangliwei7758\/unity-AI-Chat-Toolkit: \u4f7f\u7528unity\u5b9e\u73b0AI\u804a\u5929\u76f8\u5173\u529f\u80fd (github.com)<\/a><\/p>\n<p>\u4e3b\u8981\u5728\u5176 ChatGPT \u6a21\u5757\u57fa\u7840\u4e0a\u8ffd\u52a0\u5f00\u53d1 function call \u76f8\u5173\u529f\u80fd<\/p>\n<h1>\u5b9e\u73b0\u901f\u89c8<\/h1>\n<p>\u5b9a\u4e49\u4e86\u90e8\u5206\u7ed3\u6784\u4f53\u7528\u4e8e\u521b\u5efa\u548c\u56de\u8c03 GPTFunction<\/p>\n<p>\u4e00\u4e2a\u521b\u5efa\u663e\u793a\u5bf9\u8bdd\u548c\u8868\u60c5\u7684 GPTFunction \u6837\u4f8b\u5982\u4e0b\uff08\u8be6\u60c5\u89c1\u5b8c\u6574\u5de5\u7a0b\uff09<\/p>\n<pre><code class=\"language-bash\">private void InitSpeechAndExpressionFunc()\n{\n    \/\/ \u5b9a\u4e49\u53c2\u6570\n    var expressionParameters = new GPTFunctionParameters\n    {\n        type = &quot;object&quot;,\n        properties = new Dictionary&lt;string, GPTFunctionParameterProperties&gt;\n        {\n            {\n                \/\/ \u5b9a\u4e49\u5bf9\u8bdd\u5185\u5bb9\n                &quot;speech&quot;, new GPTFunctionParameterProperties\n                {\n                    type = &quot;string&quot;,\n                    description = &quot;Output the dialogue content to this parameter&quot;\n                }\n            },\n            {\n                \/\/ \u5b9a\u4e49\u53c2\u6570\u8868\u60c5\n                &quot;expression&quot;, new GPTFunctionParameterProperties\n                {\n                    type = &quot;string&quot;,\n                    description = &quot;Choose the expression to use, default to Idle&quot;,\n                    Enum = Expressions\n                }\n            },\n        },\n        required = new List&lt;string&gt; { &quot;speech&quot; }\n    };\n\n    \/\/ \u5b9a\u4e49Function\n    var expressionFunction = new GPTFunction(\n        _name: &quot;talk_with_expression&quot;,\n        _description: &quot;When not invoking other Func, please use this Func to create dialogues with expressions&quot;,\n        _parameters: expressionParameters,\n        _callback: SpeechAndExpressionCallback\n    );\n\n    Functions[FuncTypes.Normal].Add(expressionFunction);\n}\n<\/code><\/pre>\n<h1>\u8868\u60c5\u5dee\u5206\u6548\u679c\u5c55\u793a<\/h1>\n<p>\u200b<img decoding=\"async\" src=\"http:\/\/kodo.cyasylum.top\/siyuan\/202311041031114.png\" alt=\"image\" \/><\/p>\n<p>\uff08\u867d\u7136ChattyChan\u5e76\u4e0d\u662f\u732b\u5a18\uff09<\/p>\n<p>\u200b<img decoding=\"async\" src=\"http:\/\/kodo.cyasylum.top\/siyuan\/202311041031488.png\" alt=\"image\" \/><\/p>\n<p>\uff08\u6709\u5149\u73af\uff0c\u4f0a\u7ec7\u4ee3\u4e86\uff0c\u563f\u563f\uff09<\/p>\n<p>\u200d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>UnityChattyChan \u200d syan2018\/UnityChattyChan: An example of driving &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-439","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/posts\/439","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/comments?post=439"}],"version-history":[{"count":4,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/posts\/439\/revisions"}],"predecessor-version":[{"id":463,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/posts\/439\/revisions\/463"}],"wp:attachment":[{"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/media?parent=439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/categories?post=439"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.cyasylum.top\/index.php\/wp-json\/wp\/v2\/tags?post=439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}