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 @@