|
| 1 | +-- You can run the following commands in your local mindsdb setup |
| 2 | + |
| 3 | +-- Creating a project. This will contain the model, views and job you are about to create |
| 4 | +CREATE PROJECT mind_reader_project; |
| 5 | + |
| 6 | +-- Creating a model which will predict the response |
| 7 | +CREATE MODEL mind_reader_project.gpt_model |
| 8 | +PREDICT response |
| 9 | +USING |
| 10 | +engine = 'openai', |
| 11 | +max_tokens = 300, |
| 12 | +api_key = '<your-openai-api-key>', -- In MindsDB cloud accounts we provide a default key |
| 13 | +model_name = 'gpt-3.5-turbo', -- You can also use 'text-davinci-003' |
| 14 | +prompt_template = 'Reply like a friend who cares and wants to help.\ |
| 15 | + Input message: {{text}}\ |
| 16 | + In less than 550 characters, when there is some sign of distress in the input share healthy habits, \ |
| 17 | + motivational quotes, inspirational real-life stories. |
| 18 | + Provide options to seek out in-person help if you are not able to satisfy.'; -- Prompt which will decide the style of output |
| 19 | + |
| 20 | +-- Confirm if the model status is complete before proceeding |
| 21 | +SELECT * |
| 22 | +FROM mind_reader_project.models |
| 23 | +WHERE name='gpt_model'; -- Name of the model within our project |
| 24 | + |
| 25 | +-- Query the model to get a response |
| 26 | +SELECT response |
| 27 | +FROM mind_reader_project.gpt_model |
| 28 | +WHERE text = "Not doing so great"; -- Input to the model |
| 29 | + |
| 30 | +-- Creating yugabyteDB instance |
| 31 | +CREATE DATABASE yugabyte_demo |
| 32 | +WITH |
| 33 | + engine = 'yugabyte', |
| 34 | + parameters = { |
| 35 | + "user": "admin", -- User name |
| 36 | + "password": "password", -- Password associated with the user |
| 37 | + "host": "link", -- Link to the instance which hosts the DB |
| 38 | + "port": 5433, |
| 39 | + "database": "demo", -- Database name in instance |
| 40 | + "schema": "public" -- Schema name in instance |
| 41 | + }; |
| 42 | + |
| 43 | +-- Viewing the stored inputs |
| 44 | +SELECT * from yugabyte_demo.chatbot_input; |
| 45 | + |
| 46 | +-- Storing input into the table |
| 47 | +INSERT INTO yugabyte_demo.chatbot_input (text) |
| 48 | +VALUES ('feeling lonely'); |
| 49 | + |
| 50 | +-- Storing output generated from the model based on the input data |
| 51 | +INSERT INTO yugabyte_demo.chatbot_output ( |
| 52 | +SELECT r.response AS text -- Response from model |
| 53 | +FROM yugabyte_demo.chatbot_input t |
| 54 | +JOIN mind_reader_project.gpt_model r |
| 55 | +); |
| 56 | + |
| 57 | +-- Viewing the responses stored in table |
| 58 | +SELECT * |
| 59 | +FROM yugabyte_demo.chatbot_output; |
| 60 | + |
| 61 | +-- View that stores the input messages which haven't been replied to yet |
| 62 | +CREATE VIEW mind_reader_project.to_reply_to ( |
| 63 | +SELECT id, text FROM yugabyte_demo.chatbot_input |
| 64 | +WHERE id NOT IN (SELECT r.id FROM yugabyte_demo.chatbot_output AS r) -- Fetching input which hasn't been replied to |
| 65 | +); |
| 66 | + |
| 67 | +-- View the messages which haven't been replied to |
| 68 | +SELECT * |
| 69 | +FROM mind_reader_project.to_reply_to; |
| 70 | + |
| 71 | +-- View that stores the responses (against the messages which weren't replied to) from model |
| 72 | +CREATE VIEW mind_reader_project.to_chatbot_output ( |
| 73 | + SELECT * FROM mind_reader_project.to_reply_to |
| 74 | + JOIN mind_reader_project.gpt_model |
| 75 | +); |
| 76 | + |
| 77 | +-- Job to automate the flow, runs every minute |
| 78 | +CREATE JOB mind_reader_project.chatbot_job ( |
| 79 | + -- Storing the responses from model in output table |
| 80 | + INSERT INTO yugabyte_demo.chatbot_output ( |
| 81 | + SELECT |
| 82 | + id, |
| 83 | + response AS text |
| 84 | + FROM mind_reader_project.to_chatbot_output |
| 85 | + ) |
| 86 | + |
| 87 | +) EVERY MINUTE; |
| 88 | + |
| 89 | +-- See all the jobs within the project |
| 90 | +SELECT * |
| 91 | +FROM mind_reader_project.jobs where name = "chatbot_job"; |
| 92 | + |
| 93 | +-- Once job is created, input message |
| 94 | +INSERT INTO yugabyte_demo.chatbot_input (text) |
| 95 | +VALUES ('feeling lonely'); |
| 96 | + |
| 97 | +-- Output table will be updated by the job every minute in case of new input messages |
| 98 | +SELECT * |
| 99 | +FROM yugabyte_demo.chatbot_output; |
| 100 | + |
| 101 | +-- See the whole history of the jobs within the project |
| 102 | +SELECT * |
| 103 | +FROM mind_reader_project.jobs_history; |
| 104 | + |
| 105 | +-- Drop the database instance from mindsdb |
| 106 | +DROP DATABASE yugabyte_demo; |
| 107 | + |
| 108 | +-- Drop the running job |
| 109 | +DROP JOB mind_reader_project.chatbot_job; |
| 110 | + |
| 111 | +-- Drop the gpt_model |
| 112 | +DROP MODEL mind_reader_project.gpt_model; |
| 113 | + |
| 114 | +-- Drop the to_reply_to view |
| 115 | +DROP VIEW mind_reader_project.to_reply_to; |
| 116 | + |
| 117 | +-- Drop the to_chatbot_output view |
| 118 | +DROP VIEW mind_reader_project.to_chatbot_output; |
| 119 | + |
| 120 | +-- Drop the mind_reader_project |
| 121 | +DROP PROJECT mind_reader_project; |
0 commit comments