Skip to content

Commit

Permalink
chore: first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmaynes committed Nov 21, 2023
0 parents commit 757303f
Show file tree
Hide file tree
Showing 73 changed files with 8,171 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI

on:
push:
branches:
- main

jobs:
deploy:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: "0"
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: "yarn"
- name: 🚀 Deploy 🚀
run: make deploy
env:
API_HOST: ${{ secrets.API_HOST }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Macos
.DS_Store

# Editors
.vscode/
.idea/
.fleet/

# Node
node_modules/
25 changes: 25 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) 2023 TJ Maynes. <tj@tjmaynes.com>

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
install:
yarn install
cd e2e && make install

dev_api:
cd api && make dev

dev_web:
cd web && make dev

start_api:
cd api && make start

start_web:
cd web && make start

start:
yarn $@

dev:
yarn $@

.PHONY: e2e
e2e:
cd e2e && make test

deploy: install e2e
cd api && make $@
cd web && make $@
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Image Analyzer App

> a monorepo for a web app that analyzes images using MobileNet (in-browser) and ChatGPT (Cloudflare Workers)
## Requirements

- [GNU Make](https://www.gnu.org/software/make)
- [Nodejs](https://nodejs.org/en/)
- [Yarn](https://yarnpkg.com/)

## Usage

To install project dependencies, run the following command:
```bash
make install
```

To start the application, run the following command:
```bash
make start
```

To run `e2e` tests, run the following command:
```bash
make e2e
```

To deploy the application, run the following command:
```bash
make deploy
```
1 change: 1 addition & 0 deletions api/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# src/**/*.spec.ts
24 changes: 24 additions & 0 deletions api/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"env": {
"browser": true,
"node": true,
"es2021": true,
"jest": true
},
"ignorePatterns": ["node_modules"],
"overrides": [
{
"files": ["src/**/*.spec.ts"],
"rules": {
"@typescript-eslint/no-unused-vars": "off"
}
}
]
}
29 changes: 29 additions & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
.idea/
.fleet/

# Cloudflare
.*.vars
1 change: 1 addition & 0 deletions api/.node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
7 changes: 7 additions & 0 deletions api/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tabWidth": 2,
"printWidth": 80,
"singleQuote": true,
"trailingComma": "es5",
"semi": false
}
2 changes: 2 additions & 0 deletions api/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nodejs 18.0.0
direnv 2.32.1
23 changes: 23 additions & 0 deletions api/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
start:
yarn $@

dev:
yarn $@

test:
yarn $@

lint:
yarn $@

fix:
yarn lint:$@

logs:
yarn $@

deploy: lint test
yarn $@

ship_it: lint test
git push
52 changes: 52 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# API

> an api for talking to ChatGPT
## Requirements

- [GNU Make](https://www.gnu.org/software/make)
- [Nodejs](https://nodejs.org/en/)
- [Yarn](https://yarnpkg.com/)

## Usage

To install project dependencies, run the following command:

```bash
make install
```

To run all tests, run the following command:

```bash
make test
```

To start the application, run the following command:

```bash
make start
```

To work on the application, run the following command:

```bash
make dev
```

To deploy the application, run the following command:

```bash
make deploy
```

## Notes

To test `POST /conversation`, run the following command:

```bash
curl -v \
-H 'Content-Type: application/json' \
-d '{"context":"some-context"}' \
http://localhost:8081/conversation
```
5 changes: 5 additions & 0 deletions api/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"preset": "ts-jest",
"testEnvironment": "miniflare",
"testMatch": ["**/src/**/(*.)+(spec|test).+(ts|tsx)"]
}
41 changes: 41 additions & 0 deletions api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "image-analyzer-api",
"private": true,
"version": "0.0.0",
"scripts": {
"deploy": "wrangler publish src/index.ts",
"dev": "wrangler dev --local",
"start": "WRANGLER_SEND_METRICS=false wrangler dev src/index.ts --experimental-local",
"test": "jest",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"logs": "wrangler tail"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230115.0",
"@types/jest": "^29.4.0",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"esbuild": "^0.17.6",
"esbuild-jest": "^0.5.0",
"eslint": "^8.33.0",
"eslint-config-node": "^4.1.0",
"eslint-config-prettier": "^8.6.0",
"eslint-config-typescript": "^3.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.4.2",
"jest-environment-miniflare": "^2.11.0",
"miniflare": "^2.11.0",
"prettier": "^2.8.3",
"ts-jest": "^29.0.5",
"ts-results": "^3.3.0",
"typescript": "^4.9.5",
"wrangler": "^2.1.14"
},
"dependencies": {
"@hono/graphql-server": "^0.2.0",
"hono": "^2.7.6",
"openai-edge": "^0.2.2"
}
}
11 changes: 11 additions & 0 deletions api/src/bindings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { KVNamespace } from '@cloudflare/workers-types'

export interface Bindings {
ORIGINS: string
OPENAI_API_KEY: string
IMAGE_ANALYZER_DB: KVNamespace
}

declare global {
function getMiniflareBindings(): Bindings
}
Loading

0 comments on commit 757303f

Please sign in to comment.