From 18768721255ec3bcc3724ebdd2cb9f8b596a883b Mon Sep 17 00:00:00 2001 From: "nida.ghuman" Date: Mon, 7 Oct 2024 15:48:43 -0400 Subject: [PATCH 01/57] WIP for initial page --- .../app/views/pages/ai_assistant.html.erb | 35 +++++++++++++++++++ playbook-website/config/routes.rb | 1 + 2 files changed, 36 insertions(+) create mode 100644 playbook-website/app/views/pages/ai_assistant.html.erb diff --git a/playbook-website/app/views/pages/ai_assistant.html.erb b/playbook-website/app/views/pages/ai_assistant.html.erb new file mode 100644 index 0000000000..9812613eca --- /dev/null +++ b/playbook-website/app/views/pages/ai_assistant.html.erb @@ -0,0 +1,35 @@ +<%= pb_rails("background", props: { background_color: "white" }) do %> + <%= pb_rails("flex", props:{html_options:{style:"height: 100vh"}}) do %> + <%= pb_rails("flex/flex_item", props:{html_options:{style:"height: 100vh"}}) do %> + <% end %> + <%= pb_rails("flex/flex_item", props:{ html_options:{style:"width: 100%;height:100vh"}}) do %> + <% pb_rails("flex", props:{ grow: true, orientation:"column", align: "stretch", justify:"center", align: "center", html_options:{style:"height: 100vh"}}) do %> + <%= pb_rails("flex/flex_item", props:{margin_bottom: "lg"}) do %> + <% end %> + <%= pb_rails("card", props: {padding: "xs", html_options:{style:"width: 700px"}}) do %> + <%= pb_form_with(scope: :example, url: "", method: :get) do |form| %> + <% pb_rails("flex", props:{ grow: true, align: "stretch"}) do %> + <%= form.text_field :message, props: { placeholder: "Give me a user profile that looks like github", inline: true, margin_bottom:"none", rows: 1, html_options:{style:"width: 100%"}} %> + <%= form.actions do |action| %> + <%= pb_rails("button", props: { id: "castSpellButton", icon: "comment-dots", icon_right: true, text: "Cast Spell", margin_left: "md", type: "submit", html_options:{style:"height: 100%;width:185px;"} }) %> + <%= pb_rails("button", props: { id: "mixingPotionsButton", icon: "spin fa-hourglass-half", icon_right: true, text: "Mixing Potions", margin_left: "md", type: "submit", html_options:{style:"height: 100%;display:none;"} }) %> + <% end %> + <% end %> + <% end %> + <% end %> + <% end %> + <% end %> + <% end %> +<% end %> + + + + diff --git a/playbook-website/config/routes.rb b/playbook-website/config/routes.rb index ac11cd61c9..814962b72b 100644 --- a/playbook-website/config/routes.rb +++ b/playbook-website/config/routes.rb @@ -9,6 +9,7 @@ get "changelog/swift", to: "pages#changelog_swift" get "changelog/figma", to: "pages#changelog_figma" get "changelog", to: redirect("changelog/web") + get "ai_assistant", to: "pages#ai_assistant" # Kits From 3f7a0a23cf062d6b3eec51d7b37940cd11a88de6 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 8 Oct 2024 10:22:38 -0400 Subject: [PATCH 02/57] db create worked --- Makefile | 3 ++ docker-compose.yml | 45 ++++++++++++++++++++++++++ playbook-website/Gemfile | 1 + playbook-website/Gemfile.lock | 2 ++ playbook-website/bin/rails | 2 +- playbook-website/bin/setup | 21 +++++++----- playbook-website/config/application.rb | 2 +- playbook-website/config/database.yml | 20 ++++++++++++ playbook-website/db/schema.rb | 16 +++++++++ 9 files changed, 102 insertions(+), 10 deletions(-) create mode 100644 playbook-website/config/database.yml create mode 100644 playbook-website/db/schema.rb diff --git a/Makefile b/Makefile index 25bad38519..73c8ed7d44 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,9 @@ clean: changelog: docker compose run web bundle exec github_changelog_generator +db: + docker compose up -d db + time-to-live ?= 3h review_cluster = ${shell ./playbook-website/bin/deployer ./playbook-website/bin/cluster_for_review_stack pr$(pr)} diff --git a/docker-compose.yml b/docker-compose.yml index 08164e4db4..1b2650db3a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,3 +19,48 @@ services: - bundle:/usr/local/bundle ports: - "8089:3000" + db: + platform: linux/x86_64 + image: percona:8.0.27-18@sha256:f649b06357456689c24601fe919d585dce5b289c623bb547f84acc458c34c0d0 + init: true + ports: + - "3306:3306" # Map the host port 3306 to the container port 3306 + environment: + MYSQL_ROOT_HOST: "%" + MYSQL_ROOT_PASSWORD: password + healthcheck: + test: ["CMD", "mysql", "-u", "root", "-ppassword", "-e", "SHOW DATABASES;"] + interval: 5s + timeout: 2s + retries: 5 + start_period: 20s + networks: + - main + redis: + image: redis:7.4.0-alpine@sha256:c35af3bbcef51a62c8bae5a9a563c6f1b60d7ebaea4cb5a3ccbcc157580ae098 + healthcheck: + test: ["CMD", "redis-cli", "PING"] + interval: 5s + timeout: 2s + retries: 5 + start_period: 20s + ports: + - 6379 + networks: + - main + influxdb: + image: influxdb:2.7.10@sha256:aac51f94d98041e591aa4a5f36294080dd7987c1033ff115febfab98adcda61d + container_name: influxdb + environment: + DOCKER_INFLUXDB_INIT_MODE: setup + DOCKER_INFLUXDB_INIT_USERNAME: admin + DOCKER_INFLUXDB_INIT_PASSWORD: passwordpasswordpassword + DOCKER_INFLUXDB_INIT_ORG: web + DOCKER_INFLUXDB_INIT_BUCKET: app_data + DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: influxdbwebtoken + ports: + - 8086:8086 + networks: + - main +networks: + main: diff --git a/playbook-website/Gemfile b/playbook-website/Gemfile index e74c01ade0..4f5bc2f843 100644 --- a/playbook-website/Gemfile +++ b/playbook-website/Gemfile @@ -18,6 +18,7 @@ gem "bootsnap", ">= 1.1.0", require: false # livenessProbe and readinessProbe. See: https://github.com/powerhome/playbook/blob/master/playbook/config/deploy/templates/deployment.yaml.erb gem "health_check" +gem "mysql2", "0.5.6" gem "redcarpet", "~> 3.6" gem 'front_matter_parser', "~> 1.0.1" gem "rouge", "~> 3.15" diff --git a/playbook-website/Gemfile.lock b/playbook-website/Gemfile.lock index 3bc1bfb9fe..4bc4e355a4 100644 --- a/playbook-website/Gemfile.lock +++ b/playbook-website/Gemfile.lock @@ -140,6 +140,7 @@ GEM mini_mime (1.1.5) minitest (5.25.1) msgpack (1.7.2) + mysql2 (0.5.6) net-imap (0.4.15) date net-protocol @@ -332,6 +333,7 @@ DEPENDENCIES front_matter_parser (~> 1.0.1) health_check listen + mysql2 (= 0.5.6) playbook_ui! psych (< 4) puma (~> 6.3) diff --git a/playbook-website/bin/rails b/playbook-website/bin/rails index 6fb4e4051c..efc0377492 100755 --- a/playbook-website/bin/rails +++ b/playbook-website/bin/rails @@ -1,4 +1,4 @@ #!/usr/bin/env ruby -APP_PATH = File.expand_path('../config/application', __dir__) +APP_PATH = File.expand_path("../config/application", __dir__) require_relative "../config/boot" require "rails/commands" diff --git a/playbook-website/bin/setup b/playbook-website/bin/setup index 1ac8ce0b7a..ec47b79b3b 100755 --- a/playbook-website/bin/setup +++ b/playbook-website/bin/setup @@ -2,7 +2,7 @@ require "fileutils" # path to your application root. -APP_ROOT = File.expand_path('..', __dir__) +APP_ROOT = File.expand_path("..", __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -13,16 +13,21 @@ FileUtils.chdir APP_ROOT do # This script is idempotent, so that you can run it at any time and get an expectable outcome. # Add necessary setup steps to this file. - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") - # Install JavaScript dependencies - system! 'bin/yarn' + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" + # end + + puts "\n== Preparing database ==" + system! "bin/rails db:prepare" puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' + system! "bin/rails log:clear tmp:clear" puts "\n== Restarting application server ==" - system! 'bin/rails restart' + system! "bin/rails restart" end diff --git a/playbook-website/config/application.rb b/playbook-website/config/application.rb index 786e521774..a2ef4578b4 100644 --- a/playbook-website/config/application.rb +++ b/playbook-website/config/application.rb @@ -6,7 +6,7 @@ # Pick the frameworks you want: require "active_model/railtie" require "active_job/railtie" -# require "active_record/railtie" +require "active_record/railtie" # require "active_storage/engine" require "action_controller/railtie" # require "action_mailer/railtie" diff --git a/playbook-website/config/database.yml b/playbook-website/config/database.yml new file mode 100644 index 0000000000..d328f8c1a6 --- /dev/null +++ b/playbook-website/config/database.yml @@ -0,0 +1,20 @@ +default: &default + adapter: mysql2 + encoding: utf8 + pool: 5 + username: root + password: password + host: 127.0.0.1 + port: 3306 + +development: + <<: *default + database: playbook_website_dev + +test: + <<: *default + database: playbook_website_test + +production: + <<: *default + database: playbook_website_prod diff --git a/playbook-website/db/schema.rb b/playbook-website/db/schema.rb new file mode 100644 index 0000000000..dc29ad706d --- /dev/null +++ b/playbook-website/db/schema.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[7.0].define(version: 0) do +end From 4d6bdf8f6357ad4147b00f09540f07603ce223e1 Mon Sep 17 00:00:00 2001 From: Carlos Lima Date: Tue, 8 Oct 2024 10:28:42 -0400 Subject: [PATCH 03/57] Adding ChatGPT Api call (#3777) **What does this PR do?** A clear and concise description with your runway ticket url. **Screenshots:** Screenshots to visualize your addition/change **How to test?** Steps to confirm the desired behavior: 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See addition/change #### Checklist: - [ ] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new kit`, `deprecated`, or `breaking`. See [Changelog & Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels) for details. - [ ] **DEPLOY** I have added the `milano` label to show I'm ready for a review. - [ ] **TESTS** I have added test coverage to my code. --- .../components/AiAssistant/apiService.jsx | 26 +++ .../components/AiAssistant/index.tsx | 73 +++++--- playbook-website/package.json | 1 + yarn.lock | 171 ++++++++++-------- 4 files changed, 166 insertions(+), 105 deletions(-) create mode 100644 playbook-website/app/javascript/components/AiAssistant/apiService.jsx diff --git a/playbook-website/app/javascript/components/AiAssistant/apiService.jsx b/playbook-website/app/javascript/components/AiAssistant/apiService.jsx new file mode 100644 index 0000000000..60855a7839 --- /dev/null +++ b/playbook-website/app/javascript/components/AiAssistant/apiService.jsx @@ -0,0 +1,26 @@ +import axios from 'axios'; + +const API_KEY = ''; // Replace with your OpenAI API key + +export const fetchChatGPTResponse = async (prompt) => { + const url = 'https://api.openai.com/v1/chat/completions'; + + const headers = { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${API_KEY}`, + }; + + const data = { + model: 'gpt-4o-mini', // Or whichever GPT model you're using + messages: [{ role: 'user', content: prompt }], + max_tokens: 150, + }; + + try { + const response = await axios.post(url, data, { headers }); + return response.data; + } catch (error) { + console.error('Error calling ChatGPT API:', error); + throw error; + } +}; diff --git a/playbook-website/app/javascript/components/AiAssistant/index.tsx b/playbook-website/app/javascript/components/AiAssistant/index.tsx index dca66ec681..fdd03b1966 100644 --- a/playbook-website/app/javascript/components/AiAssistant/index.tsx +++ b/playbook-website/app/javascript/components/AiAssistant/index.tsx @@ -1,33 +1,54 @@ -import React, { useState } from "react"; -import { Flex, Card, Textarea, Background } from "playbook-ui"; +import { useState } from 'react'; +import { fetchChatGPTResponse } from './apiService'; +import { Button, Card, Flex, Textarea, Background } from 'playbook-ui'; const AiAssistant = () => { - const [value, setValue] = useState("Start Typing..."); - const handleChange = (event) => { - setValue(event.target.value); + const [input, setInput] = useState(''); + const [response, setResponse] = useState(null); + const [loading, setLoading] = useState(false); + + const handleSubmit = async () => { + setLoading(true); + try { + const data = await fetchChatGPTResponse(input); + setResponse(data.choices[0].message.content); + } catch (error) { + console.error('Error fetching response:', error); + } finally { + setLoading(false); + } }; + return ( -
- - - -