Advertisement
zaq_hack

ComfyUI to Kobold (llm) custom node

Dec 21st, 2023 (edited)
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.06 KB | Source Code | 0 0
  1. # Change the URL on line 40 to wherever you host your Kobold API.
  2. class z_local_llm_text:
  3.    
  4.     def __init__(self):
  5.         pass
  6.    
  7.     @classmethod
  8.     def INPUT_TYPES(s):
  9.         return {
  10.             "required": {
  11.                 "llmQuery": ("STRING", {
  12.                     "default": "",
  13.                     "display": "text"
  14.                 }),
  15.                 "maxLength": ("INT", {
  16.                     "default": 100,
  17.                     "display": "number"
  18.                 }),
  19.                 "seed": ("INT", {
  20.                     # This is only included so that you can drive a new prompt in large batch workflows.
  21.                     # Hook up a seed to it, and every time the seed changes, it will re-request to the LLM.
  22.                     "default": 7331,
  23.                     "step": 1, #Slider's step
  24.                     "display": "number" # Cosmetic only: display as "number" or "slider"
  25.                 }),
  26.             },
  27.         }
  28.  
  29.     RETURN_TYPES = ("STRING",)
  30.    
  31.     RETURN_NAMES = ("LLM Response",)
  32.  
  33.     FUNCTION = "zllt"
  34.  
  35.     CATEGORY = "zaq_nodes"
  36.  
  37.     def zllt(self, llmQuery, maxLength, seed):
  38.         import requests, json, string
  39.         # This is not the default port. I have a 3060 and a 3090 in my ComfyUI box, so I used port 3060 for Kobold. Har har.
  40.         url = 'http://localhost:3060/api/v1/generate'
  41.         kobold = { "max_context_length": 2048, "max_length": maxLength, "prompt": llmQuery, "quiet": False, "rep_pen": 1.1, "rep_pen_range": 256, "rep_pen_slope": 1, "temperature": 0.5, "tfs": 1, "top_a": 0, "top_k": 100, "top_p": 0.9, "typical": 1, "seed": seed }
  42.         r2 = ""
  43.         while len(r2) < 5:
  44.             x1 = (requests.post(url, json=kobold))
  45.             x2 = x1.text
  46.             x3 = json.loads(x2)
  47.             x4 = x3["results"][0]
  48.             r1 = "" + x4["text"]
  49.             r2 = r1.strip()
  50.         return (r2,)
  51.  
  52. # NOTE: names should be globally unique
  53. NODE_CLASS_MAPPINGS = {
  54.     "z_local_llm_text": z_local_llm_text
  55. }
  56.  
  57. NODE_DISPLAY_NAME_MAPPINGS = {
  58.     "zllt": "z_local_llm_text"
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement