Spaces:
Running
Running
cleaner
Browse files
src/proxy_lite/logger.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import asyncio
|
2 |
import logging
|
3 |
import sys
|
4 |
-
import time # Added for time.sleep
|
5 |
from typing import Literal
|
6 |
from uuid import uuid4
|
7 |
|
@@ -9,29 +8,18 @@ from rich.logging import RichHandler
|
|
9 |
|
10 |
|
11 |
class StructuredLogger(logging.Logger):
|
12 |
-
def
|
13 |
-
"""
|
14 |
try:
|
15 |
sys.stdout.write("\r") # Overwrite current line
|
16 |
for char in message:
|
17 |
sys.stdout.write(char)
|
18 |
sys.stdout.flush()
|
19 |
-
|
20 |
sys.stdout.write("\n")
|
21 |
except Exception:
|
22 |
pass
|
23 |
|
24 |
-
async def stream_message(self, message: str) -> None:
|
25 |
-
"""Streams the message character by character in a separate thread."""
|
26 |
-
return await asyncio.to_thread(self._stream_message_sync, message)
|
27 |
-
|
28 |
-
# def info_stream(self, msg: str) -> Coroutine[Any, Any, None]:
|
29 |
-
# """Special method for streaming messages that returns a coroutine."""
|
30 |
-
# # Log the message normally first
|
31 |
-
# # self.info(msg)
|
32 |
-
# # Return the streaming coroutine
|
33 |
-
# return self.stream_message(msg)
|
34 |
-
|
35 |
def _log(
|
36 |
self,
|
37 |
level,
|
@@ -102,5 +90,3 @@ logging.setLoggerClass(StructuredLogger)
|
|
102 |
|
103 |
# Initialize logger
|
104 |
logger = create_logger(__name__, level="INFO")
|
105 |
-
|
106 |
-
stream_logger = create_logger(__name__, level="INFO", detailed_name=False)
|
|
|
1 |
import asyncio
|
2 |
import logging
|
3 |
import sys
|
|
|
4 |
from typing import Literal
|
5 |
from uuid import uuid4
|
6 |
|
|
|
8 |
|
9 |
|
10 |
class StructuredLogger(logging.Logger):
|
11 |
+
async def stream_message(self, message: str) -> None:
|
12 |
+
"""Streams the message character by character asynchronously."""
|
13 |
try:
|
14 |
sys.stdout.write("\r") # Overwrite current line
|
15 |
for char in message:
|
16 |
sys.stdout.write(char)
|
17 |
sys.stdout.flush()
|
18 |
+
await asyncio.sleep(0.002)
|
19 |
sys.stdout.write("\n")
|
20 |
except Exception:
|
21 |
pass
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def _log(
|
24 |
self,
|
25 |
level,
|
|
|
90 |
|
91 |
# Initialize logger
|
92 |
logger = create_logger(__name__, level="INFO")
|
|
|
|
src/proxy_lite/solvers/simple_solver.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
import json
|
3 |
import re
|
4 |
from functools import cached_property
|
5 |
-
from typing import
|
6 |
|
7 |
from proxy_lite.agents import AgentConfigTypes, Agents, BaseAgent
|
8 |
from proxy_lite.environments.environment_base import Action, Observation
|
@@ -27,7 +27,6 @@ class SimpleSolverConfig(BaseSolverConfig):
|
|
27 |
class SimpleSolver(BaseSolver):
|
28 |
task: Optional[str] = None
|
29 |
complete: bool = False
|
30 |
-
coroutines: list[Coroutine[Any, Any, None]] = []
|
31 |
|
32 |
@cached_property
|
33 |
def tools(self) -> list[Tool]:
|
@@ -84,7 +83,7 @@ class SimpleSolver(BaseSolver):
|
|
84 |
|
85 |
self.logger.info("🌐 [bold blue]Observation:[/]")
|
86 |
# await self.logger.stream_message(observation_content)
|
87 |
-
self.logger.
|
88 |
|
89 |
# Extract text between thinking tags if present
|
90 |
thinking_match = re.search(r"<thinking>(.*?)</thinking>", text_content, re.DOTALL)
|
@@ -92,7 +91,7 @@ class SimpleSolver(BaseSolver):
|
|
92 |
|
93 |
self.logger.info("🧠 [bold purple]Thinking:[/]")
|
94 |
# await self.logger.stream_message(thinking_content)
|
95 |
-
self.logger.
|
96 |
|
97 |
return Action(tool_calls=message.tool_calls, text=text_content)
|
98 |
|
|
|
2 |
import json
|
3 |
import re
|
4 |
from functools import cached_property
|
5 |
+
from typing import Literal, Optional
|
6 |
|
7 |
from proxy_lite.agents import AgentConfigTypes, Agents, BaseAgent
|
8 |
from proxy_lite.environments.environment_base import Action, Observation
|
|
|
27 |
class SimpleSolver(BaseSolver):
|
28 |
task: Optional[str] = None
|
29 |
complete: bool = False
|
|
|
30 |
|
31 |
@cached_property
|
32 |
def tools(self) -> list[Tool]:
|
|
|
83 |
|
84 |
self.logger.info("🌐 [bold blue]Observation:[/]")
|
85 |
# await self.logger.stream_message(observation_content)
|
86 |
+
await self.logger.stream_message(observation_content)
|
87 |
|
88 |
# Extract text between thinking tags if present
|
89 |
thinking_match = re.search(r"<thinking>(.*?)</thinking>", text_content, re.DOTALL)
|
|
|
91 |
|
92 |
self.logger.info("🧠 [bold purple]Thinking:[/]")
|
93 |
# await self.logger.stream_message(thinking_content)
|
94 |
+
await self.logger.stream_message(thinking_content)
|
95 |
|
96 |
return Action(tool_calls=message.tool_calls, text=text_content)
|
97 |
|