Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add logging to IDEService in OpenAI and pipeline modules #389

Merged
merged 2 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions devchat/llm/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import httpx
import openai

from devchat.ide import IDEService

from .pipeline import (
RetryException,
exception_handle,
Expand Down Expand Up @@ -83,6 +85,7 @@ def retry_timeout(chunks):
for chunk in chunks:
yield chunk
except (openai.APIConnectionError, openai.APITimeoutError) as err:
IDEService().ide_logging("info", f"in retry_timeout: err: {err}")
raise RetryException(err) from err


Expand Down Expand Up @@ -127,8 +130,10 @@ def content_to_json(content):
response_obj = json.loads(content_no_block)
return response_obj
except json.JSONDecodeError as err:
IDEService().ide_logging("info", f"in content_to_json: json decode error: {err}")
raise RetryException(err) from err
except Exception as err:
IDEService().ide_logging("info", f"in content_to_json: other error: {err}")
raise err


Expand Down
8 changes: 8 additions & 0 deletions devchat/llm/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import sys
import time
from typing import Dict

import openai

from devchat.ide import IDEService


class RetryException(Exception):
def __init__(self, err):
Expand All @@ -17,8 +20,10 @@ def wrapper(*args, **kwargs):
except RetryException as err:
if index + 1 == times:
raise err.error
IDEService().ide_logging("debug", f"has retries: {index + 1}")
continue
except Exception as err:
IDEService().ide_logging("info", f"exception: {err}")
raise err.error

return wrapper
Expand Down Expand Up @@ -59,6 +64,7 @@ def wrapper(*args, **kwargs):

def pipeline(*funcs):
def wrapper(*args, **kwargs):
start_time = time.time()
for index, func in enumerate(funcs):
if index > 0:
if isinstance(args, Dict) and args.get("__type__", None) == "parallel":
Expand All @@ -67,6 +73,8 @@ def wrapper(*args, **kwargs):
args = func(args)
else:
args = func(*args, **kwargs)
end_time = time.time()
IDEService().ide_logging("debug", f"time on pipeline: {end_time-start_time}")
return args

return wrapper
Expand Down
Loading