branch: elpa/gptel commit 43c38bfd6973d6f55edf1ccc0f149252173de5f7 Author: Yikai Zhao <r...@blahgeek.com> Commit: GitHub <nore...@github.com>
README: Add Moonshot (kimi) instructions (#967) * README.org: Add configuration for Moonshot and its built-in search tool. --- README.org | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/README.org b/README.org index bec5645414..088189fb49 100644 --- a/README.org +++ b/README.org @@ -14,7 +14,7 @@ gptel is a simple Large Language Model chat client for Emacs, with support for m | Anthropic (Claude) | ✓ | [[https://www.anthropic.com/api][API key]] | | Gemini | ✓ | [[https://makersuite.google.com/app/apikey][API key]] | | Ollama | ✓ | [[https://ollama.ai/][Ollama running locally]] | -| Open WebUI | ✓ | [[https://openwebui.com/][Open WebUI running locally]] | +| Open WebUI | ✓ | [[https://openwebui.com/][Open WebUI running locally]] | | Llama.cpp | ✓ | [[https://github.com/ggml-org/llama.cpp/tree/master/tools/server#quick-start][Llama.cpp running locally]] | | Llamafile | ✓ | [[https://github.com/Mozilla-Ocho/llamafile#quickstart][Local Llamafile server]] | | GPT4All | ✓ | [[https://gpt4all.io/index.html][GPT4All running locally]] | @@ -37,6 +37,7 @@ gptel is a simple Large Language Model chat client for Emacs, with support for m | xAI | ✓ | [[https://console.x.ai?utm_source=github_gptel&utm_medium=github_readme&utm_campaign=link][API key]] | | Github CopilotChat | ✓ | Github account | | Bedrock | ✓ | AWS credentials | +| Moonshot (Kimi) | ✓ | API key ([[https://platform.moonshot.cn/console][CN]] or [[https://platform.moonshot.ai/console][Global]]) | #+html: </div> *General usage*: ([[https://www.youtube.com/watch?v=bsRnh_brggM][YouTube Demo]]) @@ -124,6 +125,7 @@ gptel uses Curl if available, but falls back to the built-in url-retrieve to wor - [[#aiml-api][AI/ML API]] - [[#github-copilotchat][Github CopilotChat]] - [[#aws-bedrock][AWS Bedrock]] + - [[#moonshot-kimi][Moonshot (Kimi)]] - [[#usage][Usage]] - [[#in-any-buffer][In any buffer:]] - [[#in-a-dedicated-chat-buffer][In a dedicated chat buffer:]] @@ -1085,6 +1087,53 @@ The above code makes the backend available to select. If you want it to be the #+html: </details> +#+html: <details><summary> +**** Moonshot (Kimi) +#+html: </summary> + +Register a backend with + +#+begin_src emacs-lisp +(gptel-make-openai "Moonshot" + :host "api.moonshot.cn" ;; or "api.moonshot.ai" for the global site + :key "your-api-key" + :stream t ;; optionally enable streaming + :models '(kimi-latest kimi-k2-0711-preview)) +#+end_src + +See [[https://platform.moonshot.ai/docs/pricing/chat][Moonshot.ai document]] for a complete list of models. + +***** (Optional) Use the builtin search tool + +Moonshot supports a builtin search tool that does not requires the user to provide the tool implementation. To use that, you first need to define the tool and add to =gptel-tools= (while it does not requires the client to provide the search implementation, it does expects the client to reply a tool call message with its given argument, to be consistent with other tool calls): + +#+begin_src emacs-lisp +(setq gptel-tools + (list (gptel-make-tool + :name "$web_search" + :function (lambda (&optional search_result) + (json-serialize + `(:search_result ,search_result))) + :description "Moonshot builtin web search. Only usable by moonshot model (kimi), ignore this if you are not." + :args '((:name "search_result" :type object :optional t)) + :category "web"))) +#+end_src + +Then you also need to add the tool declaration via =:request-params= because it needs a special =builtin_function= type: + +#+begin_src emacs-lisp +(gptel-make-openai "Moonshot" + :host "api.moonshot.cn" ;; or "api.moonshot.ai" for the global site + :key "your-api-key" + :stream t ;; optionally enable streaming + :models '(kimi-latest kimi-k2-0711-preview) + :request-params '(:tools [(:type "builtin_function" :function (:name "$web_search"))])) +#+end_src + +Now the chat should be able to automatically use search. Try "what's new today" and you should expect the up-to-date news in response. + +#+html: </details> + ** Usage gptel provides a few powerful, general purpose and flexible commands. You can dynamically tweak their behavior to the needs of your task with /directives/, redirection options and more. There is a [[https://www.youtube.com/watch?v=bsRnh_brggM][video demo]] showing various uses of gptel -- but =gptel-send= might be all you need.