diff --git a/README.md b/README.md index f085a82..bdbbd4c 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,11 @@ configure environment variables cp .env.example .env.local ``` +configure database +```sh +cp config/database.yml.example config/database.yml +``` + fire up the app ```sh docker-compose up --build @@ -85,6 +90,8 @@ Right now the only authentication method supported is Google Oauth. You'll need If you're using Marqo, make sure to set the `MARQO_URL` environment variable, otherwise the `MemoryAnnotator` will not run. +You can use the `docker-compose.yml.marqo.example` docker-compose configuration to get marqo propped up with everything else. If you do this, you can set `MARQO_URL=http://host.docker.internal:8882` + ### Admin User Admin privileges are granted simply with the `admin` boolean attribute on `User`. There is no admin UI at the moment, so if you want to give your user admin rights, do it via the console. diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 5d7ed60..9ab7c1f 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -9,7 +9,7 @@ def create # todo: should we do this everytime? calendar = service.get_calendar('primary') - user.update!(time_zone: calendar.time_zone.split('/').last.gsub('_', ' ')) + user.update!(time_zone: calendar.time_zone) redirect_to "/conversations", notice: "Signed in!" end diff --git a/app/models/conversation.rb b/app/models/conversation.rb index 7544a12..e3ee83a 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -116,10 +116,6 @@ def summary analysis[:summary] end - def tags - analysis[:tags] || [] - end - def total_token_count messages.sum(:tokens_count) end diff --git a/app/services/marqo.rb b/app/services/marqo.rb index f2cad46..aebce89 100644 --- a/app/services/marqo.rb +++ b/app/services/marqo.rb @@ -15,6 +15,9 @@ class Marqo base_uri ENV.fetch('MARQO_URL') + class IndexNotFound < StandardError + end + class SearchResult < RecursiveOpenStruct end @@ -23,8 +26,25 @@ def initialize(auth = { username: 'admin', password: 'admin' }) @auth = auth end + def create(index:, model: "hf/all_datasets_v4_MiniLM-L6") + puts + puts "🧠🧠🧠 CREATING INDEX: #{index} 🧠🧠🧠" + puts + options = { + headers: { 'Content-Type' => 'application/json' }, + body: { index_defaults: { model: model } }.to_json + } + url = "/indexes/#{index.to_s.parameterize}" + self.class.post(url, options).then do |response| + puts response + end + end + def store(index:, doc:, id:, non_tensor_fields: []) return if ENV['MARQO_URL'].blank? + + create_index_attempts ||= 0 + puts puts "🧠🧠🧠 INDEX: #{index} 🧠🧠🧠" puts "🧠🧠🧠 DOC: #{doc} 🧠🧠🧠" @@ -42,8 +62,16 @@ def store(index:, doc:, id:, non_tensor_fields: []) end self.class.post(url, options).then do |response| puts response + raise IndexNotFound if response["type"].to_s == "invalid_request" && response["code"].to_s == "index_not_found" response.dig("items",0,"_id") end + rescue IndexNotFound + create_index_attempts += 1 + + if create_index_attempts < 2 + create(index: index) + retry + end end def search(index_name, query, filter: nil, limit: 5) diff --git a/app/views/conversations/new.html.erb b/app/views/conversations/new.html.erb index fddf308..57a1571 100644 --- a/app/views/conversations/new.html.erb +++ b/app/views/conversations/new.html.erb @@ -9,7 +9,8 @@
" data-placeholder="<%= it("Start a new conversation with #{bot.name.force_encoding("UTF-8")}") %>" - data-hello="<%= hello_in_user_language&.force_encoding("UTF-8") %>"> + data-hello="<%= hello_in_user_language&.force_encoding("UTF-8") %>" + data-controller="botselect" data-action="click->botselect#select">
<%= image_tag bot.image_url, class: "object-fit" %>
diff --git a/docker-compose.yml.example b/docker-compose.yml.example index 26fc047..e73f454 100644 --- a/docker-compose.yml.example +++ b/docker-compose.yml.example @@ -76,6 +76,7 @@ services: volumes: + app: null redis-data: null pg-data: null diff --git a/docker-compose.yml.marqo.example b/docker-compose.yml.marqo.example new file mode 100644 index 0000000..8d5eb80 --- /dev/null +++ b/docker-compose.yml.marqo.example @@ -0,0 +1,99 @@ +version: "3" + +x-app: &default-app + build: + context: "." + dockerfile: Dockerfile + depends_on: + redis: + condition: service_healthy + db: + condition: service_healthy + env_file: + - .env.local + tty: true + volumes: + - .:/rails + +x-assets: &default-assets + build: + context: "." + dockerfile: Dockerfile + env_file: + - .env.local + tty: true + volumes: + - .:/rails + entrypoint: [] + ports: [] + +services: + marqoai: + image: marqoai/marqo:latest + privileged: true + ports: + - '8882:8882' + volumes: + - 'vector-data:/data' + networks: + default: + + redis: + image: redis + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 5s + timeout: 5s + retries: 5 + command: redis-server --requirepass password + ports: + - '6380:6379' + volumes: + - 'redis-data:/data' + networks: + default: + + db: + image: postgres:15 + healthcheck: + test: ["CMD-SHELL", "pg_isready -U rails"] + interval: 5s + timeout: 5s + retries: 5 + ports: + - "5433:5432" + restart: always + environment: + - POSTGRES_USER=rails + - POSTGRES_PASSWORD=password + - POSTGRES_HOST_AUTH_METHOD=trust + volumes: + - 'pg-data:/var/lib/postgresql/data' + - './db/development.sql:/docker-entrypoint-initdb.d/setup.sql' + networks: + default: + + web: + <<: *default-app + privileged: true + depends_on: + - marqoai + ports: + - "3000:3000" + networks: + default: + + css: + <<: *default-assets + command: bin/rails tailwindcss:watch + + +volumes: + app: null + redis-data: null + pg-data: null + vector-data: null + +networks: + default: + driver: bridge