Skip to content

Commit

Permalink
Change response for ChatGPT's failed authentication
Browse files Browse the repository at this point in the history
Fix secret access via offline communicator
  • Loading branch information
dormant-user committed Jul 31, 2023
1 parent 567458a commit 810cad8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion jarvis/api/fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ def enable_cors() -> NoReturn:
@app.on_event(event_type='startup')
async def startup_func() -> NoReturn:
"""Simple startup function to add anything that has to be triggered when Jarvis API starts up."""
logger.info("Hosting at http://{%s}:{%s}", models.env.offline_host, models.env.offline_port)
logger.info("Hosting at http://%s:%s", models.env.offline_host, models.env.offline_port)
if models.env.author_mode:
Thread(target=stockanalysis_squire.nasdaq).start()
10 changes: 6 additions & 4 deletions jarvis/api/routers/offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ async def offline_communicator_api(request: Request, input_data: OfflineCommunic
raise APIResponse(status_code=HTTPStatus.NO_CONTENT.real, detail=HTTPStatus.NO_CONTENT.phrase)

logger.info("Request: %s", command)
if 'alarm' in command.lower() or 'remind' in command.lower():
command = command.lower()
else:
command = command.translate(str.maketrans('', '', string.punctuation)) # Remove punctuations from string
if command.lower() == 'test':
logger.info("Test message received.")
raise APIResponse(status_code=HTTPStatus.OK.real, detail="Test message received.")
Expand All @@ -115,8 +111,14 @@ async def offline_communicator_api(request: Request, input_data: OfflineCommunic
response = "The secret requested can be accessed from 'secure-send' endpoint using the token below.\n" \
"Note that the secret cannot be retrieved again using the same token and the token will " \
f"expire in 5 minutes.\n\n{response}"
else:
logger.error("Response: %s", response)
raise APIResponse(status_code=HTTPStatus.OK.real, detail=response)

if 'alarm' in command.lower() or 'remind' in command.lower():
command = command.lower()
else:
command = command.translate(str.maketrans('', '', string.punctuation)) # Remove punctuations from string
if ' and ' in command and not word_match.word_match(phrase=command, match_list=keywords.ignore_and):
and_response = ""
for each in command.split(' and '):
Expand Down
9 changes: 5 additions & 4 deletions jarvis/modules/transformer/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from openai.openai_object import OpenAIObject

from jarvis.modules.audio import speaker
from jarvis.modules.exceptions import MissingEnvVars
from jarvis.modules.logger.custom_logger import logger
from jarvis.modules.models import models
from jarvis.modules.utils import support


def dump_history(request: str, response: str) -> NoReturn:
Expand Down Expand Up @@ -115,6 +115,8 @@ def __init__(self):
"""Initiates authentication to GPT api."""
self.authenticated = False
self.authenticate()
if not self.authenticated:
raise MissingEnvVars

def authenticate(self) -> NoReturn:
"""Initiates authentication and prepares GPT responses ready to be audio fed."""
Expand Down Expand Up @@ -152,9 +154,6 @@ def query(self, phrase: str) -> NoReturn:
if response := existing_response(request=phrase):
speaker.speak(text=response)
return
if not self.authenticated:
support.no_env_vars()
return
self.MESSAGES.append(
{"role": "user", "content": phrase},
)
Expand Down Expand Up @@ -190,5 +189,7 @@ def query(self, phrase: str) -> NoReturn:
except ThreadTimeoutError:
logger.error("Failed to load GPT instance for '%s'", models.settings.pname)
instance = None
except MissingEnvVars:
instance = None
else:
instance = None
5 changes: 5 additions & 0 deletions release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Release Notes
=============

7.5.5 (07/31/2023)
------------------
- Change response for ``ChatGPT``'s failed authentication
- Fix secret access via offline communicator

7.5.4 (07/30/2023)
------------------
- Add a feature to get holidays across the world
Expand Down

0 comments on commit 810cad8

Please sign in to comment.