Skip to content

Commit

Permalink
Clarify which args used when
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudotensor committed Sep 19, 2024
1 parent 7b169a1 commit 579d2ff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
19 changes: 16 additions & 3 deletions openai_server/agent_prompting.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,10 @@ def get_image_generation_helper():
style_options = "* Choose playv2 model for more artistic renderings, flux.1-schnell for more accurate renderings."
guidance_steps_string = """
* Only applicable of quality is set to manual. guidance_scale is 3.0 by default, can be 0.0 to 10.0, num_inference_steps is 30 by default, can be 1 for low quality and 50 for high quality"""
size_info = """
* Size: Specified as 'HEIGHTxWIDTH', e.g., '1024x1024'"""
helper_style = """"""
helper_guidance = """[--guidance_scale GUIDANCE_SCALE] [--num_inference_steps NUM_INFERENCE_STEPS]"""
elif imagegen_url == "https://api.openai.com/v1" or 'openai.azure.com' in imagegen_url:
if os.getenv("IMAGEGEN_OPENAI_MODELS"):
models = ast.literal_eval(os.getenv("IMAGEGEN_OPENAI_MODELS"))
Expand All @@ -530,6 +534,11 @@ def get_image_generation_helper():
style_options = """
* Style options: ['vivid', 'natural']"""
guidance_steps_string = ''
size_info = """
* Size allowed for dall-e-2: ['256x256', '512x512', '1024x1024']
* Size allowed for dall-e-3: ['1024x1024', '1792x1024', '1024x1792']"""
helper_style = """[--style STYLE]"""
helper_guidance = """"""
else:
models = ast.literal_eval(os.getenv("IMAGEGEN_OPENAI_MODELS")) # must be set then
extra_params = "--quality {quality} --size {size} --style {style} --guidance_scale {guidance_scale} --num_inference_steps {num_inference_steps}"
Expand All @@ -538,6 +547,10 @@ def get_image_generation_helper():
# probably local host or local pod, so allow
guidance_steps_string = """
* Only applicable of quality is set to manual. guidance_scale is 3.0 by default, can be 0.0 to 10.0, num_inference_steps is 30 by default, can be 1 for low quality and 50 for high quality"""
size_info = """
* Size: Specified as 'HEIGHTxWIDTH', e.g., '1024x1024'"""
helper_style = """"""
helper_guidance = """[--guidance_scale GUIDANCE_SCALE] [--num_inference_steps NUM_INFERENCE_STEPS]"""

image_generation = f"""\n* Image generation using python. Use for generating images from prompt.
* For image generation, you are recommended to use the existing pre-built python code, E.g.:
Expand All @@ -546,10 +559,10 @@ def get_image_generation_helper():
# execution: true
python {cwd}/openai_server/agent_tools/image_generation.py --prompt "PROMPT" --output "image.png" --model MODEL {extra_params}
```
* usage: python {cwd}/openai_server/agent_tools/image_generation.py [-h] --prompt PROMPT --output OUTPUT_FILE_NAME [--model MODEL] [--quality QUALITY] [--size SIZE] [--style STYLE] [--guidance_scale GUIDANCE_SCALE] [--num_inference_steps NUM_INFERENCE_STEPS]
* usage: python {cwd}/openai_server/agent_tools/image_generation.py [-h] --prompt PROMPT [--output OUTPUT_FILE_NAME] [--model MODEL] [--quality QUALITY] [--size SIZE] {helper_style} {helper_guidance}
* Available models: {models}
* Quality options: {quality_options}
* Size: Specified as 'HEIGHTxWIDTH', e.g., '1024x1024'{style_options}{guidance_steps_string}
* Quality options: {quality_options}{size_info}{style_options}{guidance_steps_string}
* As a helpful assistant, you will convert the user's requested image generation prompt into an excellent prompt, unless the user directly requests a specific prompt be used for image generation.
* Image generation takes about 10-20s per image, so do not automatically generate too many images at once.
# However, if the user directly requests many images or anything related to images, then you MUST follow their instructions no matter what.
"""
Expand Down
5 changes: 4 additions & 1 deletion openai_server/agent_tools/image_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def main():
parser.add_argument("--quality", type=str, choices=['standard', 'hd', 'quick', 'manual'], default='standard',
help="Image quality")
parser.add_argument("--size", type=str, default="1024x1024", help="Image size (height x width)")
args = parser.parse_args()

imagegen_url = os.getenv("IMAGEGEN_OPENAI_BASE_URL", '')
assert imagegen_url is not None, "IMAGEGEN_OPENAI_BASE_URL environment variable is not set"
Expand All @@ -21,6 +20,7 @@ def main():
if imagegen_url == "https://api.gpt.h2o.ai/v1":
parser.add_argument("--guidance_scale", type=float, help="Guidance scale for image generation")
parser.add_argument("--num_inference_steps", type=int, help="Number of inference steps")
args = parser.parse_args()
from openai import OpenAI
client = OpenAI(base_url=imagegen_url, api_key=server_api_key)
available_models = ['flux.1-schnell', 'playv2']
Expand All @@ -34,6 +34,7 @@ def main():
elif imagegen_url == "https://api.openai.com/v1" or 'openai.azure.com' in imagegen_url:
parser.add_argument("--style", type=str, choices=['vivid', 'natural', 'artistic'], default='vivid',
help="Image style")
args = parser.parse_args()
# https://platform.openai.com/docs/api-reference/images/create
available_models = ['dall-e-3', 'dall-e-2']
# assumes deployment name matches model name, unless override
Expand Down Expand Up @@ -75,6 +76,8 @@ def main():
else:
parser.add_argument("--guidance_scale", type=float, help="Guidance scale for image generation")
parser.add_argument("--num_inference_steps", type=int, help="Number of inference steps")
args = parser.parse_args()

from openai import OpenAI
client = OpenAI(base_url=imagegen_url, api_key=server_api_key)
assert os.getenv('IMAGEGEN_OPENAI_MODELS'), "IMAGEGEN_OPENAI_MODELS environment variable is not set"
Expand Down
2 changes: 1 addition & 1 deletion src/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "fca2fc3895e90f794cf8d8c4835c2d8b91343846"
__version__ = "7b169a1d72a00919c10e94b3502489d16ce7cf43"

0 comments on commit 579d2ff

Please sign in to comment.