Skip to content

Commit

Permalink
log response from requests + refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
AdiGro committed Feb 14, 2024
1 parent 4e8e301 commit b085cb8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions characterai/characterai.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def request(
response = session.put(link, headers=headers, json=data)

data = json.loads(response.text.split("\n")[-2]) if split else response.json()
_log.debug(f"Response code: {response.status_code}")
_log.debug(f"Response data: {data}")
if str(data).startswith("{'command': 'neo_error'"):
raise errors.ServerError(data["comment"])
Expand Down Expand Up @@ -320,7 +321,7 @@ def create(
*,
avatar_rel_path: str = "",
base_img_prompt: str = "",
categories: list = [],
categories: list = None,
copyable: bool = True,
definition: str = "",
description: str = "",
Expand All @@ -330,6 +331,8 @@ def create(
token: str = None,
**kwargs,
):
if categories is None:
categories = []
_log.debug(
f"Creating character with greeting: {greeting}, identifier: {identifier}, name: {name}, additional data: {kwargs}"
)
Expand Down Expand Up @@ -362,7 +365,7 @@ def update(
identifier: str,
name: str,
title: str = "",
categories: list = [],
categories: list = None,
definition: str = "",
copyable: bool = True,
description: str = "",
Expand All @@ -371,6 +374,8 @@ def update(
token: str = None,
**kwargs,
):
if categories is None:
categories = []
_log.debug(
f"Updating character with external ID: {external_id}, greeting: {greeting}, identifier: {identifier}, name: {name}, additional data: {kwargs}"
)
Expand Down
4 changes: 4 additions & 0 deletions characterai/pyasynccai.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ async def request(
link, headers=headers, json=data
)

_log.debug(f"Received response: {response}. Status code: {response.status_code}")
_log.debug(f"Response text: {response.text}")


if split:
data = json.loads(response.text.split('\n')[-2])
else:
Expand Down

0 comments on commit b085cb8

Please sign in to comment.