From 50a6b695666d893e75f80ade4d355b220fd6f0b0 Mon Sep 17 00:00:00 2001 From: Hussain Nagaria Date: Wed, 24 May 2023 22:02:40 +0530 Subject: [PATCH 1/6] fix: key warning --- doppio_bot/public/js/ChatView.jsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doppio_bot/public/js/ChatView.jsx b/doppio_bot/public/js/ChatView.jsx index 8bbf0ef..ae9fdc8 100644 --- a/doppio_bot/public/js/ChatView.jsx +++ b/doppio_bot/public/js/ChatView.jsx @@ -47,7 +47,6 @@ const ChatView = ({ sessionID }) => { session_id: sessionID, }) .then((response) => { - console.log("message from backend: ", response); setMessages((old) => { old.splice(old.length - 1, 1, { from: "ai", @@ -95,7 +94,7 @@ const ChatView = ({ sessionID }) => { > {messages.map((message) => { - return ; + return ; })} From b930e3e53d8316d97bbe5c80c6ed785c5fc85d55 Mon Sep 17 00:00:00 2001 From: Hussain Nagaria Date: Wed, 24 May 2023 22:08:18 +0530 Subject: [PATCH 2/6] chore: remove experimental app banner --- doppio_bot/public/js/ChatView.jsx | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/doppio_bot/public/js/ChatView.jsx b/doppio_bot/public/js/ChatView.jsx index ae9fdc8..8c0cc9f 100644 --- a/doppio_bot/public/js/ChatView.jsx +++ b/doppio_bot/public/js/ChatView.jsx @@ -10,7 +10,7 @@ import { Textarea, } from "@chakra-ui/react"; import { SendIcon } from "lucide-react"; -import React, { useEffect, useState } from "react"; +import React, { useState } from "react"; import Message from "./components/message/Message"; const ChatView = ({ sessionID }) => { @@ -66,15 +66,6 @@ const ChatView = ({ sessionID }) => { }); }; - useEffect(() => { - toast({ - title: "This is an experimental app", - status: "warning", - position: "bottom-right", - isClosable: true, - }); - }, []); - return ( Date: Wed, 24 May 2023 22:10:05 +0530 Subject: [PATCH 3/6] feat: add keyboard shortcut to open doppio bot! --- doppio_bot/hooks.py | 96 +++++++++++----------- doppio_bot/public/js/app_customizations.js | 8 ++ 2 files changed, 56 insertions(+), 48 deletions(-) create mode 100644 doppio_bot/public/js/app_customizations.js diff --git a/doppio_bot/hooks.py b/doppio_bot/hooks.py index c662e5e..f4ebb06 100644 --- a/doppio_bot/hooks.py +++ b/doppio_bot/hooks.py @@ -12,7 +12,7 @@ # include js, css files in header of desk.html # app_include_css = "/assets/doppio_bot/css/doppio_bot.css" -# app_include_js = "/assets/doppio_bot/js/doppio_bot.js" +app_include_js = "/assets/doppio_bot/js/app_customizations.js" # include js, css files in header of web template # web_include_css = "/assets/doppio_bot/css/doppio_bot.css" @@ -42,7 +42,7 @@ # website user home page (by Role) # role_home_page = { -# "Role": "home_page" +# "Role": "home_page" # } # Generators @@ -56,8 +56,8 @@ # add methods and filters to jinja environment # jinja = { -# "methods": "doppio_bot.utils.jinja_methods", -# "filters": "doppio_bot.utils.jinja_filters" +# "methods": "doppio_bot.utils.jinja_methods", +# "filters": "doppio_bot.utils.jinja_filters" # } # Installation @@ -83,11 +83,11 @@ # Permissions evaluated in scripted ways # permission_query_conditions = { -# "Event": "frappe.desk.doctype.event.event.get_permission_query_conditions", +# "Event": "frappe.desk.doctype.event.event.get_permission_query_conditions", # } # # has_permission = { -# "Event": "frappe.desk.doctype.event.event.has_permission", +# "Event": "frappe.desk.doctype.event.event.has_permission", # } # DocType Class @@ -95,7 +95,7 @@ # Override standard doctype classes # override_doctype_class = { -# "ToDo": "custom_app.overrides.CustomToDo" +# "ToDo": "custom_app.overrides.CustomToDo" # } # Document Events @@ -103,32 +103,32 @@ # Hook on document methods and events # doc_events = { -# "*": { -# "on_update": "method", -# "on_cancel": "method", -# "on_trash": "method" -# } +# "*": { +# "on_update": "method", +# "on_cancel": "method", +# "on_trash": "method" +# } # } # Scheduled Tasks # --------------- # scheduler_events = { -# "all": [ -# "doppio_bot.tasks.all" -# ], -# "daily": [ -# "doppio_bot.tasks.daily" -# ], -# "hourly": [ -# "doppio_bot.tasks.hourly" -# ], -# "weekly": [ -# "doppio_bot.tasks.weekly" -# ], -# "monthly": [ -# "doppio_bot.tasks.monthly" -# ], +# "all": [ +# "doppio_bot.tasks.all" +# ], +# "daily": [ +# "doppio_bot.tasks.daily" +# ], +# "hourly": [ +# "doppio_bot.tasks.hourly" +# ], +# "weekly": [ +# "doppio_bot.tasks.weekly" +# ], +# "monthly": [ +# "doppio_bot.tasks.monthly" +# ], # } # Testing @@ -140,14 +140,14 @@ # ------------------------------ # # override_whitelisted_methods = { -# "frappe.desk.doctype.event.event.get_events": "doppio_bot.event.get_events" +# "frappe.desk.doctype.event.event.get_events": "doppio_bot.event.get_events" # } # # each overriding function accepts a `data` argument; # generated from the base implementation of the doctype dashboard, # along with any modifications made in other Frappe apps # override_doctype_dashboards = { -# "Task": "doppio_bot.task.get_dashboard_data" +# "Task": "doppio_bot.task.get_dashboard_data" # } # exempt linked doctypes from being automatically cancelled @@ -173,29 +173,29 @@ # -------------------- # user_data_fields = [ -# { -# "doctype": "{doctype_1}", -# "filter_by": "{filter_by}", -# "redact_fields": ["{field_1}", "{field_2}"], -# "partial": 1, -# }, -# { -# "doctype": "{doctype_2}", -# "filter_by": "{filter_by}", -# "partial": 1, -# }, -# { -# "doctype": "{doctype_3}", -# "strict": False, -# }, -# { -# "doctype": "{doctype_4}" -# } +# { +# "doctype": "{doctype_1}", +# "filter_by": "{filter_by}", +# "redact_fields": ["{field_1}", "{field_2}"], +# "partial": 1, +# }, +# { +# "doctype": "{doctype_2}", +# "filter_by": "{filter_by}", +# "partial": 1, +# }, +# { +# "doctype": "{doctype_3}", +# "strict": False, +# }, +# { +# "doctype": "{doctype_4}" +# } # ] # Authentication and authorization # -------------------------------- # auth_hooks = [ -# "doppio_bot.auth.validate" +# "doppio_bot.auth.validate" # ] diff --git a/doppio_bot/public/js/app_customizations.js b/doppio_bot/public/js/app_customizations.js new file mode 100644 index 0000000..817a349 --- /dev/null +++ b/doppio_bot/public/js/app_customizations.js @@ -0,0 +1,8 @@ +frappe.ui.keys.add_shortcut({ + shortcut: "shift+ctrl+d", + action: function () { + // navigate to ask doppio bot page + frappe.set_route("doppio-bot"); + }, + description: __("Ask DoppioBot"), +}); From d2008510b721688123ba2b65f8e9cdb96e580fd8 Mon Sep 17 00:00:00 2001 From: Hussain Nagaria Date: Wed, 24 May 2023 22:15:59 +0530 Subject: [PATCH 4/6] fix: page header styles Fixes #3 --- .../frappe_chatgpt_integration/page/doppio_bot/doppio_bot.js | 3 +-- doppio_bot/public/js/ChatView.jsx | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doppio_bot/frappe_chatgpt_integration/page/doppio_bot/doppio_bot.js b/doppio_bot/frappe_chatgpt_integration/page/doppio_bot/doppio_bot.js index c552f4a..ba84d1e 100644 --- a/doppio_bot/frappe_chatgpt_integration/page/doppio_bot/doppio_bot.js +++ b/doppio_bot/frappe_chatgpt_integration/page/doppio_bot/doppio_bot.js @@ -1,7 +1,6 @@ frappe.pages["doppio-bot"].on_page_load = function (wrapper) { - var page = frappe.ui.make_app_page({ + frappe.ui.make_app_page({ parent: wrapper, - title: "Ask DoppioBot", single_column: true, }); }; diff --git a/doppio_bot/public/js/ChatView.jsx b/doppio_bot/public/js/ChatView.jsx index 8c0cc9f..cf9dd9b 100644 --- a/doppio_bot/public/js/ChatView.jsx +++ b/doppio_bot/public/js/ChatView.jsx @@ -8,6 +8,7 @@ import { Avatar, useToast, Textarea, + Text, } from "@chakra-ui/react"; import { SendIcon } from "lucide-react"; import React, { useState } from "react"; @@ -74,6 +75,7 @@ const ChatView = ({ sessionID }) => { maxWidth={"4xl"} mx={"auto"} > + Ask DoppioBot {/* Chat Area */} Date: Wed, 24 May 2023 22:34:52 +0530 Subject: [PATCH 5/6] chore: mention LangChan in app description --- doppio_bot/hooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doppio_bot/hooks.py b/doppio_bot/hooks.py index f4ebb06..0b742f9 100644 --- a/doppio_bot/hooks.py +++ b/doppio_bot/hooks.py @@ -3,7 +3,7 @@ app_name = "doppio_bot" app_title = "DoppioBot" app_publisher = "Hussain Nagaria" -app_description = "ChatGPT in the Desk, powered by React & OpenAI API" +app_description = "ChatGPT in the Desk, powered by React, LangChain & OpenAI API" app_email = "hussain@frappe.io" app_license = "AGPL-3.0" From e063dc943d1ec6a483818a962031a0a6d28e519a Mon Sep 17 00:00:00 2001 From: Hussain Nagaria Date: Wed, 21 Jun 2023 13:11:58 +0530 Subject: [PATCH 6/6] feat: select openAI model in settings --- doppio_bot/api.py | 10 ++++- .../doctype/__init__.py | 0 .../doctype/doppiobot_settings/__init__.py | 0 .../doppiobot_settings/doppiobot_settings.js | 8 ++++ .../doppiobot_settings.json | 42 +++++++++++++++++++ .../doppiobot_settings/doppiobot_settings.py | 9 ++++ .../test_doppiobot_settings.py | 9 ++++ 7 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 doppio_bot/frappe_chatgpt_integration/doctype/__init__.py create mode 100644 doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/__init__.py create mode 100644 doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/doppiobot_settings.js create mode 100644 doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/doppiobot_settings.json create mode 100644 doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/doppiobot_settings.py create mode 100644 doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/test_doppiobot_settings.py diff --git a/doppio_bot/api.py b/doppio_bot/api.py index a5cb589..314fba8 100644 --- a/doppio_bot/api.py +++ b/doppio_bot/api.py @@ -5,7 +5,6 @@ from langchain.chains import ConversationChain from langchain.prompts import PromptTemplate -OPENAI_MODEL_NAME = "gpt-3.5-turbo" # Note: Copied the default template and added extra instructions for code output prompt_template = PromptTemplate( @@ -33,11 +32,12 @@ def get_chatbot_response(session_id: str, prompt_message: str) -> str: # Throw if no key in site_config # Maybe extract and cache this (site cache) opeai_api_key = frappe.conf.get("openai_api_key") + openai_model = get_model_from_settings() if not opeai_api_key: frappe.throw("Please set `openai_api_key` in site config") - llm = OpenAI(model_name=OPENAI_MODEL_NAME, temperature=0, openai_api_key=opeai_api_key) + llm = OpenAI(model_name=openai_model, temperature=0, openai_api_key=opeai_api_key) message_history = RedisChatMessageHistory( session_id=session_id, url=frappe.conf.get("redis_cache") or "redis://localhost:6379/0", @@ -47,3 +47,9 @@ def get_chatbot_response(session_id: str, prompt_message: str) -> str: response = conversation_chain.run(prompt_message) return response + + +def get_model_from_settings(): + return ( + frappe.db.get_single_value("DoppioBot Settings", "openai_model") or "gpt-3.5-turbo" + ) diff --git a/doppio_bot/frappe_chatgpt_integration/doctype/__init__.py b/doppio_bot/frappe_chatgpt_integration/doctype/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/__init__.py b/doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/doppiobot_settings.js b/doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/doppiobot_settings.js new file mode 100644 index 0000000..8c61834 --- /dev/null +++ b/doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/doppiobot_settings.js @@ -0,0 +1,8 @@ +// Copyright (c) 2023, Hussain Nagaria and contributors +// For license information, please see license.txt + +// frappe.ui.form.on("DoppioBot Settings", { +// refresh(frm) { + +// }, +// }); diff --git a/doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/doppiobot_settings.json b/doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/doppiobot_settings.json new file mode 100644 index 0000000..f20b9ad --- /dev/null +++ b/doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/doppiobot_settings.json @@ -0,0 +1,42 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2023-06-21 13:00:34.366049", + "doctype": "DocType", + "engine": "InnoDB", + "field_order": [ + "openai_model" + ], + "fields": [ + { + "default": "gpt-3.5-turbo", + "fieldname": "openai_model", + "fieldtype": "Select", + "label": "OpenAI Model", + "options": "gpt-3.5-turbo\ngpt-3.5-turbo-16k\ntext-davinci-003\ngpt-4\ngpt-4-32k" + } + ], + "index_web_pages_for_search": 1, + "issingle": 1, + "links": [], + "modified": "2023-06-21 13:06:09.895694", + "modified_by": "Administrator", + "module": "Frappe ChatGPT Integration", + "name": "DoppioBot Settings", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "print": 1, + "read": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/doppiobot_settings.py b/doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/doppiobot_settings.py new file mode 100644 index 0000000..34482aa --- /dev/null +++ b/doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/doppiobot_settings.py @@ -0,0 +1,9 @@ +# Copyright (c) 2023, Hussain Nagaria and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + + +class DoppioBotSettings(Document): + pass diff --git a/doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/test_doppiobot_settings.py b/doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/test_doppiobot_settings.py new file mode 100644 index 0000000..e268451 --- /dev/null +++ b/doppio_bot/frappe_chatgpt_integration/doctype/doppiobot_settings/test_doppiobot_settings.py @@ -0,0 +1,9 @@ +# Copyright (c) 2023, Hussain Nagaria and Contributors +# See license.txt + +# import frappe +from frappe.tests.utils import FrappeTestCase + + +class TestDoppioBotSettings(FrappeTestCase): + pass