Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
pom.xml
pom.xml.asc
*.jar
*.class
/lib/
*.jar
.cpcache/
.nrepl-port
/.shadow-cljs/
/checkouts/
/classes/
/lib/
/node_modules/
/resources/js/
/target/
/checkouts/
.lein-deps-sum
.lein-repl-history
.lein-plugins/
.lein-failures
.nrepl-port
.cpcache/
pom.xml
pom.xml.asc
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
# inferenceql.chat.webapp
# inferenceql.chat.webapp

![Stability: Experimental](https://img.shields.io/badge/stability-experimental-orange.svg)

## Prerequisites

- [pnpm](https://pnpm.io/installation)
- [clojure](https://clojure.org/guides/install_clojure)

## Usage

This tool requires that the environment variable `OPENAI_API_KEY` is set to an valid [OpenAI](https://openai.com/) API key. To retrieve an OpenAI API key [log in](https://platform.openai.com/login/) and visit the [API keys](https://platform.openai.com/account/api-keys) page.

Set the database and schema paths at the top of `src/user.clj`, then:

``` shell
pnpm install --shamefully-hoist
clj -A:dev
user=> (go)
```
18 changes: 18 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{:paths ["src" "resources" "target/classes"]
:deps {babashka/fs {:mvn/version "0.1.6"}
babashka/process {:mvn/version "0.1.2"}
com.stuartsierra/component {:mvn/version "1.1.0"}
io.github.inferenceql/inferenceql.query {:git/sha "775698d76b649e55c384021020c4418e67b0649f"}
io.github.inferenceql/inferenceql.chat {:git/sha "3bb17f53de713695955cf0c786d508e67ce295f5"}
lambdaisland/fetch {:mvn/version "1.0.41"}
lambdaisland/regal {:mvn/version "0.0.143"}
lilactown/helix {:mvn/version "0.1.7"}
metosin/reitit {:mvn/version "0.5.18"}
org.clojure/clojurescript {:mvn/version "1.11.60"}
ring/ring-jetty-adapter {:mvn/version "1.9.5"}
ring-middleware-format/ring-middleware-format {:mvn/version "0.7.5"}}
:aliases {:dev {:extra-paths ["dev"]
:extra-deps {io.github.clojure/tools.build {:git/tag "v0.8.3" :git/sha "0d20256"}
org.clojure/tools.namespace {:mvn/version "1.3.0"}
thheller/shadow-cljs {:mvn/version "2.20.2"}}}
:run {:exec-fn inferenceql.chat.webapp/run}}}
103 changes: 103 additions & 0 deletions dev/user.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
(ns user
(:require [clojure.string :as string]
[clojure.tools.namespace.repl :as repl]
[com.stuartsierra.component :as component]
[inferenceql.chat.webapp :as webapp]
[shadow.cljs.devtools.api :as shadow]
[shadow.cljs.devtools.server :as server]))

(def db-path "/Users/zane/projects/inferenceql.auto-modeling/data/db.edn")
(def schema-path "/Users/zane/projects/inferenceql.auto-modeling/data/schema.edn")

(defonce system nil)

(defn nilsafe
"Returns a function that calls f on its argument if its argument is not nil."
[f]
(fn [x]
(when x
(f x))))

(def db (delay (webapp/read-db db-path)))
(def schema (delay (webapp/read-schema schema-path)))

(defn distinct-values
[column rows]
(into #{}
(comp (map #(get % column))
(distinct)
(remove nil?)
(remove string/blank?))
rows))


(defn chat-schema
[db schema]
(let [[table-name rows] (-> db (:iql/tables) (first))]
{:table-name table-name
:model-name (-> db (:iql/models) (keys) (first))
:columns (into []
(comp (remove #(= :ignore (val %)))
(map (fn [[name type]]
(let [name (symbol name)
type (case type
:numerical "INT"
:nominal (str "ENUM("
(->> (distinct-values name rows)
(take 3)
(map pr-str)
(string/join ", " ))
")"))]
{:name name :type type}))))
schema)}))

(defn init
"Constructs the current development system."
[]
(server/start!)
(shadow/watch :app)
(alter-var-root #'system
(fn [_] (webapp/new-system
{:port 8080
:db @db
:schema (chat-schema @db @schema)}))))

(defn start
"Starts the current development system."
[]
(alter-var-root #'system component/start))

(defn stop
"Shuts down and destroys the current development system."
[]
(alter-var-root #'system (nilsafe component/stop)))

(defn go
"Initializes the current development system and starts it running."
[]
(init)
(start))

(defn reset []
(stop)
(shadow/watch-compile! :app)
(repl/refresh :after 'user/go))

(comment

(set! *print-level* 4)
(set! *print-length* 5)

(server/start!)
(server/stop!)
(shadow/watch :app)
(shadow/compile :app)

(go)
(reset)
(stop)
(start)

system

,)
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"dependencies": {
"@emotion/react": "^11.10.4",
"@inferenceql/inferenceql.react": "github:inferenceql/inferenceql.react#612ef41fb04cd9001d40fb86c1e87f2a7e5dc12c",
"@mantine/core": "^5.10.5",
"@mantine/form": "^5.1.6",
"@mantine/hooks": "^5.10.5",
"@mantine/styles": "^5.10.5",
"@mantine/utils": "^5.10.5",
"@tabler/icons": "^1.82.0",
"prop-types": "^15.8.1",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"@babel/core": "^7.19.3",
"esbuild": "^0.15.12",
"shadow-cljs": "^2.20.2"
}
}
Loading