Skip to content

Commit

Permalink
chore(): modify log
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshinexcode committed Aug 6, 2024
1 parent 2bcc326 commit a3e846f
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions agents/addon/extension/litellm_python/litellm_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def on_start(self, rte: RteEnv) -> None:
api_key = rte.get_property_string(PROPERTY_API_KEY)
litellm_config.api_key = api_key
except Exception as e:
logger.error(f"GetProperty required {PROPERTY_API_KEY} failed, err: {e}")
logger.error(f"get_property_string required {PROPERTY_API_KEY} failed, err: {e}")
return

for key in [PROPERTY_GREETING, PROPERTY_MODEL, PROPERTY_PROMPT]:
Expand All @@ -64,19 +64,19 @@ def on_start(self, rte: RteEnv) -> None:
if val:
litellm_config.key = val
except Exception as e:
logger.warning(f"GetProperty optional {key} failed, err: {e}")
logger.warning(f"get_property_string optional {key} failed, err: {e}")

for key in [PROPERTY_FREQUENCY_PENALTY, PROPERTY_PRESENCE_PENALTY, PROPERTY_TEMPERATURE, PROPERTY_TOP_P]:
try:
litellm_config.key = float(rte.get_property_float(key))
except Exception as e:
logger.warning(f"GetProperty optional {key} failed, err: {e}")
logger.warning(f"get_property_float optional {key} failed, err: {e}")

for key in [PROPERTY_MAX_MEMORY_LENGTH, PROPERTY_MAX_TOKENS]:
try:
litellm_config.key = int(rte.get_property_int(key))
except Exception as e:
logger.warning(f"GetProperty optional {key} failed, err: {e}")
logger.warning(f"get_property_int optional {key} failed, err: {e}")

# Create LiteLLM instance
self.litellm = LiteLLM(litellm_config)
Expand Down Expand Up @@ -140,7 +140,7 @@ def on_data(self, rte: RteEnv, data: Data) -> None:
logger.info("ignore non-final input")
return
except Exception as e:
logger.error(f"OnData GetProperty {DATA_IN_TEXT_DATA_PROPERTY_IS_FINAL} failed, err: {e}")
logger.error(f"on_data get_property_bool {DATA_IN_TEXT_DATA_PROPERTY_IS_FINAL} failed, err: {e}")
return

# Get input text
Expand All @@ -149,9 +149,9 @@ def on_data(self, rte: RteEnv, data: Data) -> None:
if not input_text:
logger.info("ignore empty text")
return
logger.info(f"OnData input text: [{input_text}]")
logger.info(f"on_data input text: [{input_text}]")
except Exception as e:
logger.error(f"OnData GetProperty {DATA_IN_TEXT_DATA_PROPERTY_TEXT} failed, err: {e}")
logger.error(f"on_data get_property_string {DATA_IN_TEXT_DATA_PROPERTY_TEXT} failed, err: {e}")
return

# Prepare memory
Expand All @@ -161,12 +161,12 @@ def on_data(self, rte: RteEnv, data: Data) -> None:

def chat_completions_stream_worker(start_time, input_text, memory):
try:
logger.info(f"GetChatCompletionsStream for input text: [{input_text}] memory: {memory}")
logger.info(f"chat_completions_stream_worker for input text: [{input_text}] memory: {memory}")

# Get result from AI
resp = self.litellm.get_chat_completions_stream(memory)
if resp is None:
logger.info(f"GetChatCompletionsStream for input text: [{input_text}] failed")
logger.info(f"chat_completions_stream_worker for input text: [{input_text}] failed")
return

sentence = ""
Expand All @@ -175,7 +175,7 @@ def chat_completions_stream_worker(start_time, input_text, memory):

for chat_completions in resp:
if start_time < self.outdate_ts:
logger.info(f"GetChatCompletionsStream recv interrupt and flushing for input text: [{input_text}], startTs: {start_time}, outdateTs: {self.outdate_ts}")
logger.info(f"chat_completions_stream_worker recv interrupt and flushing for input text: [{input_text}], startTs: {start_time}, outdateTs: {self.outdate_ts}")
break

if (len(chat_completions.choices) > 0 and chat_completions.choices[0].delta.content is not None):
Expand All @@ -192,23 +192,23 @@ def chat_completions_stream_worker(start_time, input_text, memory):
logger.info(f"sentence {sentence} is empty or not final")
break

logger.info(f"GetChatCompletionsStream recv for input text: [{input_text}] got sentence: [{sentence}]")
logger.info(f"chat_completions_stream_worker recv for input text: [{input_text}] got sentence: [{sentence}]")

# send sentence
try:
output_data = Data.create("text_data")
output_data.set_property_string(DATA_OUT_TEXT_DATA_PROPERTY_TEXT, sentence)
output_data.set_property_bool(DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, False)
rte.send_data(output_data)
logger.info(f"GetChatCompletionsStream recv for input text: [{input_text}] sent sentence [{sentence}]")
logger.info(f"chat_completions_stream_worker recv for input text: [{input_text}] sent sentence [{sentence}]")
except Exception as e:
logger.error(f"GetChatCompletionsStream recv for input text: [{input_text}] send sentence [{sentence}] failed, err: {e}")
logger.error(f"chat_completions_stream_worker recv for input text: [{input_text}] send sentence [{sentence}] failed, err: {e}")
break

sentence = ""
if not first_sentence_sent:
first_sentence_sent = True
logger.info(f"GetChatCompletionsStream recv for input text: [{input_text}] first sentence sent, first_sentence_latency {get_micro_ts() - start_time}ms")
logger.info(f"chat_completions_stream_worker recv for input text: [{input_text}] first sentence sent, first_sentence_latency {get_micro_ts() - start_time}ms")

# remember response as assistant content in memory
memory.append({"role": "assistant", "content": full_content})
Expand All @@ -219,12 +219,12 @@ def chat_completions_stream_worker(start_time, input_text, memory):
output_data.set_property_string(DATA_OUT_TEXT_DATA_PROPERTY_TEXT, sentence)
output_data.set_property_bool(DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, True)
rte.send_data(output_data)
logger.info(f"GetChatCompletionsStream for input text: [{input_text}] end of segment with sentence [{sentence}] sent")
logger.info(f"chat_completions_stream_worker for input text: [{input_text}] end of segment with sentence [{sentence}] sent")
except Exception as e:
logger.error(f"GetChatCompletionsStream for input text: [{input_text}] end of segment with sentence [{sentence}] send failed, err: {e}")
logger.error(f"chat_completions_stream_worker for input text: [{input_text}] end of segment with sentence [{sentence}] send failed, err: {e}")

except Exception as e:
logger.error(f"GetChatCompletionsStream for input text: [{input_text}] failed, err: {e}")
logger.error(f"chat_completions_stream_worker for input text: [{input_text}] failed, err: {e}")

# Start thread to request and read responses from LiteLLM
start_time = get_micro_ts()
Expand Down

0 comments on commit a3e846f

Please sign in to comment.