-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aki
committed
Mar 5, 2025
1 parent
84089bc
commit 8cecb4e
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import time | ||
from typing import List, Optional, Dict | ||
|
||
from .tools import Tool | ||
from .models import ChatMessage, LiteLLMModel | ||
|
||
|
||
class SleepPerLastTokenModelLiteLLM(LiteLLMModel): | ||
def __init__(self, sleep_factor: float = 0.01, **kwargs): | ||
super().__init__(**kwargs) | ||
self.sleep_factor = sleep_factor | ||
|
||
def __call__( | ||
self, | ||
messages: List[Dict[str, str]], | ||
stop_sequences: Optional[List[str]] = None, | ||
grammar: Optional[str] = None, | ||
tools_to_call_from: Optional[List[Tool]] = None, | ||
**kwargs, | ||
) -> ChatMessage: | ||
if self.last_input_token_count is not None: | ||
sleep_time = ( | ||
self.last_input_token_count + self.last_output_token_count | ||
) * self.sleep_factor | ||
print(f"Sleeping for {sleep_time:.2f} seconds...") | ||
time.sleep(sleep_time) | ||
|
||
return super().__call__( | ||
messages, stop_sequences, grammar, tools_to_call_from, **kwargs | ||
) |