# Re-use Custom Port Object from existing extensions Python-based extensions

**URL:** <https://forum.knime.com/t/re-use-custom-port-object-from-existing-extensions-python-based-extensions/82263>\
**Category:** Node Development\
**Tags:** python\
**Created:** [August 23, 2024, 9:04am UTC](https://forum.knime.com/t/re-use-custom-port-object-from-existing-extensions-python-based-extensions/82263 "2024-08-23T09:04:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MartinDDDD](https://forum-cdn.knime.com/user_avatar/forum.knime.com/martindddd/32/69988_2.png) [@MartinDDDD](https://forum.knime.com/u/MartinDDDD)\
**Post date:** [August 23, 2024, 9:04am UTC](https://forum.knime.com/t/re-use-custom-port-object-from-existing-extensions-python-based-extensions/82263/1 "2024-08-23T09:04:29Z")

</div>

Hey there,

I’m currently experimenting with developing nodes with LLM functionality.

Is there a way to “tap into” what is already implemented in the existing python-based Gen AI extension?

E.g. I wanted to make my node “compatible” with the OpenAI Chat Model Connector Ports (I am working on a Prompter node) and I observed the following:

When including the relevant port definitions directly in my extension I get this error:

```auto
ValueError: There is already a port type with the provided object class '<class 'utils.ports.ChatModelPortObject'>' registered.

```

**Is there a way to “point” my extension to the existing extensions Custom Port Object s?** How do I import Custom Port Objects correctly?

I’ve followed this part of the documentation and have added “_org.knime.python.features.llm_” as a dependency in my knime.yml:

> Feature dependencies: if your extension depends on another extension, you can specify it as a bullet point of `feature_dependencies`. Optionally, you can add a specific minimum version to it.
> 
> Example: You use data types like `SmilesValue` of the `KNIME Base Chemistry Types & Nodes` extension in your extension. You have that extension already installed and want to make sure that everybody who uses your extension will also have this extension installed. Then you can go to _Help \> About KNIME Analytics Platform \> Installation Details_ and check the id of `KNIME Base Chemistry Types & Nodes`, which is `org.knime.features.chem.types.feature.group`. Take the id without `.feature.group` and you have the string of the feature dependency: `org.knime.features.chem.types`

---

<div class="post-metadata">

**Author:** ![carstenhaubold](https://forum-cdn.knime.com/user_avatar/forum.knime.com/carstenhaubold/32/33947_2.png) [@carstenhaubold](https://forum.knime.com/u/carstenhaubold)\
**Post date:** [August 27, 2024, 7:01am UTC](https://forum.knime.com/t/re-use-custom-port-object-from-existing-extensions-python-based-extensions/82263/2 "2024-08-27T07:01:19Z")

</div>

Hey @MartinDDDD,

It is really cool to see that you are building an extension that wants to interface our AI Extension! But by doing so, you notice the boundaries of what is currently possible in KNIME from Python 😉

Using port objects defined in other extensions is something that we do not support yet.

There are a few complications why that is the case.

Assume extension A defines port object type PA. It uses library LA in its code and that is also used for serialization of some internals of the port object PA. Note that port objects are always passed between nodes in serialized form.

**Importing the Port Object definition**

To be able to use the port object PA defined in A in another extension B, we’d have to be able to import the module defining PA in A in our extension B. We currently didn’t build a means of module discoverability between extension yet, also because whatever libraries imported in the module defining PA need to be available in B, which brings us to…

**Environment Compatibility**  
We don’t know yet how to ensure compatibility of the Python environments:

Now extension B wants to use PA. It will only be able to call the deserialization of PA if it also has library LA in its Python environment. There’s no way to enforce that. But we’d like to be able to at least check that this library is available when B depends on PA.

If you have input around how we could nicely resolve these issues, I’m all ears 😉

Best,  
Carsten

---

<div class="post-metadata">

**Author:** ![MartinDDDD](https://forum-cdn.knime.com/user_avatar/forum.knime.com/martindddd/32/69988_2.png) [@MartinDDDD](https://forum.knime.com/u/MartinDDDD)\
**Post date:** [August 27, 2024, 5:36pm UTC](https://forum.knime.com/t/re-use-custom-port-object-from-existing-extensions-python-based-extensions/82263/3 "2024-08-27T17:36:15Z")

</div>

Thanks a lot for the detailed response - got it.

The part of the docs and the error that I got had made me hope that there’s a way (given that the port object has been registered). You pretty much need to allow extending an extension rather than extending KNIME… but then again what happens if two people extend the same extension?

Absolutely not in my realm of expertise to solve this ;-). Glad I manage to build something with the integration as is!

Takeaway for me: Will take those parts that have been implemented very well already and re-use it in my extensions… glad it is all open source 🙂

If you are interested in what I am cooking up - successfully built my extension which allows to use Structured Outputs from OpenAI incl. Table to JSON Schema generator:

> **[GitHub - miuuu1/FinnovationFlows-Extension: KNIME Extension by Finnovation Flows](https://github.com/miuuu1/FinnovationFlows-Extension)**
>
> KNIME Extension by Finnovation Flows. Contribute to miuuu1/FinnovationFlows-Extension development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [September 3, 2024, 5:36pm UTC](https://forum.knime.com/t/re-use-custom-port-object-from-existing-extensions-python-based-extensions/82263/4 "2024-09-03T17:36:37Z")

</div>

Closed on September 3, 2024, 5:36pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
