Skip to content

Commit 41ad3f1

Browse files
committed
add Presidio example
1 parent b4c5864 commit 41ad3f1

30 files changed

Lines changed: 1320 additions & 1 deletion

‎samples/semantickernel-demos/pom.xml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45
<parent>
56
<groupId>com.microsoft.semantic-kernel</groupId>
@@ -16,5 +17,6 @@
1617
<modules>
1718
<module>booking-agent-m365</module>
1819
<module>semantickernel-spring-starter</module>
20+
<module>sk-presidio-sample</module>
1921
</modules>
2022
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
2+
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
3+
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
4+
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
5+
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
6+
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
7+
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
8+
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
9+
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
10+
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.3/apache-maven-3.9.3-bin.zip
18+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Presidio Sample
2+
3+
This sample demonstrates how to use Presidio with Semantic Kernel to redact sensitive data from a prompt. A sample
4+
output from this example is shown below:
5+
6+
```
7+
==============================
8+
Input text is:
9+
The users name is: Steven.
10+
Steven has account number 012345612.
11+
Steven was born in New York and their mother is Sally.
12+
==============================
13+
Anonymised text is:
14+
The users name is: PERSON4.
15+
PERSON4 has account number AU_ACN3.
16+
PERSON4 was born in LOCATION1 and their mother is PERSON2.
17+
18+
==============================
19+
User Question:
20+
Question: Where was the user born?
21+
==============================
22+
Anonymised response:
23+
The user was born in LOCATION1.
24+
==============================
25+
Deanonymised response:
26+
The user was born in New York.
27+
28+
==============================
29+
User Question:
30+
Question: Who is the users mother?
31+
==============================
32+
Anonymised response:
33+
The user's mother is PERSON2.
34+
==============================
35+
Deanonymised response:
36+
The user's mother is Sally.
37+
```
38+
39+
# App structure
40+
41+
The [semantickernel-presidio-plugin](..%2F..%2Fsemantickernel-sample-plugins%2Fsemantickernel-presidio-plugin) plugin
42+
takes user text and runs it through Presidio to redact sensitive data. The plugin then returns the redacted text. The
43+
redacted information is then sent to an LLM for processing. The response is then de-anonymised.
44+
45+
# Build and Run
46+
47+
As this example depends on running Presidio, it run within docker containers using docker compose.
48+
49+
- Before building and running ensure that you have run `./mvnw install` on the semantic kernel you wish to use.
50+
- Copy [env.example](env.example) to `.env` and update the values as needed.
51+
- Run [buildAndRun.sh](buildAndRun.sh)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -eux
4+
5+
./mvnw package
6+
7+
docker-compose build && docker-compose up
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: '3.6'
2+
services:
3+
presidio-analyzer:
4+
image: "mcr.microsoft.com/presidio-analyzer"
5+
ports:
6+
- 3001:3000
7+
logging:
8+
driver: none
9+
presidio-anonymizer:
10+
image: "mcr.microsoft.com/presidio-anonymizer"
11+
ports:
12+
- 3000:3000
13+
logging:
14+
driver: none
15+
sk-presidio-sample:
16+
image: "sk-presidio-sample"
17+
depends_on:
18+
- presidio-anonymizer
19+
- presidio-analyzer
20+
build:
21+
context: .
22+
dockerfile: ./sk-presidio-sample-dockerfile
23+
secrets:
24+
- ai-config
25+
secrets:
26+
ai-config:
27+
file: ./.env
28+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# If OpenAI
2+
#CLIENT_KEY="<KEY>"
3+
4+
# If Azure OpenAI
5+
#USE_AZURE_CLIENT=true
6+
#CLIENT_ENDPOINT="<ENDPOINT>"
7+
#AZURE_CLIENT_KEY="<KEY>"

0 commit comments

Comments
 (0)