mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +00:00
Log the end-to-end time of generating a streamed response from OpenAI
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from time import perf_counter
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import json
|
import json
|
||||||
@@ -38,6 +39,7 @@ class ThreadedGenerator:
|
|||||||
self.compiled_references = compiled_references
|
self.compiled_references = compiled_references
|
||||||
self.completion_func = completion_func
|
self.completion_func = completion_func
|
||||||
self.response = ""
|
self.response = ""
|
||||||
|
self.start_time = perf_counter()
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self
|
return self
|
||||||
@@ -45,6 +47,8 @@ class ThreadedGenerator:
|
|||||||
def __next__(self):
|
def __next__(self):
|
||||||
item = self.queue.get()
|
item = self.queue.get()
|
||||||
if item is StopIteration:
|
if item is StopIteration:
|
||||||
|
time_to_response = perf_counter() - self.start_time
|
||||||
|
logger.info(f"Time to stream full response: {time_to_response:.3f}")
|
||||||
if self.completion_func:
|
if self.completion_func:
|
||||||
# The completion func effective acts as a callback.
|
# The completion func effective acts as a callback.
|
||||||
# It adds the aggregated response to the conversation history. It's constructed in api.py.
|
# It adds the aggregated response to the conversation history. It's constructed in api.py.
|
||||||
|
|||||||
Reference in New Issue
Block a user