Skip to content

Commit

Permalink
refactor(sdk): clean the naming of the prompt var
Browse files Browse the repository at this point in the history
  • Loading branch information
Lerri-Cofannos committed Aug 22, 2023
1 parent 511718f commit bee18f4
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions sdk-python/omnilogger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def start_listener(url: str):

class OpenAIFilter(logging.Filter):
url: str
t_prompt: str
prompt: str

def __init__(self, url):
self.url = url
self.t_prompt = ""
self.prompt = ""

def filter(self, record) -> bool:
msg = record.getMessage()
Expand All @@ -51,7 +51,6 @@ def filter(self, record) -> bool:
record.msg = "JSONDecodeError for OpenAI response: " + msg
return True
return False
record.msg += record.levelname
return True

def handle_openai_response(self, data: str):
Expand All @@ -60,17 +59,16 @@ def handle_openai_response(self, data: str):
output = json.loads(output)

log = {
"input": self.t_prompt,
"input": self.prompt,
"datetime_utc": datetime.utcfromtimestamp(output["created"]),
"output": output["choices"][0]["text"],
"total_tokens": output["usage"]["total_tokens"],
}
self.t_prompt = ""
send_to_db(self.url, log)

def handle_openai_request(self, data: str):
t_data = data.split('"prompt": "')[1]
self.t_prompt = t_data.split('", "temperature"')[0]
self.prompt = data.split('"prompt": "')[1]
self.prompt = self.prompt.split('", "temperature"')[0]


class StreamToLogger(object):
Expand Down

0 comments on commit bee18f4

Please sign in to comment.