Skip to content
This repository has been archived by the owner on Jan 31, 2025. It is now read-only.

Commit

Permalink
Add dialog and make it more async (#11)
Browse files Browse the repository at this point in the history
* Inform the user about the ChatGPT request

* Rename locales to locale

* Add French translation

* Better English

* Make it async

* Update readme

* Add gpt_error.dialog
  • Loading branch information
goldyfruit authored Dec 29, 2023
1 parent 03f4265 commit 30b5bcf
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 26 deletions.
34 changes: 22 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 <<EOF>~/.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?"
38 changes: 24 additions & 14 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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)
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions locale/en-us/asking.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Let me ask Chat G.P.T.
Asking Chat G.P.T.
2 changes: 2 additions & 0 deletions locale/en-us/gpt_error.dialog
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions locale/fr-fr/asking.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Laissez moi poser la question à Chat G.P.T.
Je demande à Chat G.P.T.
2 changes: 2 additions & 0 deletions locale/fr-fr/gpt_error.dialog
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 30b5bcf

Please sign in to comment.