Fixed Bug with converting PositivePrompt Into an input and Enhanced API Key System
This commit is contained in:
@@ -4,12 +4,11 @@ class apiManager:
|
||||
return {
|
||||
"required": {
|
||||
"API Key": ("STRING", {
|
||||
"tooltip": "Set Your Runware API Key To Start Using Runware Image Inference Services.\n\n(eg: BcVr1JVQM8FGzrRwb3GsbCq5ww1QwabV)\n\nIf You Don't Have One, You Can Get It From: https://my.runware.ai/keys",
|
||||
"tooltip": "Set Your Runware API Key To Start Using Runware Image Inference Services.\n\n(e.g; BcVr1JVQM8FGzrRwb3GsbCq5ww1QwabV)\n\nIf You Don't Have One, You Can Get It From: https://my.runware.ai/keys",
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
DESCRIPTION = "API Managers is a Runware Utility That helps you set your API Key From The ComfyUI Interface Without having to adjust the env file locally."
|
||||
DESCRIPTION = "API Managers is a Runware Utility That helps you define or change your API Key From The ComfyUI Interface Without having to adjust the env file locally."
|
||||
CATEGORY = "Runware"
|
||||
RETURN_TYPES = ()
|
||||
OUTPUT_NODE = True
|
||||
RETURN_TYPES = ()
|
||||
@@ -9,9 +9,14 @@ async def setAPIKey(reqPayload):
|
||||
reqData = await reqPayload.json()
|
||||
apiKey = reqData.get('apiKey', None)
|
||||
if(apiKey is None or apiKey == "" or len(apiKey) < 30):
|
||||
return web.json_response({'success': False, 'error': 'API Key Not Provided!'})
|
||||
return web.json_response({'success': False, 'error': 'Invalid API Key!'})
|
||||
try:
|
||||
apiKey = apiKey.strip()
|
||||
apiCheckResult = rwUtils.checkAPIKey(apiKey)
|
||||
if(apiCheckResult == False):
|
||||
return web.json_response({'success': False, 'error': 'Failed To Set Your API Key, Please Try Again!'})
|
||||
elif(apiCheckResult != True):
|
||||
return web.json_response({'success': False, 'error': apiCheckResult})
|
||||
rwUtils.setAPIKey(apiKey)
|
||||
except Exception as e:
|
||||
return web.json_response({'success': False, 'error': str(e)})
|
||||
|
||||
@@ -125,7 +125,7 @@ class txt2img:
|
||||
|
||||
@classmethod
|
||||
def VALIDATE_INPUTS(cls, positivePrompt, negativePrompt):
|
||||
if (positivePrompt is None or len(positivePrompt) < 3 or len(positivePrompt) > 2000):
|
||||
if (positivePrompt is not None and (positivePrompt == "" or len(positivePrompt) < 3 or len(positivePrompt) > 2000)):
|
||||
raise Exception("Positive Prompt Must Be Between 3 And 2000 characters!")
|
||||
if (negativePrompt is not None and negativePrompt != "" and (len(negativePrompt) < 3 or len(negativePrompt) > 2000)):
|
||||
raise Exception("Negative Prompt Must Be Between 3 And 2000 characters!")
|
||||
|
||||
@@ -115,7 +115,7 @@ class photoMaker:
|
||||
|
||||
@classmethod
|
||||
def VALIDATE_INPUTS(cls, positivePrompt, negativePrompt):
|
||||
if (positivePrompt is None or len(positivePrompt) < 3 or len(positivePrompt) > 2000):
|
||||
if (positivePrompt is not None and (positivePrompt == "" or len(positivePrompt) < 3 or len(positivePrompt) > 2000)):
|
||||
raise Exception("Positive Prompt Must Be Between 3 And 2000 characters!")
|
||||
if (negativePrompt is not None and negativePrompt != "" and (len(negativePrompt) < 3 or len(negativePrompt) > 2000)):
|
||||
raise Exception("Negative Prompt Must Be Between 3 And 2000 characters!")
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
from comfy.model_management import InterruptProcessingException
|
||||
from requests.adapters import HTTPAdapter
|
||||
from server import PromptServer
|
||||
from dotenv import load_dotenv
|
||||
from pathlib import Path
|
||||
from PIL import Image
|
||||
@@ -58,6 +60,28 @@ def genRandSeed(minSeed = 1000, maxSeed = 9223372036854776000):
|
||||
def genRandUUID():
|
||||
return str(uuid.uuid4())
|
||||
|
||||
def checkAPIKey(apiKey):
|
||||
headers = {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Accept-Encoding": "gzip, deflate, br, zstd",
|
||||
}
|
||||
|
||||
genConfig = [{
|
||||
"taskType": "authentication",
|
||||
"apiKey": apiKey,
|
||||
}]
|
||||
|
||||
try:
|
||||
genResult = session.post(RUNWARE_API_BASE_URL, headers=headers, json=genConfig, timeout=SESSION_TIMEOUT, allow_redirects=False, stream=True)
|
||||
genResult = genResult.json()
|
||||
if("errors" in genResult):
|
||||
return str(genResult["errors"][0]["message"])
|
||||
else:
|
||||
return True
|
||||
except Exception as e:
|
||||
return False
|
||||
|
||||
def inferenecRequest(genConfig):
|
||||
global RUNWARE_API_KEY
|
||||
RUNWARE_API_KEY = os.getenv("RUNWARE_API_KEY")
|
||||
@@ -80,7 +104,12 @@ def inferenecRequest(genConfig):
|
||||
raise Exception("Error: Runware Request Failed!")
|
||||
except Exception as e:
|
||||
if "invalid api key" in str(e).lower():
|
||||
raise Exception("Invalid API Key - Please Make Sure you set your correctly API Key Either in the env file or through the API Manager Node!\n\nIf you don't have an API Key, you can get it from: https://my.runware.ai/keys")
|
||||
PromptServer.instance.send_sync("runwareError", {
|
||||
"success": False,
|
||||
"errorMessage": str(e),
|
||||
"errorCode": 401,
|
||||
})
|
||||
raise InterruptProcessingException()
|
||||
else:
|
||||
raise Exception(f"Error: {e}")
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user