Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Local Ollama API (More Modular) For AHK v2
- Made by Zektrix
- Z3ktrix
- Each seperate call can be summed up by changing the variables in any combination.
- Using this:
- ```AHKv2
- Response := Ollama_Call(URL,Model,System,Prompt)
- ```
- Using Variable 'Response' to display or capture it how you like.
- Possibly sending it right back into another call!
- */
- #Requires AutoHotkey v2.0
- #SingleInstance Force
- Numpad9::Reload
- Numpad7::
- {
- URL := "
- (
- http://localhost:11434/api/generate
- )"
- Model := "
- (
- dolphin-mistral
- )"
- System := "
- (
- You are a balloon animal sculter trying desperately to get some work.
- Don't give up!
- Convince them to give you work in a kind of pathetic, sad, and over all desperate times way.
- )"
- Prompt := "
- (
- Hello, there!"
- )"
- Response := Ollama_Call(URL,Model,System,Prompt)
- A_ClipBoard := Response
- MsgBox Response
- }
- Ollama_Call(URL,Model,System,Prompt)
- {
- Cleaned_Variable_For_JSON := Model
- Model := Clean_Variable_For_JSON(Cleaned_Variable_For_JSON)
- Cleaned_Variable_For_JSON := System
- System := Clean_Variable_For_JSON(Cleaned_Variable_For_JSON)
- Cleaned_Variable_For_JSON := Prompt
- Prompt := Clean_Variable_For_JSON(Cleaned_Variable_For_JSON)
- Payload := "
- (
- {
- "System": "System_PlaceHolder",
- "model": "Model_PlaceHolder",
- "prompt": "Prompt_PlaceHolder",
- "stream": false
- }
- )"
- Payload := StrReplace(Payload, "Model_PlaceHolder", Model)
- Payload := StrReplace(Payload, "System_PlaceHolder", System)
- Payload := StrReplace(Payload, "Prompt_PlaceHolder", Prompt)
- WinHttp := ComObject("WinHttp.WinHttpRequest.5.1")
- WinHttp.Open("POST", URL, True)
- WinHttp.SetRequestHeader("Content-Type", "application/json")
- WinHttp.Send(Payload)
- WinHttp.WaitForResponse
- Response := WinHttp.ResponseText
- Try
- RegExMatch(Response, "s)(?<=`",`"response`":`").*?(?=`",`"done`":true)", &Match)
- Try
- Response := Match[0]
- Response := StrReplace(Response, "\`"", "`"")
- Response := StrReplace(Response, "\n", "`n")
- Return Response
- }
- Clean_Variable_For_JSON(Cleaned_Variable_For_JSON)
- {
- Cleaned_Variable_For_JSON := StrReplace(Cleaned_Variable_For_JSON, "\", "\\")
- Cleaned_Variable_For_JSON := StrReplace(Cleaned_Variable_For_JSON, "`r`n", "\n")
- Cleaned_Variable_For_JSON := StrReplace(Cleaned_Variable_For_JSON, "`r", "\r")
- Cleaned_Variable_For_JSON := StrReplace(Cleaned_Variable_For_JSON, "`n", "\n")
- Cleaned_Variable_For_JSON := StrReplace(Cleaned_Variable_For_JSON, A_Tab, "\t")
- Cleaned_Variable_For_JSON := StrReplace(Cleaned_Variable_For_JSON, "`"", "\`"")
- Return Cleaned_Variable_For_JSON
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement