Skip to content

Commit

Permalink
Merge pull request #3 from chaskiq/gem-upgrade
Browse files Browse the repository at this point in the history
Gem upgrade
  • Loading branch information
michelson committed Aug 21, 2023
2 parents 3d704e7 + 6621c8e commit 01f72d8
Show file tree
Hide file tree
Showing 28 changed files with 560 additions and 153 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Rails Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2

- name: Build and test with Rake
env:
RAILS_ENV: test
run: |
gem install bundler
bundle install --jobs 4 --retry 3
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rails test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/test/dummy/log/*.log
/test/dummy/storage/
/test/dummy/tmp/
.env
36 changes: 36 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,47 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Specify your gem's dependencies in plain.gemspec.
gemspec

gem "pg"

gem "puma"

gem "sqlite3"

gem "sprockets-rails"

gem "turbo-rails"

# Start debugger with binding.b [https://github.com/ruby/debug]
# gem "debug", ">= 1.0.0"


group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
end

gem "ruby-openai", "~> 4.2"
gem "qdrant-ruby", "~> 0.9.2"

group :test do
gem 'mocha'
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver"
gem "webdrivers"
gem 'shoulda-matchers', '~> 5.0'
gem 'faker'
end

gem 'dotenv-rails', groups: [:development, :test]

group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"

# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
# gem "rack-mini-profiler"

# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end
72 changes: 69 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
PATH
remote: .
specs:
plain (0.1.0)
plain-rails (0.1.1)
coderay (~> 1.1)
front_matter_parser (~> 1.0.1)
langchainrb (~> 0.6.8)
langchainrb (~> 0.6.12)
qdrant-ruby (~> 0.9.2)
rails (>= 7.0.6)
redcarpet (~> 2.3.0)
Expand Down Expand Up @@ -81,13 +81,32 @@ GEM
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
baran (0.1.7)
bindex (0.8.1)
builder (3.2.4)
capybara (3.39.2)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
coderay (1.1.3)
colorize (0.8.1)
concurrent-ruby (1.2.2)
crass (1.0.6)
date (3.3.3)
debug (1.8.0)
irb (>= 1.5.0)
reline (>= 0.3.1)
dotenv (2.8.1)
dotenv-rails (2.8.1)
dotenv (= 2.8.1)
railties (>= 3.2)
erubi (1.12.0)
faker (3.2.1)
i18n (>= 1.8.11, < 2)
faraday (2.7.10)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
Expand All @@ -99,6 +118,9 @@ GEM
activesupport (>= 5.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
io-console (0.6.0)
irb (1.7.4)
reline (>= 0.3.6)
json-schema (4.0.0)
addressable (>= 2.8)
langchainrb (0.6.12)
Expand All @@ -116,9 +138,12 @@ GEM
net-pop
net-smtp
marcel (1.0.2)
matrix (0.4.2)
method_source (1.0.0)
mini_mime (1.1.5)
minitest (5.19.0)
mocha (2.1.0)
ruby2_keywords (>= 0.0.5)
multipart-post (2.3.0)
net-imap (0.3.7)
date
Expand All @@ -132,6 +157,7 @@ GEM
nio4r (2.5.9)
nokogiri (1.15.3-arm64-darwin)
racc (~> 1.4)
pg (1.5.3)
public_suffix (5.0.3)
puma (6.2.1)
nio4r (~> 2.0)
Expand Down Expand Up @@ -171,10 +197,21 @@ GEM
zeitwerk (~> 2.5)
rake (13.0.6)
redcarpet (2.3.0)
regexp_parser (2.8.1)
reline (0.3.8)
io-console (~> 0.5)
rexml (3.2.6)
ruby-openai (4.3.2)
faraday (>= 1)
faraday-multipart (>= 1)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
selenium-webdriver (4.10.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
shoulda-matchers (5.3.0)
activesupport (>= 5.2.0)
sprockets (4.2.0)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand All @@ -186,21 +223,50 @@ GEM
thor (1.2.2)
tiktoken_ruby (0.0.5-arm64-darwin)
timeout (0.4.0)
turbo-rails (1.4.0)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
web-console (4.2.0)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webdrivers (5.3.1)
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0, < 4.11)
websocket (1.2.9)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.11)

PLATFORMS
arm64-darwin-21

DEPENDENCIES
plain!
capybara
debug
dotenv-rails
faker
mocha
pg
plain-rails!
puma
qdrant-ruby (~> 0.9.2)
ruby-openai (~> 4.2)
selenium-webdriver
shoulda-matchers (~> 5.0)
sprockets-rails
sqlite3
turbo-rails
web-console
webdrivers

BUNDLED WITH
2.4.15
46 changes: 44 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# What is this Ruby on Plan rails engine
# Ruby on Plain

[![Rails Test](https://github.com/chaskiq/plain/actions/workflows/ci.yml/badge.svg)](https://github.com/chaskiq/plain/actions/workflows/ci.yml)

---
## What is this Ruby on Plan rails engine

Plain is a Rails engine that serves as an Artificial Intelligence (AI) assistant for your Rails project. It's not just about organizing your codes or managing your project structure, but about providing deeper, more meaningful context to your work, in real-time. It was proudly developed and presented during the esteemed Rails Hackathon 2023.

Expand All @@ -13,7 +18,13 @@ How to use my plugin.
Add this line to your application's Gemfile:

```ruby
gem "plain", github: "chaskiq/plain", branch: "main"
gem "plain-rails"
```

or development version

```ruby
gem "plain-rails", github: "chaskiq/plain", branch: "main"
```

### Overview
Expand All @@ -40,6 +51,37 @@ Beyond just an AI assistant, Plain acts as a comprehensive documentation site. W

### Configuration:

put this in an config/initializers , config/initializers/plain.rb

```ruby
Plain.configure do |config|
config.paths = [
Rails.root.join("Gemfile"),
Rails.root.join("app/models"),
Rails.root.join("app/controllers"),
Rails.root.join("spec")
]
config.extensions = ["rb", "js", "md", "json", "erb"]
config.chat_environments = [:development]

# initialize your vector search
config.vector_search = Langchain::Vectorsearch::Qdrant.new(
url: ENV["QDRANT_URL"],
api_key: ENV["QDRANT_API_KEY"],
index_name: ENV["QDRANT_INDEX"],
llm: Langchain::LLM::OpenAI.new(
api_key: ENV["OPENAI_API_KEY"],
llm_options: {},
default_options: {
chat_completion_model_name: "gpt-3.5-turbo-16k"
}
)
)
end
```

For other vector search please refer to langchainrb repo https://github.com/andreibondarev/langchainrb#using-vector-search-databases-

Some environment configuration variables are required:

```bash
Expand Down
19 changes: 7 additions & 12 deletions app/models/plain/conversation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,14 @@ def add_assistant_response(question)
message = messages.new(role: "assistant", content: "")

chat = Plain::AiDocs.new.conversation_client do |chunk|
puts "****++"
puts "****"
p chunk
puts "****++"
next if chunk["choices"].blank?
chunk["choices"].each do |choice|
# puts choice["delta"]["content"].present?
# next unless choice["delta"]["content"].present?
new_content = choice["delta"]["content"]
next if new_content.nil?
complete_response << new_content
message.content = complete_response
message.save
end
puts "****"

next if chunk.content.nil?
complete_response << chunk.content
message.content = complete_response
message.save
end

# plain_answer = vector_search.ask(question: @question)
Expand Down
9 changes: 9 additions & 0 deletions app/models/plain/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,14 @@ def persist_as_document(path)
File.write(full_path, self.content) unless File.exist?(full_path)
end

def type
case self.role
when "user"
"human"
when "assistant"
"ai"
end
end

end
end

0 comments on commit 01f72d8

Please sign in to comment.