Skip to content

Commit

Permalink
Helper scripts to set the REACT_APP environment variables (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdbartholomew committed Oct 19, 2023
1 parent 254a09a commit 9d31239
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/applications/chatbot-rag-memory/chatbot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pipeline:
messages:
- role: system
content: |
You are a conversational intepreter for a converstation between a user and
You are a conversational interpreter for a conversation between a user and
a bot who is an expert on ${globals.assistantType}.
The user will give you a question without context. You will reformulate the question
Expand All @@ -111,7 +111,7 @@ pipeline:
When reformulating the question give higher value to the latest question and response
in the Chat History. The chat history is in reverse chronological order, so the most
recent exhange is at the top.
recent exchange is at the top.
Only respond with the reformulated question. If there is no chat history, then respond
only with the question unchanged.
Expand Down
18 changes: 18 additions & 0 deletions examples/applications/react-chatbot-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ export REACT_APP_CREDENTIALS=..
```
or add your app details to `config.ts`

You can use a helper script to get the environment variable settings from the langstream CLI output. To get some of the env vars from the current profile, use this command:

```
langstream profiles get `langstream profiles get-current` -o yaml | ./get-env-vars-from-profile.sh
```

You can copy and paste the results into your terminal.

To get some of the env vars from the application, use this command:

```
langstream apps get <app-name> -o yaml | ./get-env-vars-from-app.sh
```

Again, copy and paste the results in your terminal.

These scripts will give you commands for all environment variables except `REACT_APP_CREDENTIALS`. You will have to set that manually.

## Run

```
Expand Down
37 changes: 37 additions & 0 deletions examples/applications/react-chatbot-ui/get-env-vars-from-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
#
# 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.
#


# Receive YAML output from a pipe
YAML_OUTPUT=$(cat)

# Extract necessary values
APP=$(echo "$YAML_OUTPUT" | grep "application-id" | awk '{print $2}' | tr -d '"')

# Extract IDs for CONSUMER and PRODUCER based on the type
CONSUMER=$(echo "$YAML_OUTPUT" | awk '/- id: / {id=$3} /type: "consume"/ {print id}' | tr -d '"')
PRODUCER=$(echo "$YAML_OUTPUT" | awk '/- id: / {id=$3} /type: "produce"/ {print id}' | tr -d '"')

# Set environment variables
export REACT_APP_APP=$APP
export REACT_APP_CONSUMER=$CONSUMER
export REACT_APP_PRODUCER=$PRODUCER

# Print environment variables
echo "export REACT_APP_APP=$REACT_APP_APP"
echo "export REACT_APP_CONSUMER=$REACT_APP_CONSUMER"
echo "export REACT_APP_PRODUCER=$REACT_APP_PRODUCER"
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
#
# 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.
#


# Receive YAML output from a pipe
YAML_OUTPUT=$(cat)

# Extract necessary values
WEBSOCKET_URL=$(echo "$YAML_OUTPUT" | grep "apiGatewayUrl:" | awk '{print $2}' | tr -d '"')
TENANT=$(echo "$YAML_OUTPUT" | grep "tenant:" | awk '{print $2}' | tr -d '"')
CREDENTIALS=$(echo "$YAML_OUTPUT" | grep "token:" | awk '{print $2}' | tr -d '"')

# Set environment variables
export REACT_APP_WEBSOCKET_URL=$WEBSOCKET_URL
export REACT_APP_TENANT=$TENANT
export REACT_APP_CREDENTIALS=$CREDENTIALS

# Print environment variables
echo "export REACT_APP_WEBSOCKET_URL=$REACT_APP_WEBSOCKET_URL"
echo "export REACT_APP_TENANT=$REACT_APP_TENANT"

0 comments on commit 9d31239

Please sign in to comment.