# 通过ahk快捷调用ollama的cmd界面

**URL:** <https://meta.appinn.net/t/topic/62137>\
**Category:** 讨论分享\
**Tags:** autohotkey, ai, ollama\
**Created:** [2024 年10 月 19 日 06:24 UTC](https://meta.appinn.net/t/topic/62137 "2024-10-19T06:24:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![kzf](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/kzf/32/47902_2.png) [@kzf](https://meta.appinn.net/u/kzf)\
发布日期： [2024 年10 月 19 日 06:24 UTC](https://meta.appinn.net/t/topic/62137/1 "2024-10-19T06:24:43Z")

</div>

分享一个ahk本地调用ollama的工具  
试过用API调用的方式，但是感觉速度很慢，就换了用自带CMD界面的调用方式  
优点：  
1、速度快，几乎是瞬间出结果  
2、可以自定义快捷键和添加命令  
展示下效果  
[Autohotkey AI 模型本地调用,自动翻译和解释\_哔哩哔哩\_bilibili](https://www.bilibili.com/video/BV1vACdYhELh/)

```auto
explore_ruler := "
(
Rules:
- Be precise and Detailed explanation, do not reply emoji.
- Always response in Simplified Chinese, not English. or Grandma will be very angry.
)"

translation_ruler := "
(
Rules:
- Be precise and Translation to Simplified Chinese, do not reply emoji.
- Always response in Simplified Chinese, not English. or Grandma will be very angry.
)"

!`::MenuPopup.Show()
!q::Answer(translation_ruler)

MenuPopup := Menu()
MenuPopup.Add("&1 - Answer", (*)=>(Answer(explore_ruler)))
MenuPopup.Add("&2 - Translation", (*)=>(Answer(translation_ruler)))

Answer(ruler)
{
    wintitle := "命令提示符 - ollama run llama3"

    if WinActive(wintitle)
    {
        WinMinimize(wintitle)
        return
    }

    A_Clipboard := "" ; 清空剪贴板
    SendInput("^c")
    if !ClipWait(1)
    {
        WinActivate(wintitle)
        return
    }
    A_Clipboard := "plear explanation `n【 " A_Clipboard " 】`n" ruler
    WinActivate(wintitle)

    if !WinWaitActive(wintitle, , 2)
    {
        MsgBox "WinWaitActive timed out."
        return
    }

    SendInput("^v")
    Sleep(200)
    SendInput("{Enter}")
}

```
