Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize setup #73

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Author

@codenamev codenamev Aug 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I signed up, my time zone was pulling from Google's APIs in the railsy formatAmerica/New_York. Setting it with the spaces as it is throws an error downstream when trying to use_zone


redirect_to "/conversations", notice: "Signed in!"
end
Expand Down
4 changes: 0 additions & 4 deletions app/models/conversation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ def summary
analysis[:summary]
end

def tags
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was maybe missed in conflict resolution, but there's a duplicate method that handles an edge case better.

analysis[:tags] || []
end

def total_token_count
messages.sum(:tokens_count)
end
Expand Down
28 changes: 28 additions & 0 deletions app/services/marqo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class Marqo

base_uri ENV.fetch('MARQO_URL')

class IndexNotFound < StandardError
end

class SearchResult < RecursiveOpenStruct
end

Expand All @@ -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} 🧠🧠🧠"
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion app/views/conversations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<div class="card flex cursor-pointer border-4 px-4 w-full items-center xl:items-end relative"
data-id="<%= bot.id %>" data-name="<%= bot.name&.force_encoding("UTF-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">
<div class="max-w-[140px]">
<%= image_tag bot.image_url, class: "object-fit" %>
</div>
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ services:


volumes:
app: null
redis-data: null
pg-data: null

Expand Down
99 changes: 99 additions & 0 deletions docker-compose.yml.marqo.example
Original file line number Diff line number Diff line change
@@ -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