Skip to content

Commit f9c3a48

Browse files
committed
Added a skill that performs CRUD operations on points
1 parent 0a9f557 commit f9c3a48

File tree

6 files changed

+399
-52
lines changed

6 files changed

+399
-52
lines changed

notebooks/012_kv_storage.ipynb

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "eb98ef8f",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"from intrinsic.solutions import deployments\n",
11+
"from intrinsic.solutions import behavior_tree as bt"
12+
]
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"id": "50e02e1c",
17+
"metadata": {},
18+
"source": [
19+
"First, connect to the deployed solution:"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": null,
25+
"id": "e827eb16",
26+
"metadata": {},
27+
"outputs": [],
28+
"source": [
29+
"solution = deployments.connect_to_selected_solution()\n",
30+
"executive = solution.executive\n",
31+
"skills = solution.skills\n",
32+
"points_crud_skill = skills.com.example.points_crud"
33+
]
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"id": "e622f4bc",
38+
"metadata": {},
39+
"source": [
40+
"Store two points in the KV storage:"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": null,
46+
"id": "6878fdea",
47+
"metadata": {},
48+
"outputs": [],
49+
"source": [
50+
"create_points = points_crud_skill(create=True, return_value_key=\"create_points_log\")\n",
51+
"executive.run(create_points)\n",
52+
"\n",
53+
"result = executive.get_value(create_points.result)\n",
54+
"print(result)"
55+
]
56+
},
57+
{
58+
"cell_type": "markdown",
59+
"id": "91ed1cc6",
60+
"metadata": {},
61+
"source": [
62+
"## Redeploy your solution now\n",
63+
"\n",
64+
"It will demonstrate that data in the key-value storage survives redeployment.\n",
65+
"\n",
66+
"- In Flowstate, select File -> Redeploy.\n",
67+
"- Wait for redeployment to complete before running code in cells below."
68+
]
69+
},
70+
{
71+
"cell_type": "markdown",
72+
"id": "981462b5",
73+
"metadata": {},
74+
"source": [
75+
"Reconnect to the solution after it has been redeployed:"
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": null,
81+
"id": "5b593596",
82+
"metadata": {},
83+
"outputs": [],
84+
"source": [
85+
"solution = deployments.connect_to_selected_solution()\n",
86+
"executive = solution.executive\n",
87+
"skills = solution.skills\n",
88+
"points_crud_skill = skills.com.example.points_crud"
89+
]
90+
},
91+
{
92+
"cell_type": "markdown",
93+
"id": "e48f731b",
94+
"metadata": {},
95+
"source": [
96+
"Confirm that the contents of the KV storage survived the redeployment:"
97+
]
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": null,
102+
"id": "b2f7c05d",
103+
"metadata": {},
104+
"outputs": [],
105+
"source": [
106+
"read_points = points_crud_skill(read=True, return_value_key=\"read_log\")\n",
107+
"executive.run(read_points)\n",
108+
"result = executive.get_value(read_points.result)\n",
109+
"print(result)"
110+
]
111+
},
112+
{
113+
"cell_type": "markdown",
114+
"id": "ce5bf121",
115+
"metadata": {},
116+
"source": [
117+
"Update a value stored in the KV storage:"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": null,
123+
"id": "c06faaea",
124+
"metadata": {},
125+
"outputs": [],
126+
"source": [
127+
"update_point = points_crud_skill(update=True, return_value_key=\"update_log\")\n",
128+
"executive.run(update_point)\n",
129+
"result = executive.get_value(update_point.result)\n",
130+
"print(result)"
131+
]
132+
},
133+
{
134+
"cell_type": "markdown",
135+
"id": "94cd7a0e",
136+
"metadata": {},
137+
"source": [
138+
"Finally, delete all points from the KV storage:"
139+
]
140+
},
141+
{
142+
"cell_type": "code",
143+
"execution_count": null,
144+
"id": "3c6b46db",
145+
"metadata": {},
146+
"outputs": [],
147+
"source": [
148+
"delete_points = points_crud_skill(delete=True, return_value_key=\"delete_log\")\n",
149+
"executive.run(delete_points)\n",
150+
"result = executive.get_value(delete_points.result)\n",
151+
"print(result)"
152+
]
153+
}
154+
],
155+
"metadata": {
156+
"kernelspec": {
157+
"display_name": "Python 3",
158+
"language": "python",
159+
"name": "python3"
160+
},
161+
"language_info": {
162+
"codemirror_mode": {
163+
"name": "ipython",
164+
"version": 3
165+
},
166+
"file_extension": ".py",
167+
"mimetype": "text/x-python",
168+
"name": "python",
169+
"nbconvert_exporter": "python",
170+
"pygments_lexer": "ipython3",
171+
"version": "3.11.13"
172+
}
173+
},
174+
"nbformat": 4,
175+
"nbformat_minor": 5
176+
}

notebooks/scratchpad.ipynb

Lines changed: 0 additions & 52 deletions
This file was deleted.

skills/points_crud/BUILD

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
load("@ai_intrinsic_sdks//bazel:skills.bzl", "py_skill", "skill_manifest")
2+
load("@com_github_grpc_grpc//bazel:python_rules.bzl", "py_proto_library")
3+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
4+
load("@rules_python//python:defs.bzl", "py_library")
5+
6+
proto_library(
7+
name = "points_crud_proto",
8+
srcs = ["points_crud.proto"],
9+
)
10+
11+
py_proto_library(
12+
name = "points_crud_py_pb2",
13+
deps = [":points_crud_proto"],
14+
)
15+
16+
skill_manifest(
17+
name = "points_crud_py_manifest",
18+
src = "points_crud.manifest.textproto",
19+
deps = [":points_crud_proto"],
20+
)
21+
22+
py_library(
23+
name = "points_crud",
24+
srcs = ["points_crud.py"],
25+
deps = [
26+
":points_crud_py_pb2",
27+
"//services/points_storage:points_storage_service_py_pb2",
28+
"//services/points_storage:points_storage_service_py_pb2_grpc",
29+
"@ai_intrinsic_sdks//intrinsic/skills/proto:equipment_py_pb2",
30+
"@ai_intrinsic_sdks//intrinsic/skills/python:proto_utils",
31+
"@ai_intrinsic_sdks//intrinsic/skills/python:skill_interface",
32+
"@ai_intrinsic_sdks//intrinsic/util:decorators",
33+
"@ai_intrinsic_sdks//intrinsic/util/grpc:connection",
34+
"@ai_intrinsic_sdks//intrinsic/util/grpc:interceptor",
35+
"@com_google_absl_py//absl/logging",
36+
"@com_google_protobuf//:protobuf_python",
37+
],
38+
)
39+
40+
py_skill(
41+
name = "points_crud_skill",
42+
manifest = ":points_crud_py_manifest",
43+
deps = [
44+
":points_crud",
45+
":points_crud_py_pb2",
46+
],
47+
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# proto-file: https://github.com/intrinsic-ai/sdk/blob/main/intrinsic/skills/proto/skill_manifest.proto
2+
# proto-message: intrinsic_proto.skill.SkillManifest
3+
4+
id {
5+
package: "com.example"
6+
name: "points_crud"
7+
}
8+
display_name: "Store points"
9+
vendor {
10+
display_name: "Intrinsic"
11+
}
12+
documentation {
13+
description: "Stores coordinates of 3d points in key-value storage."
14+
}
15+
options {
16+
supports_cancellation: false
17+
python_config {
18+
skill_module: "skills.points_crud.points_crud"
19+
proto_module: "skills.points_crud.points_crud_pb2"
20+
create_skill: "skills.points_crud.points_crud.PointsCrud"
21+
}
22+
}
23+
dependencies {
24+
required_equipment {
25+
key: "points_storage_service"
26+
value {
27+
capability_names: "points_storage.PointsStorageService"
28+
}
29+
}
30+
}
31+
parameter {
32+
message_full_name: "com.example.PointsCrudParams"
33+
default_value {
34+
type_url: "type.googleapis.com/com.example.PointsCrudParams"
35+
}
36+
}
37+
return_type {
38+
message_full_name: "com.example.PointsCrudExecutionLog"
39+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
syntax = "proto3";
2+
3+
package com.example;
4+
5+
message PointsCrudParams {
6+
bool create = 1;
7+
bool read = 2;
8+
bool update = 3;
9+
bool delete = 4;
10+
}
11+
12+
message PointsCrudExecutionLog {
13+
repeated string messages = 1;
14+
}

0 commit comments

Comments
 (0)