Skip to content

Commit

Permalink
fix typing in worker.py and set body value correctly in `http_cli…
Browse files Browse the repository at this point in the history
…ent.py`
  • Loading branch information
the-praxs committed Apr 17, 2024
1 parent 7a83f6f commit 4af7f7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions agentops/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ class Response:
def __init__(self, status: HttpStatus = HttpStatus.UNKNOWN, body: Optional[dict] = None):
self.status: HttpStatus = status
self.code: int = status.value
self.body = body
if not self.body:
self.body = {}
self.body = body if body else {}

def parse(self, res: requests.models.Response):
res_body = res.json()
Expand Down
12 changes: 6 additions & 6 deletions agentops/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import threading
import time
from .http_client import HttpClient
from .config import Configuration, ConfigurationError
from .config import Configuration
from .session import Session
from .helpers import safe_serialize, filter_unjsonable
from typing import Dict
from typing import Dict, Optional


class Worker:
Expand All @@ -17,7 +17,7 @@ def __init__(self, config: Configuration) -> None:
self.thread = threading.Thread(target=self.run)
self.thread.daemon = True
self.thread.start()
self._session: Session | None = None
self._session: Optional[Session] = None

def add_event(self, event: dict) -> None:
with self.lock:
Expand All @@ -32,7 +32,7 @@ def flush_queue(self) -> None:
self.queue = []

payload = {
"session_id": self._session.session_id,
"session_id": getattr(self._session, "session_id", None),
"events": events
}

Expand All @@ -42,7 +42,7 @@ def flush_queue(self) -> None:
self.config.api_key,
self.config.parent_key)

def start_session(self, session: Session) -> None:
def start_session(self, session: Session) -> bool:
self._session = session
with self.lock:
payload = {
Expand Down Expand Up @@ -94,7 +94,7 @@ def create_agent(self, agent_id, name):
payload = {
"id": agent_id,
"name": name,
"session_id": self._session.session_id
"session_id": getattr(self._session, "session_id", None),
}

serialized_payload = \
Expand Down

0 comments on commit 4af7f7d

Please sign in to comment.