Advertisement
Zektrix1

Ollama API GUI

Sep 8th, 2024
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #Requires AutoHotkey v2.0
  2. #SingleInstance Force
  3.  
  4. OllamaGui := Gui(, "Ollama API")
  5. OllamaGui.Add("Text", "x10 y14 w60 h14", "Prompt")
  6. OllamaGui.Add("Text", "x100 y14 w200 h14", "Ctrl+Enter=New Line | Enter=Send")
  7. Prompt_Edit := OllamaGui.Add("Edit", "x10 y30 w420 h125 -WantReturn +Multi", "How does one go about shop until you drop?")
  8. OllamaGui.Add("Text", "x10 y164 w60 h14", "Response")
  9. Response_Edit := OllamaGui.Add("Edit", "x10 y180 w420 h175 +Multi")
  10. OllamaGui.Add("Text", "x10 y364 w60 h14", "Model")
  11. Model_Edit := OllamaGui.Add("Edit", "x10 y380 w130 h30 -vScroll r1", "dolphin-mistral:latest")
  12. OllamaGui.Add("Text", "x150 y364 w60 h14", "Context")
  13. Context_Edit := OllamaGui.Add("Edit", "x150 y380 w130 h30 -vScroll r1", "2000")
  14. OllamaGui.Add("Text", "x300 y364 w60 h14", "Temperature")
  15. Temperature_Edit := OllamaGui.Add("Edit", "x300 y380 w130 h30 -vScroll r1", "0.8")
  16. H_SendRequest := OllamaGui.AddButton("Default Hidden", "OK")
  17. H_SendRequest.OnEvent("Click", SendRequest)
  18. OllamaGui.Show("w440 h420")
  19.  
  20. SendRequest(*)
  21. {
  22. DATA := "
  23. (
  24. {
  25. "model": "Model_EditValueC",
  26. "prompt": "Prompt_EditValueC",
  27. "stream": false,
  28. "Options": {
  29. "temperature": "Temperature_EditValueC",
  30. "num_ctx": "Context_EditValueC"
  31. }
  32. }
  33. )"
  34. ; Is this the (Can't be) best way to variable the above like below, instead of making every escape?
  35. DATA := StrReplace(DATA, "`"Context_EditValueC`"", Context_Edit.Value)
  36. DATA := StrReplace(DATA, "`"Temperature_EditValueC`"", Temperature_Edit.Value)
  37. DATA := StrReplace(DATA, "`"Prompt_EditValueC`"", "`"" Prompt_Edit.Value "`"")
  38. DATA := StrReplace(DATA, "`"Model_EditValueC`"", "`"" Model_Edit.Value "`"")
  39. URL := "http://localhost:11434/api/generate"
  40. WinHttp := ComObject("WinHttp.WinHttpRequest.5.1")
  41. WinHttp.Open("POST", URL, True)
  42. WinHttp.SetRequestHeader("Content-Type", "application/json")
  43. WinHttp.Send(DATA)
  44. WinHttp.WaitForResponse
  45. DATA := WinHttp.ResponseText
  46. RegExMatch(DATA, "s)(?<=`",`"response`":`").*?(?=`",`"done`":true)", &Match)
  47. DATA := Match[0]
  48. DATA := StrReplace(DATA, "\`"", "`"")
  49. DATA := StrReplace(DATA, "\n", "`n")
  50. Response_Edit.Value := DATA
  51. }
  52.  
  53. Numpad2::
  54. {
  55. Reload
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement