Skip to content

Commit

Permalink
Add callbacks to LLM chat
Browse files Browse the repository at this point in the history
  • Loading branch information
mahaloz committed Oct 4, 2024
1 parent 1e44a3d commit 330689b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dailalib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "3.9.1"
__version__ = "3.10.0"

import os
# stop LiteLLM from querying at all to the remote server
Expand Down
2 changes: 2 additions & 0 deletions dailalib/api/litellm/litellm_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(
prompts: Optional[list] = None,
fit_to_tokens: bool = False,
chat_use_ctx: bool = True,
chat_event_callbacks: Optional[dict] = None,
**kwargs
):
super().__init__(**kwargs)
Expand All @@ -40,6 +41,7 @@ def __init__(
self.model = model
self.fit_to_tokens = fit_to_tokens
self.chat_use_ctx = chat_use_ctx
self.chat_event_callbacks = chat_event_callbacks or {"send": None, "receive": None}

# delay prompt import
from .prompts import PROMPTS, DEFAULT_STYLE
Expand Down
13 changes: 12 additions & 1 deletion dailalib/llm_chat/llm_chat_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def __init__(self, ai_api: "LiteLLMAIAPI", parent=None, context: Context = None)
# create a context for this first message
if ai_api.chat_use_ctx:
ai_api.info("Collecting context for the current function...")
#import remote_pdb; remote_pdb.RemotePdb('localhost', 4444).set_trace()
if context is None:
context = ai_api._dec_interface.gui_active_context()
dec = ai_api._dec_interface.decompile(context.func_addr)
Expand Down Expand Up @@ -124,6 +123,12 @@ def send_message(self, add_text=True, role="user"):
if not user_text:
return

# do aiapi calback
if self.ai_api:
send_callback = self.ai_api.chat_event_callbacks.get("send", None)
if send_callback:
send_callback(user_text)

# Display user message
if add_text:
self.add_message(user_text, is_user=True)
Expand All @@ -145,6 +150,12 @@ def receive_message(self, assistant_message):
# Display assistant message
self.add_message(assistant_message, is_user=False)

# do aiapi calback
if self.ai_api:
recv_callback = self.ai_api.chat_event_callbacks.get("receive", None)
if recv_callback:
recv_callback(assistant_message)

# Append to chat history
self.chat_history.append({"role": "user", "content": assistant_message})

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ install_requires =
litellm>=1.44.27
tiktoken
Jinja2
libbs>=2.0.2
libbs>=2.1.0

python_requires = >= 3.10
include_package_data = True
Expand Down

0 comments on commit 330689b

Please sign in to comment.