generated from jupyter-naas/data-product-framework
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path.cursorrules
204 lines (156 loc) · 6.64 KB
/
.cursorrules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// User Intent: Create new integration
Required input: IntegrationName (PascalCase if not convert to it)
Template to use:
```python
from lib.abi.integration.integration import Integration, IntegrationConfiguration
from dataclasses import dataclass
@dataclass
class YourIntegrationConfiguration(IntegrationConfiguration):
"""Configuration for YourIntegration.
Attributes:
attribute_1 (str): Description of attribute_1
attribute_2 (int): Description of attribute_2
"""
attribute_1: str
attribute_2: int
class YourIntegration(Integration):
"""YourIntegration class for interacting with YourService.
This class provides methods to interact with YourService's API endpoints.
It handles authentication and request management.
Attributes:
__configuration (YourIntegrationConfiguration): Configuration instance
containing necessary credentials and settings.
Example:
>>> config = YourIntegrationConfiguration(
... attribute_1="value1",
... attribute_2=42
... )
>>> integration = YourIntegration(config)
"""
__configuration: YourIntegrationConfiguration
def __init__(self, configuration: YourIntegrationConfiguration):
super().__init__(configuration)
self.__configuration = configuration
```
Output: Create file in `src/integrations/IntegrationName.py`
// User Intent: Create new pipeline or Update existing pipeline
Required input: PipelineName (PascalCase if not convert to it)
Template to use:
```python
from abi.pipeline import Pipeline, PipelineConfiguration, PipelineParameters
from dataclasses import dataclass
from src.data.integrations import YourIntegration
from abi.utils.Graph import ABIGraph
from rdflib import Graph
from abi.services.ontology_store.OntologyStorePorts import IOntologyStoreService
from src import secret
from fastapi import APIRouter
from langchain_core.tools import StructuredTool
@dataclass
class YourPipelineConfiguration(PipelineConfiguration):
"""Configuration for YourPipeline.
Attributes:
integration (YourIntegration): The integration instance to use
ontology_store (IOntologyStoreService): The ontology store service to use
ontology_store_name (str): Name of the ontology store to use. Defaults to "yourstorename"
"""
integration: YourIntegration
ontology_store: IOntologyStoreService
ontology_store_name: str = "yourstorename"
class YourPipelineParameters(PipelineParameters):
"""Parameters for YourPipeline execution.
Attributes:
parameter_1 (str): Description of parameter_1
parameter_2 (int): Description of parameter_2
"""
parameter_1: str
parameter_2: int
class YourPipeline(Pipeline):
__configuration: YourPipelineConfiguration
def __init__(self, configuration: YourPipelineConfiguration):
self.__configuration = configuration
def as_tools(self) -> list[StructuredTool]:
"""Returns a list of LangChain tools for this pipeline.
Returns:
list[StructuredTool]: List containing the pipeline tool
"""
return [StructuredTool(
name="your_pipeline",
description="Executes the pipeline with the given parameters",
func=lambda **kwargs: self.run(YourPipelineParameters(**kwargs)),
args_schema=YourPipelineParameters
)]
def as_api(self, router: APIRouter) -> None:
"""Adds API endpoints for this pipeline to the given router.
Args:
router (APIRouter): FastAPI router to add endpoints to
"""
@router.post("/YourPipeline")
def run(parameters: YourPipelineParameters):
return self.run(parameters).serialize(format="turtle")
def run(self, parameters: YourPipelineParameters) -> Graph:
graph = ABIGraph()
# ... Add your code here
self.__configuration.ontology_store.insert(self.__configuration.ontology_store_name, graph)
return graph
```
Output: Create file in `src/data/pipelines/ToolNameIfRelevent/PipelineName.py`
// User Intent: Create new workflow
Required input: WorkflowName (PascalCase if not convert to it)
Template to use:
```python
from abi.workflow import Workflow, WorkflowConfiguration
from abi.workflow.workflow import WorkflowParameters
from src.core.modules.common.integrations import YourIntegration, YourIntegrationConfiguration
from src import secret, config
from dataclasses import dataclass
from pydantic import BaseModel, Field
from typing import Optional, List, Dict
from abi import logger
from fastapi import APIRouter
from langchain_core.tools import StructuredTool
from typing import Any
@dataclass
class YourWorkflowConfiguration(WorkflowConfiguration):
"""Configuration for YourWorkflow.
Attributes:
integration_config (YourIntegrationConfiguration): Configuration for the integration
"""
integration_config: YourIntegrationConfiguration
class YourWorkflowParameters(WorkflowParameters):
"""Parameters for YourWorkflow execution.
Attributes:
parameter_1 (str): Description of parameter_1
parameter_2 (int): Description of parameter_2
"""
parameter_1: str = Field(..., description="Description of parameter_1")
parameter_2: int = Field(..., description="Description of parameter_2")
class YourWorkflow(Workflow):
__configuration: YourWorkflowConfiguration
def __init__(self, configuration: YourWorkflowConfiguration):
self.__configuration = configuration
self.__integration = YourIntegration(self.__configuration.integration_config)
def run(self, parameters: YourWorkflowParameters) -> Any:
# Add your workflow logic here
return "Your result"
def as_tools(self) -> list[StructuredTool]:
"""Returns a list of LangChain tools for this workflow.
Returns:
list[StructuredTool]: List containing the workflow tool
"""
return [StructuredTool(
name="your_workflow_name",
description="Description of what your workflow does",
func=lambda **kwargs: self.run(YourWorkflowParameters(**kwargs)),
args_schema=YourWorkflowParameters
)]
def as_api(self, router: APIRouter) -> None:
"""Adds API endpoints for this workflow to the given router.
Args:
router (APIRouter): FastAPI router to add endpoints to
"""
@router.post("/your_endpoint")
def run_workflow(parameters: YourWorkflowParameters):
return self.run(parameters)
```
Output: Create file in `src/workflows/WorkflowName.py`