Skip to content

Commit

Permalink
Chore/disable submodule (janhq#56)
Browse files Browse the repository at this point in the history
* Chore disable git submodule for web-client and app-backend

* Chore add newest source code of app-backend and web-client

---------

Co-authored-by: Hien To <[email protected]>
  • Loading branch information
hiento09 and hiento09 authored Sep 5, 2023
1 parent 3826e30 commit 86f0ffc
Show file tree
Hide file tree
Showing 282 changed files with 17,895 additions and 8 deletions.
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
[submodule "web-client"]
path = web-client
url = ../jan-web.git
[submodule "app-backend"]
path = app-backend
url = ../app-backend.git
[submodule "jan-inference/sd/sd_cpp"]
path = jan-inference/sd/sd_cpp
url = https://github.com/leejet/stable-diffusion.cpp
1 change: 0 additions & 1 deletion app-backend
Submodule app-backend deleted from 4c44ef
4 changes: 4 additions & 0 deletions app-backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
.env
.env_postgresql
worker/node_modules/.mf
59 changes: 59 additions & 0 deletions app-backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
## Jan Backend

A Hasura Data API Platform designed to provide APIs for client interaction with the Language Model (LLM) through chat or the generation of art using Stable Diffusion. It is encapsulated within a Docker container for easy local deployment

## Quickstart
1. Run docker up

```bash
docker compose up
```

2. Install [HasuraCLI](https://hasura.io/docs/latest/hasura-cli/overview/)

3. Open Hasura Console

```bash
cd hasura && hasura console
```

4. Apply Migration

```bash
hasura migrate apply
```

5. Apply Metadata

```bash
hasura metadata apply
```

6. Apply seeds

```bash
hasura seed apply
```

## Hasura One Click Deploy
Use this URL to deploy this app to Hasura Cloud

[![Hasura Deploy](https://hasura.io/deploy-button.svg)](https://cloud.hasura.io/deploy?github_repo=https://github.com/janhq/app-backend/&hasura_dir=/hasura)

[One-click deploy docs](https://hasura.io/docs/latest/getting-started/getting-started-cloud/)

## Modify schema & model
[Hasura Tutorials](https://hasura.io/docs/latest/resources/tutorials/index/)

## Events & Workers

Serverless function (Cloudflare worker) to stream llm message & update

Readmore about Hasura Events here:
> https://hasura.io/docs/latest/event-triggers/serverless/
## Deploy Worker
```bash
npx wrangler deploy
```
[Cloudflare Worker Guide](https://developers.cloudflare.com/workers/get-started/guide/)
52 changes: 52 additions & 0 deletions app-backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: "3.6"
services:
postgres:
image: postgres:13
restart: always
volumes:
- db_data:/var/lib/postgresql/data
env_file:
- .env_postgresql
graphql-engine:
image: hasura/graphql-engine:v2.31.0.cli-migrations-v3
ports:
- "8080:8080"
restart: always
env_file:
- .env
volumes:
- ./hasura/migrations:/migrations
- ./hasura/metadata:/metadata
depends_on:
data-connector-agent:
condition: service_healthy

data-connector-agent:
image: hasura/graphql-data-connector:v2.31.0
restart: always
ports:
- 8081:8081
environment:
QUARKUS_LOG_LEVEL: ERROR # FATAL, ERROR, WARN, INFO, DEBUG, TRACE
## https://quarkus.io/guides/opentelemetry#configuration-reference
QUARKUS_OPENTELEMETRY_ENABLED: "false"
## QUARKUS_OPENTELEMETRY_TRACER_EXPORTER_OTLP_ENDPOINT: http://jaeger:4317
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8081/api/v1/athena/health"]
interval: 5s
timeout: 10s
retries: 5
start_period: 5s
worker:
build:
context: ./worker
dockerfile: ./Dockerfile
restart: always
environment:
- "NODE_ENV=development"
volumes:
- ./worker:/worker
ports:
- "8787:8787"
volumes:
db_data:
7 changes: 7 additions & 0 deletions app-backend/hasura/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 3
endpoint: http://localhost:8080
admin_secret: myadminsecretkey
metadata_directory: metadata
actions:
kind: synchronous
handler_webhook_baseurl: http://localhost:3000
20 changes: 20 additions & 0 deletions app-backend/hasura/metadata/actions.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
type Mutation {
imageGeneration(
input: ImageGenerationInput!
): ImageGenerationOutput
}

input ImageGenerationInput {
prompt: String!
neg_prompt: String!
model: String!
seed: Int!
steps: Int!
width: Int!
height: Int!
}

type ImageGenerationOutput {
url: String!
}

32 changes: 32 additions & 0 deletions app-backend/hasura/metadata/actions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
actions:
- name: imageGeneration
definition:
kind: synchronous
handler: '{{HASURA_ACTION_STABLE_DIFFUSION_URL}}'
request_transform:
body:
action: transform
template: |-
{
"prompt": {{$body.input.input.prompt}},
"neg_prompt": {{$body.input.input.neg_prompt}},
"unet_model": {{$body.input.input.model}},
"seed": {{$body.input.input.seed}},
"steps": {{$body.input.input.steps}},
"width": {{$body.input.input.width}},
"height": {{$body.input.input.height}}
}
method: POST
query_params: {}
template_engine: Kriti
url: '{{$base_url}}/inferences/txt2img'
version: 2
permissions:
- role: user
custom_types:
enums: []
input_objects:
- name: ImageGenerationInput
objects:
- name: ImageGenerationOutput
scalars: []
1 change: 1 addition & 0 deletions app-backend/hasura/metadata/allow_list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions app-backend/hasura/metadata/api_limits.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
11 changes: 11 additions & 0 deletions app-backend/hasura/metadata/backend_configs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dataconnector:
athena:
uri: http://data-connector-agent:8081/api/v1/athena
mariadb:
uri: http://data-connector-agent:8081/api/v1/mariadb
mysql8:
uri: http://data-connector-agent:8081/api/v1/mysql
oracle:
uri: http://data-connector-agent:8081/api/v1/oracle
snowflake:
uri: http://data-connector-agent:8081/api/v1/snowflake
1 change: 1 addition & 0 deletions app-backend/hasura/metadata/cron_triggers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
9 changes: 9 additions & 0 deletions app-backend/hasura/metadata/databases/databases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- name: jandb
kind: postgres
configuration:
connection_info:
database_url:
from_env: PG_DATABASE_URL
isolation_level: read-committed
use_prepared_statements: false
tables: "!include jandb/tables/tables.yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
table:
name: collection_products
schema: public
array_relationships:
- name: collections
using:
manual_configuration:
column_mapping:
collection_id: id
insertion_order: null
remote_table:
name: collections
schema: public
- name: products
using:
manual_configuration:
column_mapping:
product_id: id
insertion_order: null
remote_table:
name: products
schema: public
select_permissions:
- role: public
permission:
columns:
- created_at
- updated_at
- collection_id
- id
- product_id
filter: {}
comment: ""
- role: user
permission:
columns:
- created_at
- updated_at
- collection_id
- id
- product_id
filter: {}
comment: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
table:
name: collections
schema: public
array_relationships:
- name: collection_products
using:
manual_configuration:
column_mapping:
id: collection_id
insertion_order: null
remote_table:
name: collection_products
schema: public
select_permissions:
- role: public
permission:
columns:
- slug
- description
- name
- created_at
- updated_at
- id
filter: {}
comment: ""
- role: user
permission:
columns:
- slug
- description
- name
- created_at
- updated_at
- id
filter: {}
comment: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
table:
name: conversations
schema: public
object_relationships:
- name: conversation_product
using:
manual_configuration:
column_mapping:
product_id: id
insertion_order: null
remote_table:
name: products
schema: public
array_relationships:
- name: conversation_messages
using:
manual_configuration:
column_mapping:
id: conversation_id
insertion_order: null
remote_table:
name: messages
schema: public
insert_permissions:
- role: user
permission:
check:
user_id:
_eq: X-Hasura-User-Id
columns:
- last_image_url
- last_text_message
- product_id
- user_id
comment: ""
select_permissions:
- role: user
permission:
columns:
- last_image_url
- last_text_message
- user_id
- created_at
- updated_at
- id
- product_id
filter:
user_id:
_eq: X-Hasura-User-Id
comment: ""
update_permissions:
- role: user
permission:
columns:
- last_image_url
- last_text_message
filter:
user_id:
_eq: X-Hasura-User-Id
check: null
comment: ""
delete_permissions:
- role: user
permission:
filter:
user_id:
_eq: X-Hasura-User-Id
comment: ""
Loading

0 comments on commit 86f0ffc

Please sign in to comment.