Skip to content

Commit

Permalink
Cleanup examples (#14)
Browse files Browse the repository at this point in the history
* automated table of contents
* automated banner in each project README
* CI to catch broken examples
  • Loading branch information
Nicole White authored Oct 23, 2023
1 parent 4178754 commit 15d31e1
Show file tree
Hide file tree
Showing 26 changed files with 473 additions and 251 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OPENAI_API_KEY=
AUTOBLOCKS_INGESTION_KEY=
134 changes: 134 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: CI

on:
push:
schedule:
# Every day at ~7:17am Chicago time.
#
# Using a non-zero minute offset since GitHub Actions suggests
# running jobs at a random minute to avoid overloading their
# servers.
#
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
- cron: "17 12 * * *"

jobs:
test-table-of-contents-up-to-date:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20

- name: Make table of contents
run: node tools/make-toc.js

- name: Ensure table of contents is up to date
run: |
if [[ -n $(git status --porcelain) ]]; then
echo "::error::The table of contents is out of date. Please run 'node tools/make-toc.js' and commit the changes."
exit 1
else
echo "Table of contents is up to date!"
fi
test-python:
runs-on: ubuntu-latest

strategy:
matrix:
project:
- Python/langchain
- Python/openai-manual

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Create .env file
run: |
touch .env
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> .env
echo "AUTOBLOCKS_INGESTION_KEY=${{ secrets.AUTOBLOCKS_INGESTION_KEY }}" >> .env
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: 3.11

- name: Install poetry
run: curl -sSL https://install.python-poetry.org | python3 -

- name: Check pyproject.toml & poetry.lock are in sync
run: poetry lock --check
working-directory: ${{ matrix.project }}

- name: Install dependencies
run: poetry install
working-directory: ${{ matrix.project }}

- name: Run script
run: poetry run python main.py
working-directory: ${{ matrix.project }}

test-javascript:
runs-on: ubuntu-latest

strategy:
matrix:
project:
# - JavaScript/chatbot-nextjs
- JavaScript/langchain
# - JavaScript/novel-ai-text-editor
- JavaScript/openai-automated
- JavaScript/openai-manual

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Create .env file
run: |
touch .env
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> .env
echo "AUTOBLOCKS_INGESTION_KEY=${{ secrets.AUTOBLOCKS_INGESTION_KEY }}" >> .env
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20

- name: Install dependencies
run: npm ci
working-directory: ${{ matrix.project }}

- name: Run script
run: npm run start
working-directory: ${{ matrix.project }}

notify:
needs:
- test-python
- test-javascript

if: always() && contains(needs.*.result, 'failure') && github.event_name == 'schedule'

runs-on: ubuntu-latest

steps:
- uses: slackapi/[email protected]
with:
payload: |
{
"text": ":warning: Workflow `${{ github.workflow }}` in repository `${{ github.repository }}` failed. <${{ env.run-url }}|Logs>"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
53 changes: 26 additions & 27 deletions JavaScript/chatbot-nextjs/README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
<!-- banner start -->
<p align="center">
<img src="https://app.autoblocks.ai/images/logo.png" width="300px">
</p>

# Chatbot Autoblocks Example
<p align="center">
<a href="https://docs.autoblocks.ai/">Documentation</a>
|
<a href="https://app.autoblocks.ai/">Application</a>
|
<a href="https://www.autoblocks.ai/">Home</a>
</p>

## Quick Start
<p align="center">
:bangbang:
Make sure you've read the <a href="/README.md#getting-started">getting started</a> section in the main README.
</p>
<!-- banner end -->

Example chatbot using [Autoblocks](https://www.autoblocks.ai).
# Chatbot Example
This is a Next.js app that uses openai and Autoblocks to power and monitor a chatbot.

View deployed app at https://chatbot-example.autoblocks.ai
View the deployed application at https://chatbot-example.autoblocks.ai

### Install Dependencies
## Copy the root `.env` file to this directory

```bash
cp ../../.env .
```
npm install
```

### Sign up for Autoblocks

Sign up for an Autoblocks account at https://app.autoblocks.ai and grab your ingestion key from [settings](https://app.autoblocks.ai/settings/api-keys).

### Set environment variables
## Install dependencies

Create a `.env` file in the `chatbot-nextjs` directory with the following environment variables:

```
OPENAI_API_KEY=<your-api-key>
AUTOBLOCKS_INGESTION_KEY=<your-ingestion-key>
```bash
npm install
```

### Run the app
## Run the app

```
```bash
npm run dev
```

Visit http://localhost:3000 to see the app.

### View logs in Autoblocks
## View logs in Autoblocks

As you interact with the app, you will see traces appear in the Autoblocks explore page.
As you interact with the app, you will see traces appear in the Autoblocks [explore page](https://app.autoblocks.ai/explore).

![Autoblocks Explore](https://github.com/autoblocksai/novel-autoblocks-example/blob/main/novel-autoblocks-example.png?raw=true)

## More Information

For more information on how to use Autoblocks, visit the [Autoblocks documentation](https://docs.autoblocks.ai/).

For more information on how to use Novel, visit the [Novel repository](https://github.com/steven-tey/novel).
5 changes: 3 additions & 2 deletions JavaScript/chatbot-nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "autoblocks-examples",
"version": "0.1.0",
"name": "chatbot-nextjs",
"description": "A Next.js app that uses openai and Autoblocks to power and monitor a chatbot",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
40 changes: 16 additions & 24 deletions JavaScript/langchain/README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,34 @@
<!-- banner start -->
<p align="center">
<img src="https://app.autoblocks.ai/images/logo.png" width="300px">
</p>

# Langchain Autoblocks Example

Example using [Autoblocks](https://www.autoblocks.ai) and [Langchain JS](https://js.langchain.com/docs/get_started/introduction).
<p align="center">
<a href="https://docs.autoblocks.ai/">Documentation</a>
|
<a href="https://app.autoblocks.ai/">Application</a>
|
<a href="https://www.autoblocks.ai/">Home</a>
</p>

## Quick Start
<p align="center">
:bangbang:
Make sure you've read the <a href="/README.md#getting-started">getting started</a> section in the main README.
</p>
<!-- banner end -->

### Install Dependencies
## Install dependencies

```
npm install
```

### Sign up for Autoblocks

Sign up for an Autoblocks account at https://app.autoblocks.ai and grab your ingestion key from [settings](https://app.autoblocks.ai/settings/api-keys).

### Set environment variables

Create a `.env` file in this directory with the following environment variables:

```
OPENAI_API_KEY=<your-api-key>
AUTOBLOCKS_INGESTION_KEY=<your-ingestion-key>
```

### Run the script
## Run the script

```
npm run start
```

### View logs in Autoblocks
## View logs in Autoblocks

After you run the script, you can find the trace on the [explore page](https://app.autoblocks.ai/explore).

## More Information

For more information on how to use Autoblocks, visit the [Autoblocks documentation](https://docs.autoblocks.ai/).
5 changes: 3 additions & 2 deletions JavaScript/langchain/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "langchain-autoblocks-example",
"name": "langchain",
"description": "Automatic tracing of a LangChain pipeline",
"version": "0.0.0",
"private": true,
"engines": {
"node": ">=18"
},
"type": "module",
"scripts": {
"start": "dotenv -e .env -- node ./src/index.js"
"start": "dotenv -e ../../.env -- node ./src/index.js"
},
"author": "",
"license": "MIT",
Expand Down
44 changes: 23 additions & 21 deletions JavaScript/novel-ai-text-editor/README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
<!-- banner start -->
<p align="center">
<img src="https://app.autoblocks.ai/images/logo.png" width="300px">
</p>

# Novel Autoblocks Example
<p align="center">
<a href="https://docs.autoblocks.ai/">Documentation</a>
|
<a href="https://app.autoblocks.ai/">Application</a>
|
<a href="https://www.autoblocks.ai/">Home</a>
</p>

Example Next.js application using [Novel](https://github.com/steven-tey/novel) and [Autoblocks](https://www.autoblocks.ai).
<p align="center">
:bangbang:
Make sure you've read the <a href="/README.md#getting-started">getting started</a> section in the main README.
</p>
<!-- banner end -->

Based on [novella](https://github.com/steven-tey/novella).
# Novel Example

## Quick Start
Example Next.js application using [Novel](https://github.com/steven-tey/novel). Based on [novella](https://github.com/steven-tey/novella).

### Install Dependencies
## Copy the root `.env` file to this directory

```
npm install
```bash
cp ../../.env .
```

### Sign up for Autoblocks

Sign up for an Autoblocks account at https://app.autoblocks.ai and grab your ingestion key from [settings](https://app.autoblocks.ai/settings/api-keys).

### Set environment variables

Create a `.env.local` file in the root directory of the project with the following environment variables:
## Install Dependencies

```
OPENAI_API_KEY=<your-api-key>
AUTOBLOCKS_INGESTION_KEY=<your-ingestion-key>
npm install
```

### Run the app
## Run the app

```
npm run dev
```

Visit http://localhost:3000 to see the app.

### View logs in Autoblocks
## View logs in Autoblocks

As you interact with the app, you will see traces appear in the Autoblocks explore page.
As you interact with the app, you will see traces appear in the Autoblocks [explore page](https://app.autoblocks.ai/explore).

![Autoblocks Explore](https://github.com/autoblocksai/novel-autoblocks-example/blob/main/novel-autoblocks-example.png?raw=true)

## More Information

For more information on how to use Autoblocks, visit the [Autoblocks documentation](https://docs.autoblocks.ai/).

For more information on how to use Novel, visit the [Novel repository](https://github.com/steven-tey/novel).
5 changes: 3 additions & 2 deletions JavaScript/novel-ai-text-editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "novel-autoblocks-example",
"version": "0.1.0",
"name": "novel-ai-text-editor",
"description": "A Next.js app that uses [Novel](https://github.com/steven-tey/novel) and Autoblocks to power an AI-enabled text editor",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
Loading

1 comment on commit 15d31e1

@vercel
Copy link

@vercel vercel bot commented on 15d31e1 Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.