Skip to content

Commit

Permalink
Fix the images for AI genereated parts in README after refactoring re…
Browse files Browse the repository at this point in the history
…ferences to images in the prompts (#205)
  • Loading branch information
openvmp authored Nov 12, 2024
1 parent 0d07d7a commit 5bbbed0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
6 changes: 4 additions & 2 deletions docs/source/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,17 @@ Generate OpenSCAD, CadQuery or build123d scripts with Generative AI using the fo
parts:
<part name>:
desc: <(optional) The detailed description to be used in the model generation prompt>
type: <ai-openscad|ai-cadquery|ai-build123d>
provider: <google|openai|ollama, the model provider to use>
model: <(optional) the model to use>
tokens: <(optional) the limit of token context>
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>
- <image path>
Place the detailed description of the part in the ``desc`` field.
Use ``INSERT_IMAGE_HERE(<relative-path-without-quotes>)`` to insert images into the prompt.

The following models are recommended for use:

Expand Down
25 changes: 21 additions & 4 deletions partcad/src/partcad/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import asyncio
import copy
import os
import re

# from pprint import pformat
import ruamel.yaml
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1889,6 +1898,14 @@ def add_section(name, display_name, shape, render_cfg):
parameters += "</ul>\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"]:
Expand Down

0 comments on commit 5bbbed0

Please sign in to comment.