diff --git a/README.md b/README.md index 243cb10..0f74490 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # ChatGPT Fallback Skill -When in doubt, ask chatgpt, powered by [OpenAI Solver](https://github.com/OpenVoiceOS/ovos-solver-plugin-openai-persona) +When in doubt, ask ChatGPT, powered by [OpenAI Solver](https://github.com/OpenVoiceOS/ovos-solver-plugin-openai-persona). -You need to configure an api_key, get it at https://beta.openai.com/account/api-keys +You need to configure a `key`, get it at https://platform.openai.com/api-keys - -## About +## About Capabilities: + - Remembers what user said earlier in the conversation - Trained to decline inappropriate requests @@ -19,17 +19,27 @@ Limitations: ## Configuration -Under skill settings you can tweak some parameters for chatGPT - +Under skill settings you can tweak some parameters for chatGPT. - `key` - your api_key to access OpenAI - `persona` - can be used to create a "persona", give a personality to chatGPT -- `model` - LLM model to use, eg `"gpt-3.5-turbo", see all options [here](https://platform.openai.com/docs/models) +- `model` - LLM model to use, eg `gpt-3.5-turbo`, see all options [here](https://platform.openai.com/docs/models) The default persona is `helpful, creative, clever, and very friendly.` - -## Examples - -* "Explain quantum computing in simple terms" -* "Got any creative ideas for a 10 year old’s birthday?" +```shell +mkdir -p ~/.config/mycroft/skills/skill-ovos-fallback-chatgpt.openvoiceos +cat <~/.config/mycroft/skills/skill-ovos-fallback-chatgpt.openvoiceos/settings.json +{ + "key": "sk-XXXYYYZZZAAABBB123", + "model": "gpt-3.5-turbo", + "persona": "You are a helpful voice assistant with a friendly tone and fun sense of humor", + "__mycroft_skill_firstrun": false +} +EOF +``` + +## Examples + +- "Explain quantum computing in simple terms" +- "Got any creative ideas for a 10 year old’s birthday?" diff --git a/__init__.py b/__init__.py index c00caf2..eb741ff 100644 --- a/__init__.py +++ b/__init__.py @@ -1,8 +1,8 @@ +from ovos_bus_client.message import Message from ovos_bus_client.session import SessionManager from ovos_solver_openai_persona import OpenAIPersonaSolver from ovos_utils import classproperty from ovos_utils.process_utils import RuntimeRequirements - from ovos_workshop.skills.fallback import FallbackSkill @@ -11,15 +11,17 @@ class ChatGPTSkill(FallbackSkill): @classproperty def runtime_requirements(self): - return RuntimeRequirements(internet_before_load=True, - network_before_load=True, - gui_before_load=False, - requires_internet=True, - requires_network=True, - requires_gui=False, - no_internet_fallback=False, - no_network_fallback=False, - no_gui_fallback=True) + return RuntimeRequirements( + internet_before_load=True, + network_before_load=True, + gui_before_load=False, + requires_internet=True, + requires_network=True, + requires_gui=False, + no_internet_fallback=False, + no_network_fallback=False, + no_gui_fallback=True, + ) def initialize(self): self.chat = OpenAIPersonaSolver(config=self.settings) @@ -67,11 +69,19 @@ def build_msg_history(self, message): messages.append((q, ans)) return messages - def ask_chatgpt(self, message): - utterance = message.data['utterance'] + def _async_ask(self, message): + utterance = message.data["utterance"] self.chat.qa_pairs = self.build_msg_history(message) answer = self.chat.get_spoken_answer(utterance) if not answer: - return False - self.speak(answer) + self.speak_dialog("gpt_error") + else: + self.speak(answer) + + def ask_chatgpt(self, message): + utterance = message.data["utterance"] + self.speak_dialog("asking") + # ask in a thread so fallback doesnt timeout + self.bus.once("async.chatgpt.fallback", self._async_ask) + self.bus.emit(Message("async.chatgpt.fallback", {"utterance": utterance})) return True diff --git a/locale/en-us/asking.dialog b/locale/en-us/asking.dialog new file mode 100644 index 0000000..88ef878 --- /dev/null +++ b/locale/en-us/asking.dialog @@ -0,0 +1,2 @@ +Let me ask Chat G.P.T. +Asking Chat G.P.T. diff --git a/locale/en-us/gpt_error.dialog b/locale/en-us/gpt_error.dialog new file mode 100644 index 0000000..a8d1921 --- /dev/null +++ b/locale/en-us/gpt_error.dialog @@ -0,0 +1,2 @@ +I was not able to get an answer from Chat G.P.T. +Sorry but something went wrong with the Chat G.P.T. request. diff --git a/locale/fr-fr/asking.dialog b/locale/fr-fr/asking.dialog new file mode 100644 index 0000000..86432ec --- /dev/null +++ b/locale/fr-fr/asking.dialog @@ -0,0 +1,2 @@ +Laissez moi poser la question à Chat G.P.T. +Je demande à Chat G.P.T. diff --git a/locale/fr-fr/gpt_error.dialog b/locale/fr-fr/gpt_error.dialog new file mode 100644 index 0000000..98279c7 --- /dev/null +++ b/locale/fr-fr/gpt_error.dialog @@ -0,0 +1,2 @@ +Je n'ai pas pu obtenir de réponse venant de Chat G.P.T. +Désolé, mais quelque chose s'est mal passé avec la demande à Chat G.P.T.