@@ -7,10 +7,13 @@ Welcome to Allie FlowKit Python. This repository hosts Python functions similar
7
7
- [ Objectives] ( #objectives )
8
8
- [ How it works] ( #how-it-works )
9
9
- [ Getting started] ( #getting-started )
10
- - [ Prerequisites] ( #prerequisites )
11
- - [ Installation] ( #installation )
12
- - [ Usage] ( #usage )
10
+ - [ Run locally] ( #run-locally )
11
+ - [ Prerequisites] ( #prerequisites )
12
+ - [ Installation] ( #installation )
13
+ - [ Usage] ( #usage )
14
+ - [ Run as a Docker container] ( #run-as-a-docker-container )
13
15
- [ Adding custom functions] ( #adding-custom-functions )
16
+ - [ Example] ( #example )
14
17
- [ Example functions] ( #example-functions )
15
18
- [ Contributing] ( #contributing )
16
19
@@ -38,13 +41,17 @@ Allie Flowkit Python supports these actions:
38
41
39
42
## Getting started
40
43
41
- ### Prerequisites
44
+ Allie FlowKit Python can be run locally or as a Docker container. Follow the instructions below to get started.
45
+
46
+ ### Run locally
47
+
48
+ #### Prerequisites
42
49
43
50
- Python 3.7 or later
44
51
- pip (Python package installer)
45
52
- A running instance of the Allie Flowkit
46
53
47
- ### Installation
54
+ #### Installation
48
55
49
56
1 . Clone the repository:
50
57
``` sh
@@ -57,62 +64,142 @@ Allie Flowkit Python supports these actions:
57
64
pip install -r requirements.txt
58
65
` ` `
59
66
60
- # ## Usage
67
+ # ### Usage
61
68
62
69
1. Start the service:
63
- ` ` ` sh
64
- uvicorn app.app:app --host 0.0.0.0 --port 8000 --workers 1
65
- ` ` `
66
- You can specify the host, port, and number of workers as needed. The service exposes the functions as REST APIs on the specified port. The default is 8000.
70
+ ` ` ` sh
71
+ uvicorn app.app:app --host 0.0.0.0 --port 50052 --workers 1
72
+ ` ` `
73
+ You can specify the host, port, and number of workers as needed.
74
+
75
+ 2. The service will expose the functions as REST APIs on the specified port (default: 8000).
76
+
77
+ 3. Integrate these APIs into your Allie workflows as needed.
67
78
68
- 2. Integrate these APIs into your Allie workflows as needed.
79
+ # ## Run as a Docker container
80
+
81
+ 1. Build the Docker container image with the following command:
82
+
83
+ ` ` ` bash
84
+ docker build -f docker/Dockerfile . -t allie-flowkit-python:latest
85
+ ` ` `
86
+
87
+ 2. Run the Docker container and expose the port on your desired endpoint. You can also specify the number of workers as needed:
88
+
89
+ ` ` ` bash
90
+ docker run -d -e WORKERS=5 --rm --name allie-flowkit-python -p 50052:50052 allie-flowkit-python:latest
91
+ ` ` `
69
92
70
93
# # Adding custom functions
71
94
72
- 1. ** Create a function. **
95
+ 1. ** Create a New Function: **
73
96
- Add your function code as an endpoint to a new Python file in the ` app/endpoints` directory.
74
97
- Use the ` app/endpoints/splitter.py` file and its endpoints as an example.
75
- - Be explicit about the input and output of the function as they are used by the Allie agent
76
- to call the function.
77
-
78
- 2. ** Add the models for the function.**
79
- - Add the models for the input and output of the function in the ` app/models` directory.
80
- - Use the ` app/models/splitter.py` file its models as an example.
81
-
82
- 2. ** Add the endpoints to the service.**
83
-
84
- - Import your module in the ` app/app.py` file.
85
- - Add the router to the service:
86
- ` ` ` python
87
- app.include_router(splitter.router, prefix=" /custom_module" , tags=[" custom_module" ])
88
- ` ` `
89
-
90
- ** Example**
91
- ` ` ` python
92
- from fastapi import FastAPI, APIRouter
93
- from app.models.custom_model import CustomRequest, CustomResponse
94
-
95
- app = FastAPI ()
96
- router = APIRouter ()
97
-
98
- @router.post(' /custom_function' , response_model=CustomResponse)
99
- async def custom_function(request: CustomRequest) -> CustomResponse:
100
- " " " Endpoint for custom function.
101
-
102
- Parameters
103
- ----------
104
- request : CustomRequest
105
- Object containing the input data required for the function.
106
-
107
- Returns
108
- -------
109
- CustomResponse
110
- Object containing the output data of the function.
111
- " " "
112
- # Your custom processing logic here
113
- result = ...
114
- return result
115
- ` ` `
98
+ - Explicitly define the input and output of the function using Pydantic models, as these will be used by the Allie Agent to call the function.
99
+
100
+ 2. ** Add the models for the function:**
101
+ - Create the models for the input and output of the function in the ` app/models` directory.
102
+ - Use the ` app/models/splitter.py` file and its models as an example.
103
+
104
+ 3. ** Add the endpoints to the service:**
105
+ - Import your module in the ` app/app.py` file and add the router to the service.
106
+
107
+ 4. ** Add the function to the function map:**
108
+ - Add your function to the ` function_map` dictionary in the ` app/app.py` file.
109
+
110
+ # ## Example´
111
+
112
+ 1. ** Create a new file for all your custom functions:**
113
+ - In the ` app/endpoints` directory, create a new Python file named ` custom_endpoint.py` .
114
+
115
+ 2. ** Create the models for the custom function:**
116
+ - In the ` app/models` directory, create a new Python file named ` custom_model.py` .
117
+
118
+ ** custom_model.py** :
119
+ ` ` ` python
120
+ from pydantic import BaseModel
121
+
122
+
123
+ class CustomRequest(BaseModel):
124
+ " " " Model for the input data required for the custom function.
125
+
126
+ Parameters
127
+ ----------
128
+ BaseModel : pydantic.BaseModel
129
+ Base model for the request.
130
+
131
+ " " "
132
+
133
+ input_data: str
134
+
135
+
136
+ class CustomResponse(BaseModel):
137
+ " " " Model for the output data of the custom function.
138
+
139
+ Parameters
140
+ ----------
141
+ BaseModel : pydantic.BaseModel
142
+ Base model for the response.
143
+
144
+ " " "
145
+
146
+ output_data: str
147
+ ` ` `
148
+
149
+ 3. ** Define your custom function:**
150
+ - Add your function to ` ` custom_endpoint.py` ` , explicitly defining the input and output using Pydantic models.
151
+
152
+ ** custom_endpoint.py** :
153
+ ` ` ` python
154
+ from fastapi import FastAPI, APIRouter
155
+ from app.models.custom_model import CustomRequest, CustomResponse
156
+
157
+
158
+ @router.post(" /custom_function" , response_model=CustomResponse)
159
+ async def custom_function(request: CustomRequest) -> CustomResponse:
160
+ " " " Endpoint for custom function.
161
+
162
+ Parameters
163
+ ----------
164
+ request : CustomRequest
165
+ Object containing the input data required for the function.
166
+
167
+ Returns
168
+ -------
169
+ CustomResponse
170
+ Object containing the output data of the function.
171
+
172
+ " " "
173
+ # Your custom processing logic here
174
+ result = ...
175
+ return result
176
+ ` ` `
177
+
178
+ 4. ** Import the module and add the router to the service:**
179
+ - Import the module in the ` ` app/app.py` ` file and add the router to the service.
180
+
181
+ ** app.py** :
182
+ ` ` ` python
183
+ from app.endpoints import custom_endpoint
184
+
185
+ app.include_router(splitter.router, prefix=" /splitter" , tags=[" splitter" ])
186
+ app.include_router(
187
+ custom_endpoint.router, prefix=" /custom_endpoint" , tags=[" custom_endpoint" ]
188
+ )
189
+ ` ` `
190
+
191
+ 5. ** Add the function to the function map:**
192
+ - Add your function to the ` ` function_map` ` dictionary in the ` ` app/app.py` ` file.
193
+
194
+ ** app.py** :
195
+ ` ` ` python
196
+ function_map = {
197
+ " split_ppt" : splitter.split_ppt,
198
+ " split_pdf" : splitter.split_pdf,
199
+ " split_py" : splitter.split_py,
200
+ " custom_function" : custom_endpoint.custom_function,
201
+ }
202
+ ` ` `
116
203
117
204
# # Example functions
118
205
0 commit comments