-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This agent will read a single file from an S3 bucket. The name of the file to read is taken from the record.
- Loading branch information
1 parent
f887bd6
commit 012e520
Showing
19 changed files
with
939 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,4 @@ dist | |
.tox | ||
build/ | ||
venv/ | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
java/lib/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Preprocessing Text | ||
|
||
This sample application shows how to read a single file from an S3 bucket and process in a pipeline. | ||
|
||
The pipeline will: | ||
|
||
|
||
- Read a file from and S3 bucket which is specified in the value of the message sent to the input topic | ||
- Extract text from document files (PDF, Word...) | ||
- Split the text into chunks | ||
- Write the chunks to the output topic | ||
|
||
## Prerequisites | ||
|
||
Prepare some PDF files and upload them to a bucket in S3. | ||
|
||
## Deploy the LangStream application | ||
|
||
``` | ||
./bin/langstream docker run test -app examples/applications/s3-processor -s examples/secrets/secrets.yaml --docker-args="-p9900:9000" | ||
``` | ||
|
||
Please note that here we are adding --docker-args="-p9900:9000" to expose the S3 API on port 9900. | ||
|
||
|
||
## Write some documents in the S3 bucket | ||
|
||
``` | ||
# Upload a document to the S3 bucket | ||
dev/s3_upload.sh localhost http://localhost:9900 documents README.md | ||
dev/s3_upload.sh localhost http://localhost:9900 documents examples/applications/s3-source/simple.pdf | ||
``` | ||
|
||
## Interact with the pipeline | ||
|
||
Now you can use the developer UI to specify which document to read from S3 and process. To process the simple.pdf file, simply send `simple.pdf` as the message. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# | ||
# Copyright DataStax, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
configuration: | ||
resources: | ||
dependencies: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# | ||
# Copyright DataStax, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
name: "Extract and manipulate text" | ||
topics: | ||
- name: "request-topic" | ||
creation-mode: create-if-not-exists | ||
- name: "response-topic" | ||
creation-mode: create-if-not-exists | ||
pipeline: | ||
- name: "convert-to-structure" | ||
type: "document-to-json" | ||
input: "request-topic" | ||
configuration: | ||
text-field: "filename" | ||
- name: "Process file from S3" | ||
type: "s3-processor" | ||
configuration: | ||
bucketName: "${secrets.s3.bucket-name}" | ||
endpoint: "${secrets.s3.endpoint}" | ||
access-key: "${secrets.s3.access-key}" | ||
secret-key: "${secrets.s3.secret}" | ||
region: "${secrets.s3.region}" | ||
objectName: "{{ value.filename }}" | ||
- name: "Extract text" | ||
type: "text-extractor" | ||
- name: "Split into chunks" | ||
type: "text-splitter" | ||
configuration: | ||
splitter_type: "RecursiveCharacterTextSplitter" | ||
chunk_size: 400 | ||
separators: ["\n\n", "\n", " ", ""] | ||
keep_separator: false | ||
chunk_overlap: 100 | ||
length_function: "cl100k_base" | ||
- name: "Convert to structured data" | ||
type: "document-to-json" | ||
configuration: | ||
text-field: text | ||
copy-properties: true | ||
- name: "prepare-structure" | ||
type: "compute" | ||
output: "response-topic" | ||
configuration: | ||
fields: | ||
- name: "value.filename" | ||
expression: "properties.name" | ||
type: STRING | ||
- name: "value.chunk_id" | ||
expression: "properties.chunk_id" | ||
type: STRING | ||
- name: "value.language" | ||
expression: "properties.language" | ||
type: STRING | ||
- name: "value.chunk_num_tokens" | ||
expression: "properties.chunk_num_tokens" | ||
type: STRING |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# | ||
# | ||
# Copyright DataStax, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
gateways: | ||
- id: "request" | ||
type: produce | ||
topic: "request-topic" | ||
parameters: | ||
- sessionId | ||
produceOptions: | ||
headers: | ||
- key: langstream-client-session-id | ||
valueFromParameters: sessionId | ||
|
||
- id: "reply" | ||
type: consume | ||
topic: "response-topic" | ||
parameters: | ||
- sessionId | ||
consumeOptions: | ||
filters: | ||
headers: | ||
- key: langstream-client-session-id | ||
valueFromParameters: sessionId |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.