From 7d320494f857f8d6bb1175deaa5a70cb027bf373 Mon Sep 17 00:00:00 2001 From: Chris Bartholomew Date: Sun, 21 Jan 2024 16:57:35 -0500 Subject: [PATCH] =?UTF-8?q?Updating=20OpenAI=20embedding=20example=20to=20?= =?UTF-8?q?use=20gateways=20to=20work=20better=20with=E2=80=A6=20(#2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … docker run --- .../compute-openai-embeddings/README.md | 25 +++++++++++++++++++ .../compute-openai-embeddings/gateways.yaml | 21 ++++++++++++++++ .../compute-openai-embeddings/pipeline.yaml | 8 ++++-- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 examples/applications/compute-openai-embeddings/README.md create mode 100644 examples/applications/compute-openai-embeddings/gateways.yaml diff --git a/examples/applications/compute-openai-embeddings/README.md b/examples/applications/compute-openai-embeddings/README.md new file mode 100644 index 000000000..91b764d92 --- /dev/null +++ b/examples/applications/compute-openai-embeddings/README.md @@ -0,0 +1,25 @@ +# Computing text embeddings with Open AI + +This sample application shows how to use Open AI to compute text embeddings by calling the API. + +## Configure you OpenAI API Key + +Export to the ENV the access key to OpenAI + +``` +export OPEN_AI_ACCESS_KEY=... +``` + +## Deploy the LangStream application + +``` +./bin/langstream docker run test -app examples/applications/compute-openai-embeddings -s examples/secrets/secrets.yaml +``` + +## Talk with the Chat bot using the CLI +Since the application opens a gateway, we can use the gateway API to send and consume messages. + +``` +./bin/langstream gateway chat test -cg output -pg input -p sessionId=$(uuidgen) +``` + diff --git a/examples/applications/compute-openai-embeddings/gateways.yaml b/examples/applications/compute-openai-embeddings/gateways.yaml new file mode 100644 index 000000000..4802932be --- /dev/null +++ b/examples/applications/compute-openai-embeddings/gateways.yaml @@ -0,0 +1,21 @@ +gateways: + - id: "input" + type: produce + topic: "input-topic" + parameters: + - sessionId + produceOptions: + headers: + - key: langstream-client-session-id + valueFromParameters: sessionId + + - id: "output" + type: consume + topic: "output-topic" + parameters: + - sessionId + consumeOptions: + filters: + headers: + - key: langstream-client-session-id + valueFromParameters: sessionId \ No newline at end of file diff --git a/examples/applications/compute-openai-embeddings/pipeline.yaml b/examples/applications/compute-openai-embeddings/pipeline.yaml index 59019c114..e0a222050 100644 --- a/examples/applications/compute-openai-embeddings/pipeline.yaml +++ b/examples/applications/compute-openai-embeddings/pipeline.yaml @@ -25,15 +25,19 @@ topics: errors: on-failure: "skip" pipeline: + - name: "convert-to-structure" + input: "input-topic" + type: "document-to-json" + configuration: + text-field: "text" - name: "compute-embeddings" id: "step1" type: "compute-ai-embeddings" - input: "input-topic" output: "output-topic" configuration: model: "${secrets.open-ai.embeddings-model}" # This needs to match the name of the model deployment, not the base model embeddings-field: "value.embeddings" - text: "{{ value.name }} {{ value.description }}" + text: "{{ value.text }}" batch-size: 10 # this is in milliseconds. It is important to take this value into consideration when using this agent in the chat response pipeline # in fact this value impacts the latency of the response