跳转至

Integrate models with the Ontology(将模型与本体论(Ontology)集成)

This section provides examples on how to leverage the Ontology with models using the Ontology SDK and Platform SDK.

Object and object set inputs in model adapters

You can define a model adapter with object and object set inputs in the api() class method of a model adapter. After creating an ontology_sdk package through Developer Console or Code Workspaces, the objects can be used in the model adapter as inputs:

from ontology_sdk.ontology.objects import Employee
from ontology_sdk.ontology.object_sets import EmployeeObjectSet

class ObjectsInModelApiAdapter(pm.ModelAdapter):
    ...

    @classmethod
    def api(cls):
        inputs = {
            "object_input": pm.Object(Employee),
            "object_set_input": pm.ObjectSet(EmployeeObjectSet)
        }
        outputs = {
            "param_out": pm.Parameter(type=str)
        }
        return inputs, outputs

    def predict(self, object_input, object_set_input):
        ....

To pass in an object or object set for testing, you can select inputs from the Ontology on the model query page when a direct model deployment is running. You can also publish a function on the left side-bar using the Ontology object or object set inputs.

Example Object and Object Set input on the model query page

Use the Platform SDK in a model adapter

You can query functions, objects, and LLMs with the Ontology SDK and Platform SDK by using FoundryClient() in models through the predict or transform method of a model.

from ontology_sdk import FoundryClient

class ObjectsInModelApiAdapter(pm.ModelAdapter):
    ....

    def predict(self, employee_primary_key):
        client = FoundryClient()
        client_first_name = client.ontology.objects.Employee.get(employee_primary_key).first_name
        ...

This allows for pro-code LLM based workflows where you can interact with the Ontology and utilize traditional modeling techniques to produce more accurate predictions.


中文翻译

将模型与本体论(Ontology)集成

本节提供示例,说明如何利用本体论(Ontology)通过本体论SDK(Ontology SDK)平台SDK(Platform SDK)与模型进行集成。

模型适配器中的对象(Object)和对象集(Object Set)输入

您可以在模型适配器的api()类方法中定义包含对象和对象集输入的模型适配器。通过开发者控制台(Developer Console)代码工作区(Code Workspaces)创建ontology_sdk包后,这些对象即可作为输入在模型适配器中使用:

from ontology_sdk.ontology.objects import Employee
from ontology_sdk.ontology.object_sets import EmployeeObjectSet

class ObjectsInModelApiAdapter(pm.ModelAdapter):
    ...

    @classmethod
    def api(cls):
        inputs = {
            "object_input": pm.Object(Employee),
            "object_set_input": pm.ObjectSet(EmployeeObjectSet)
        }
        outputs = {
            "param_out": pm.Parameter(type=str)
        }
        return inputs, outputs

    def predict(self, object_input, object_set_input):
        ....

要传入对象或对象集进行测试,您可以在直接模型部署运行时,从模型查询页面上选择本体论中的输入。您也可以使用本体论对象或对象集输入,在左侧边栏发布一个函数。

模型查询页面上的对象和对象集输入示例

在模型适配器中使用平台SDK(Platform SDK)

您可以通过模型的predicttransform方法,在模型中使用FoundryClient()来查询函数、对象和大型语言模型(LLM),具体可借助本体论SDK(Ontology SDK)平台SDK(Platform SDK)

from ontology_sdk import FoundryClient

class ObjectsInModelApiAdapter(pm.ModelAdapter):
    ....

    def predict(self, employee_primary_key):
        client = FoundryClient()
        client_first_name = client.ontology.objects.Employee.get(employee_primary_key).first_name
        ...

这支持基于专业代码的LLM工作流,使您能够与本体论进行交互,并利用传统建模技术生成更准确的预测结果。