Skip to content

Commit

Permalink
Merge pull request #428 from golioth/pipeline-examples/ai
Browse files Browse the repository at this point in the history
Add cloud inference pipeline examples
  • Loading branch information
hasheddan authored Aug 5, 2024
2 parents b42b61a + 96d509d commit 626301c
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 0 deletions.
31 changes: 31 additions & 0 deletions docs/data-routing/5-examples/18-replicate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Replicate
---
import Pipeline from '@site/src/components/usethispipeline'

[Replicate](https://replicate.com/) is an AI platform that makes machine
learning accessible to every software developer by allowing for running and
fine-tuning open source and custom models at scale. Existing models on Replicate
suppport use cases that range from video generation to optical character
recognition (OCR).

The following example demonstrates captioning images streamed to Golioth using
the [Salesforce BLIP model](https://replicate.com/salesforce/blip). The PNG
image is submitted in the [`webhook`
destination](/data-routing/destinations/webhook) request by encoding as a [Data
URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs),
then embedding in a JSON object.

Predictions on Replicate are asynchronous, meaning that the result is not
accessible directly in Pipelines. Results can be viewed in the Replicate
console, or a [webhook
URL](https://replicate.com/docs/reference/http#predictions.create--webhook) can
be included in the destination body to instruct webhook to deliver the result to
the specified URL after the prediction has completed.

:::info Reminder
Make sure to create a [secret](/data-routing/secrets) named
`REPLICATE_TOKEN` in the format `Bearer <token>`.
:::

<Pipeline link='https://console.golioth.io/pipeline?name=Replicate%20Caption&pipeline=ZmlsdGVyOgogIHBhdGg6ICIvaW1hZ2VzIgpzdGVwczoKICAtIG5hbWU6IHBuZwogICAgdHJhbnNmb3JtZXI6CiAgICAgIHR5cGU6IGNoYW5nZS1jb250ZW50LXR5cGUKICAgICAgdmVyc2lvbjogdjEKICAgICAgcGFyYW1ldGVyczoKICAgICAgICBjb250ZW50X3R5cGU6IGltYWdlL3BuZwogIC0gbmFtZTogdXJsCiAgICB0cmFuc2Zvcm1lcjoKICAgICAgdHlwZTogZGF0YS11cmwKICAgICAgdmVyc2lvbjogdjEKICAtIG5hbWU6IGVtYmVkCiAgICB0cmFuc2Zvcm1lcjoKICAgICAgdHlwZTogZW1iZWQtaW4tanNvbgogICAgICB2ZXJzaW9uOiB2MQogICAgICBwYXJhbWV0ZXJzOgogICAgICAgIGtleTogaW1hZ2UKICAtIG5hbWU6IGNyZWF0ZS1wYXlsb2FkCiAgICB0cmFuc2Zvcm1lcjoKICAgICAgdHlwZToganNvbi1wYXRjaAogICAgICB2ZXJzaW9uOiB2MQogICAgICBwYXJhbWV0ZXJzOgogICAgICAgIHBhdGNoOiB8CiAgICAgICAgICBbCiAgICAgICAgICAgIHsib3AiOiAiYWRkIiwgInBhdGgiOiAiL3ZlcnNpb24iLCAidmFsdWUiOiAiMmUxZGRkYzg2MjFmNzIxNTVmMjRjZjJlMGFkYmRlNTQ4NDU4ZDNjYWI5ZjAwYzAxMzllZWE4NDBkMGFjNDc0NiJ9LAogICAgICAgICAgICB7Im9wIjogImFkZCIsICJwYXRoIjogIi9pbnB1dCIsICJ2YWx1ZSI6IHsiaW1hZ2UiOiAiIn19LAogICAgICAgICAgICB7Im9wIjogIm1vdmUiLCAiZnJvbSI6ICIvaW1hZ2UiLCAicGF0aCI6ICIvaW5wdXQvaW1hZ2UifQogICAgICAgICAgXQogIC0gbmFtZTogcHJlZGljdAogICAgZGVzdGluYXRpb246CiAgICAgIHR5cGU6IHdlYmhvb2sKICAgICAgdmVyc2lvbjogdjEKICAgICAgcGFyYW1ldGVyczoKICAgICAgICB1cmw6IGh0dHBzOi8vYXBpLnJlcGxpY2F0ZS5jb20vdjEvcHJlZGljdGlvbnMKICAgICAgICBoZWFkZXJzOgogICAgICAgICAgQXV0aG9yaXphdGlvbjogJFJFUExJQ0FURV9UT0tFTg==' />
56 changes: 56 additions & 0 deletions docs/data-routing/5-examples/19-hugging-face.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
title: Hugging Face
---
import Pipeline from '@site/src/components/usethispipeline'

[Hugging Face](https://huggingface.co/) is a platform where the machine learning
community collaborates on models, datasets, and applications. Hugging Face's
[dedicated Inference
Endpoints](https://huggingface.co/inference-endpoints/dedicated) and [Serverless
Inference API](https://huggingface.co/docs/api-inference/index) allow for
running any model via an HTTP REST API, which can be accessed from Pipelines
using the [`webhook` transformer](/data-routing/transformers/webhook).

:::warning
The Serverless Inference API is free but rate-limited. It should only be used
for testing scenarios, and it is expected that some operations may be dropped if
the specified model is not already [loaded in
memory](https://huggingface.co/docs/api-inference/quicktour#model-loading-and-latency).
Inference Endpoints should be used in production scenarios.
:::

The following example demonstrates using the Hugging Face Serverless Inference
API to perform sentiment analysis of audio samples streamed to Golioth. The
[Hubert-Large for Emotion Recognition
model](https://huggingface.co/superb/hubert-large-superb-er) is targeted.
Sentiment analysis results are delivered to [LightDB
Stream](/application-services/lightdb-stream) as a JSON payload.

Example sentiment analysis result:
```json
[
{
"score": 0.6310836672782898,
"label": "neu"
},
{
"score": 0.2573806643486023,
"label": "sad"
},
{
"score": 0.09393830597400665,
"label": "hap"
},
{
"score": 0.017597444355487823,
"label": "ang"
}
]
```

:::info Reminder
Make sure to create a [secret](/data-routing/secrets) named `HUGGING_FACE_TOKEN`
in the format `Bearer <token>`.
:::

<Pipeline link='https://console.golioth.io/pipeline?name=Hugging%20Face%20Emotion%20Recognition&pipeline=ZmlsdGVyOgogIHBhdGg6ICIvYXVkaW8iCnN0ZXBzOgogIC0gbmFtZTogZW1vdGlvbi1yZWNvZ25pdGlvbgogICAgdHJhbnNmb3JtZXI6CiAgICAgIHR5cGU6IHdlYmhvb2sKICAgICAgdmVyc2lvbjogdjEKICAgICAgcGFyYW1ldGVyczoKICAgICAgICB1cmw6IGh0dHBzOi8vYXBpLWluZmVyZW5jZS5odWdnaW5nZmFjZS5jby9tb2RlbHMvc3VwZXJiL2h1YmVydC1sYXJnZS1zdXBlcmItZXIKICAgICAgICBoZWFkZXJzOgogICAgICAgICAgQXV0aG9yaXphdGlvbjogJEhVR0dJTkdfRkFDRV9UT0tFTgogIC0gbmFtZTogZW1iZWQKICAgIHRyYW5zZm9ybWVyOgogICAgICB0eXBlOiBlbWJlZC1pbi1qc29uCiAgICAgIHZlcnNpb246IHYxCiAgICAgIHBhcmFtZXRlcnM6CiAgICAgICAga2V5OiB0ZXh0CiAgLSBuYW1lOiBzZW5kLWxpZ2h0ZGItc3RyZWFtCiAgICBkZXN0aW5hdGlvbjoKICAgICAgdHlwZTogbGlnaHRkYi1zdHJlYW0KICAgICAgdmVyc2lvbjogdjE=' />
26 changes: 26 additions & 0 deletions docs/data-routing/5-examples/20-openai.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: OpenAI
---
import Pipeline from '@site/src/components/usethispipeline'

[OpenAI](https://openai.com/) is a platform that enables developers to build and
scale AI experiences powered by industry-leading models and tools. OpenAI's
suite of proprietary models support text generation, speech-to-text, vision, and
more.

The following example demonstrates leveraging OpenAI's [GPT-4o
mini](https://platform.openai.com/docs/models/gpt-4o-mini) model via the
Pipelines [`webhook` transformer](/data-routing/transformers/webhook) to
describe an image streamed to Golioth. The image is embedded as a [Data
URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs)
alongside the chosen model and a prompt. The resulting description is passed to
a [Slack webhook](/data-routing/examples/slack-webhook) via the [`webhook`
destination](/data-routing/destinations/webhook).

:::info Reminder
Make sure to create a [secret](/data-routing/secrets) named `OPENAI_TOKEN` in
the format `Bearer <token>`. In this example a `SLACK_WEBHOOK` secret is also
required.
:::

<Pipeline link='https://console.golioth.io/pipeline?name=OpenAI%20Describe%20Image&pipeline=ZmlsdGVyOgogIHBhdGg6ICIvaW1hZ2UiCnN0ZXBzOgogIC0gbmFtZToganBlZwogICAgdHJhbnNmb3JtZXI6CiAgICAgIHR5cGU6IGNoYW5nZS1jb250ZW50LXR5cGUKICAgICAgdmVyc2lvbjogdjEKICAgICAgcGFyYW1ldGVyczoKICAgICAgICBjb250ZW50X3R5cGU6IGltYWdlL2pwZWcKICAtIG5hbWU6IHVybAogICAgdHJhbnNmb3JtZXI6CiAgICAgIHR5cGU6IGRhdGEtdXJsCiAgICAgIHZlcnNpb246IHYxCiAgLSBuYW1lOiBlbWJlZAogICAgdHJhbnNmb3JtZXI6CiAgICAgIHR5cGU6IGVtYmVkLWluLWpzb24KICAgICAgdmVyc2lvbjogdjEKICAgICAgcGFyYW1ldGVyczoKICAgICAgICBrZXk6IGltYWdlCiAgLSBuYW1lOiBjcmVhdGUtcGF5bG9hZAogICAgdHJhbnNmb3JtZXI6CiAgICAgIHR5cGU6IGpzb24tcGF0Y2gKICAgICAgdmVyc2lvbjogdjEKICAgICAgcGFyYW1ldGVyczoKICAgICAgICBwYXRjaDogfAogICAgICAgICAgWwogICAgICAgICAgICB7CiAgICAgICAgICAgICAgIm9wIjogImFkZCIsCiAgICAgICAgICAgICAgInBhdGgiOiAiL21vZGVsIiwKICAgICAgICAgICAgICAidmFsdWUiOiAiZ3B0LTRvLW1pbmkiCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAib3AiOiAiYWRkIiwKICAgICAgICAgICAgICAicGF0aCI6ICIvbWVzc2FnZXMiLAogICAgICAgICAgICAgICJ2YWx1ZSI6IFsKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgInJvbGUiOiAidXNlciIsCiAgICAgICAgICAgICAgICAgICJjb250ZW50IjogWwogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICJ0eXBlIjogInRleHQiLAogICAgICAgICAgICAgICAgICAgICAgInRleHQiOiAiV2hhdCdzIGluIHRoaXMgaW1hZ2U/IgogICAgICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgInR5cGUiOiAiaW1hZ2VfdXJsIiwKICAgICAgICAgICAgICAgICAgICAgICJpbWFnZV91cmwiOiB7CiAgICAgICAgICAgICAgICAgICAgICAgICJ1cmwiOiAiIgogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgXQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIF0KICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICJvcCI6ICJtb3ZlIiwKICAgICAgICAgICAgICAiZnJvbSI6ICIvaW1hZ2UiLAogICAgICAgICAgICAgICJwYXRoIjogIi9tZXNzYWdlcy8wL2NvbnRlbnQvMS9pbWFnZV91cmwvdXJsIgogICAgICAgICAgICB9LAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgIm9wIjogInJlbW92ZSIsCiAgICAgICAgICAgICAgInBhdGgiOiAiL2ltYWdlIgogICAgICAgICAgICB9CiAgICAgICAgICBdCiAgLSBuYW1lOiBleHBsYWluCiAgICB0cmFuc2Zvcm1lcjoKICAgICAgdHlwZTogd2ViaG9vawogICAgICB2ZXJzaW9uOiB2MQogICAgICBwYXJhbWV0ZXJzOgogICAgICAgIHVybDogaHR0cHM6Ly9hcGkub3BlbmFpLmNvbS92MS9jaGF0L2NvbXBsZXRpb25zCiAgICAgICAgaGVhZGVyczoKICAgICAgICAgIEF1dGhvcml6YXRpb246ICRPUEVOQUlfVE9LRU4KICAtIG5hbWU6IHBhcnNlLXBheWxvYWQKICAgIHRyYW5zZm9ybWVyOgogICAgICB0eXBlOiBqc29uLXBhdGNoCiAgICAgIHZlcnNpb246IHYxCiAgICAgIHBhcmFtZXRlcnM6CiAgICAgICAgcGF0Y2g6IHwKICAgICAgICAgIFsKICAgICAgICAgICAgeyJvcCI6ICJhZGQiLCAicGF0aCI6ICIvdGV4dCIsICJ2YWx1ZSI6ICIifSwKICAgICAgICAgICAgeyJvcCI6ICJtb3ZlIiwgImZyb20iOiAiL2Nob2ljZXMvMC9tZXNzYWdlL2NvbnRlbnQiLCAicGF0aCI6ICIvdGV4dCJ9CiAgICAgICAgICBdICAKICAtIG5hbWU6IHNlbmQtd2ViaG9vawogICAgZGVzdGluYXRpb246CiAgICAgIHR5cGU6IHdlYmhvb2sKICAgICAgdmVyc2lvbjogdjEKICAgICAgcGFyYW1ldGVyczoKICAgICAgICB1cmw6ICRTTEFDS19XRUJIT09L' />
24 changes: 24 additions & 0 deletions docs/data-routing/5-examples/21-anthropic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: Anthropic
---
import Pipeline from '@site/src/components/usethispipeline'

[Anthropic](https://www.anthropic.com/) is a platform that aims to build
frontier AI systems that are reliable, interpretable, and steerable. Anthropic's
models are provided via [Claude](https://www.anthropic.com/claude), an AI system
that is capable of advanced reasoning, vision analysis, code generation, and
more.

The following example demonstrates a simple chat interaction with Claude, in
which a text payload from a device is used as a prompt for the [Claude 3.5
Sonnet model](https://docs.anthropic.com/en/docs/about-claude/models). The
resulting chat answer is delivered to [LightDB
Stream](/application-services/lightdb-stream) as a JSON object.

:::info Reminder
Make sure to create a [secret](/data-routing/secrets) named `ANTHROPIC_API_KEY`
with a valid [API
key](https://docs.anthropic.com/en/api/getting-started#authentication).
:::

<Pipeline link='https://console.golioth.io/pipeline?name=Anthropic%20Assistant&pipeline=ZmlsdGVyOgogIHBhdGg6ICIvYXNzaXN0YW50IgpzdGVwczoKICAtIG5hbWU6IGVtYmVkCiAgICB0cmFuc2Zvcm1lcjoKICAgICAgdHlwZTogZW1iZWQtaW4tanNvbgogICAgICB2ZXJzaW9uOiB2MQogICAgICBwYXJhbWV0ZXJzOgogICAgICAgIGtleTogdGV4dAogIC0gbmFtZTogY3JlYXRlLXBheWxvYWQKICAgIHRyYW5zZm9ybWVyOgogICAgICB0eXBlOiBqc29uLXBhdGNoCiAgICAgIHZlcnNpb246IHYxCiAgICAgIHBhcmFtZXRlcnM6CiAgICAgICAgcGF0Y2g6IHwKICAgICAgICAgIFsKICAgICAgICAgICAgewogICAgICAgICAgICAgICJvcCI6ICJhZGQiLAogICAgICAgICAgICAgICJwYXRoIjogIi9tb2RlbCIsCiAgICAgICAgICAgICAgInZhbHVlIjogImNsYXVkZS0zLTUtc29ubmV0LTIwMjQwNjIwIgogICAgICAgICAgICB9LAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgIm9wIjogImFkZCIsCiAgICAgICAgICAgICAgInBhdGgiOiAiL21heF90b2tlbnMiLAogICAgICAgICAgICAgICJ2YWx1ZSI6IDEwMjQKICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICJvcCI6ICJhZGQiLAogICAgICAgICAgICAgICJwYXRoIjogIi9tZXNzYWdlcyIsCiAgICAgICAgICAgICAgInZhbHVlIjogWwogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAicm9sZSI6ICJ1c2VyIiwKICAgICAgICAgICAgICAgICAgImNvbnRlbnQiOiAiUkVQTEFDRU1FIgogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIF0KICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICJvcCI6ICJtb3ZlIiwKICAgICAgICAgICAgICAiZnJvbSI6ICIvdGV4dCIsCiAgICAgICAgICAgICAgInBhdGgiOiAiL21lc3NhZ2VzLzAvY29udGVudCIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICJvcCI6ICJyZW1vdmUiLAogICAgICAgICAgICAgICJwYXRoIjogIi90ZXh0IgogICAgICAgICAgICB9CiAgICAgICAgICBdCiAgLSBuYW1lOiBjaGF0CiAgICB0cmFuc2Zvcm1lcjoKICAgICAgdHlwZTogd2ViaG9vawogICAgICB2ZXJzaW9uOiB2MQogICAgICBwYXJhbWV0ZXJzOgogICAgICAgIHVybDogaHR0cHM6Ly9hcGkuYW50aHJvcGljLmNvbS92MS9tZXNzYWdlcwogICAgICAgIGhlYWRlcnM6CiAgICAgICAgICB4LWFwaS1rZXk6ICRBTlRIUk9QSUNfQVBJX0tFWQogICAgICAgICAgYW50aHJvcGljLXZlcnNpb246ICIyMDIzLTA2LTAxIgogIC0gbmFtZTogcGFyc2UtcGF5bG9hZAogICAgdHJhbnNmb3JtZXI6CiAgICAgIHR5cGU6IGpzb24tcGF0Y2gKICAgICAgdmVyc2lvbjogdjEKICAgICAgcGFyYW1ldGVyczoKICAgICAgICBwYXRjaDogfAogICAgICAgICAgWwogICAgICAgICAgICB7Im9wIjogImFkZCIsICJwYXRoIjogIi9hbnN3ZXIiLCAidmFsdWUiOiAiIn0sCiAgICAgICAgICAgIHsib3AiOiAibW92ZSIsICJmcm9tIjogIi9jb250ZW50LzAvdGV4dCIsICJwYXRoIjogIi9hbnN3ZXIifSwKICAgICAgICAgICAgeyJvcCI6ICJyZW1vdmUiLCAicGF0aCI6ICIvY29udGVudCJ9LAogICAgICAgICAgICB7Im9wIjogInJlbW92ZSIsICJwYXRoIjogIi9pZCJ9LAogICAgICAgICAgICB7Im9wIjogInJlbW92ZSIsICJwYXRoIjogIi90eXBlIn0sCiAgICAgICAgICAgIHsib3AiOiAicmVtb3ZlIiwgInBhdGgiOiAiL3JvbGUifSwKICAgICAgICAgICAgeyJvcCI6ICJyZW1vdmUiLCAicGF0aCI6ICIvc3RvcF9yZWFzb24ifSwKICAgICAgICAgICAgeyJvcCI6ICJyZW1vdmUiLCAicGF0aCI6ICIvc3RvcF9zZXF1ZW5jZSJ9LAogICAgICAgICAgICB7Im9wIjogInJlbW92ZSIsICJwYXRoIjogIi91c2FnZSJ9CiAgICAgICAgICBdICAKICAgIGRlc3RpbmF0aW9uOgogICAgICB0eXBlOiBsaWdodGRiLXN0cmVhbQogICAgICB2ZXJzaW9uOiB2MQ==' />
5 changes: 5 additions & 0 deletions docs/data-routing/5-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The best way to get started with Pipelines is to take an example and modify it
to fit your use case. This section contains a set of example pipelines along
with explanations of their functionality.

:::usage
Many examples incur usage costs after exceeding the free tier. See [Golioth
pricing](https://golioth.io/pricing) for more information.
:::

## Share Your Pipelines

You can click the share button next to a pipeline in the console to copy a
Expand Down

0 comments on commit 626301c

Please sign in to comment.