From a47050cc3754e184a7c72cef389931dbdd8deafb Mon Sep 17 00:00:00 2001 From: Roman Kuzmenko Date: Mon, 11 Nov 2024 17:43:57 -0800 Subject: [PATCH] Fix the images for AI genereated parts in README after refactoring references to images in the prompts --- docs/source/configuration.rst | 6 ++++-- partcad/src/partcad/project.py | 25 +++++++++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index bb14f61c..9ea37d71 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -446,6 +446,7 @@ Generate OpenSCAD, CadQuery or build123d scripts with Generative AI using the fo parts: : + desc: <(optional) The detailed description to be used in the model generation prompt> type: provider: model: <(optional) the model to use> @@ -453,8 +454,9 @@ Generate OpenSCAD, CadQuery or build123d scripts with Generative AI using the fo temperature: <(optional) the temperature LLM parameter> top_p: <(optional) the top_p LLM parameter> top_k: <(optional, openai|ollama) the top_k LLM parameter> - images: <(optional) contextual images as input for AI> - - + +Place the detailed description of the part in the ``desc`` field. +Use ``INSERT_IMAGE_HERE()`` to insert images into the prompt. The following models are recommended for use: diff --git a/partcad/src/partcad/project.py b/partcad/src/partcad/project.py index 9ac2240c..7b0f7d78 100644 --- a/partcad/src/partcad/project.py +++ b/partcad/src/partcad/project.py @@ -9,6 +9,7 @@ import asyncio import copy import os +import re # from pprint import pformat import ruamel.yaml @@ -560,7 +561,9 @@ def get_sketch(self, sketch_name, func_params=None) -> sketch.Sketch: param_value ) elif config["parameters"][param_name]["type"] == "array": - config["parameters"][param_name]["default"] = param_value + config["parameters"][param_name][ + "default" + ] = param_value else: # Filling "with" if not "with" in config: @@ -799,7 +802,9 @@ def get_part(self, part_name, func_params=None, quiet=False) -> part.Part: param_value ) elif config["parameters"][param_name]["type"] == "array": - config["parameters"][param_name]["default"] = param_value + config["parameters"][param_name][ + "default" + ] = param_value else: # Filling "with" if not "with" in config: @@ -994,7 +999,9 @@ def get_assembly( param_value ) elif config["parameters"][param_name]["type"] == "array": - config["parameters"][param_name]["default"] = param_value + config["parameters"][param_name][ + "default" + ] = param_value else: # Filling "with" if not "with" in config: @@ -1203,7 +1210,9 @@ def get_provider( param_value ) elif config["parameters"][param_name]["type"] == "array": - config["parameters"][param_name]["default"] = param_value + config["parameters"][param_name][ + "default" + ] = param_value else: # Filling "with" if not "with" in config: @@ -1889,6 +1898,14 @@ def add_section(name, display_name, shape, render_cfg): parameters += "\n" columns += [parameters] + if not "images" in config and "INSERT_IMAGE_HERE" in config["desc"]: + config["images"] = list( + re.findall( + r"INSERT_IMAGE_HERE\(([^)]*)\)", + config["desc"], + re.MULTILINE, + ), + ) if "images" in config: images = "Input images:\n" for image in config["images"]: