Skip to content

Commit

Permalink
Add debug logging functionality for GPT interactions
Browse files Browse the repository at this point in the history
- Introduced methods to enable and disable debug logging in UserActions class.
- Added Talon commands to toggle debug logging.
- Updated modelHelpers.py to print request data when debug is enabled.
- Modified GPTState class to include debug_enabled flag and methods to toggle debug state.
  • Loading branch information
jaresty committed Aug 14, 2024
1 parent afb96b2 commit 4a890c1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
8 changes: 8 additions & 0 deletions GPT/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ def gpt_generate_sql(text_to_process: str) -> str:
"text", ""
)

def gpt_enable_debug():
"""Enable debug logging"""
GPTState.enable_debug()

def gpt_disable_debug():
"""Disable debug logging"""
GPTState.disable_debug()

def gpt_clear_context():
"""Reset the stored context"""
GPTState.clear_context()
Expand Down
6 changes: 6 additions & 0 deletions GPT/gpt.talon
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@
{user.model} [nope] that was <user.text>$:
result = user.gpt_reformat_last(text)
user.paste(result)

# Enable debug logging so you can more details about messages being sent
{user.model} enable debug: user.gpt_enable_debug()

# Disable debug logging
{user.model} disable debug: user.gpt_disable_debug()
3 changes: 2 additions & 1 deletion lib/modelHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ def send_request(
"n": 1,
"model": settings.get("user.openai_model"),
}

if GPTState.debug_enabled:
print(data)
if tools is not None:
data["tools"] = tools

Expand Down
13 changes: 13 additions & 0 deletions lib/modelState.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ class GPTState:
context: ClassVar[list[GPTMessageItem]] = []
thread: ClassVar[list[GPTMessage]] = []
thread_enabled: ClassVar[bool] = False
debug_enabled: ClassVar[bool] = False

@classmethod
def enable_debug(cls):
"""Enable debug printing"""
cls.context = []
actions.app.notify("Enabled debug logging")

@classmethod
def disable_debug(cls):
"""Disable debug printing"""
cls.context = []
actions.app.notify("Disabled debug logging")

@classmethod
def clear_context(cls):
Expand Down

0 comments on commit 4a890c1

Please sign in to comment.