Skip to content

Commit

Permalink
modify 's log level
Browse files Browse the repository at this point in the history
  • Loading branch information
braisedpork1964 committed Oct 11, 2024
1 parent 40ce40d commit 8d66db6
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions lagent/llms/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,11 @@ def _chat(self, messages: List[dict], **gen_params) -> str:
response = raw_response.json()
return response['choices'][0]['message']['content'].strip()
except requests.ConnectionError:
print('Got connection error, retrying...')
self.logger.error('Got connection error, retrying...')
continue
except requests.JSONDecodeError:
print('JsonDecode error, got', str(raw_response.content))
self.logger.error('JsonDecode error, got ' +
str(raw_response.content))
continue
except KeyError:
if 'error' in response:
Expand All @@ -236,8 +237,8 @@ def _chat(self, messages: List[dict], **gen_params) -> str:
self.logger.warn(f'insufficient_quota key: {key}')
continue

print('Find error message in response: ',
str(response['error']))
self.logger.error('Find error message in response: ' +
str(response['error']))
except Exception as error:
print(str(error))
max_num_retries += 1
Expand Down Expand Up @@ -333,10 +334,11 @@ def streaming(raw_response):
proxies=self.proxies)
return streaming(raw_response)
except requests.ConnectionError:
print('Got connection error, retrying...')
self.logger.error('Got connection error, retrying...')
continue
except requests.JSONDecodeError:
print('JsonDecode error, got', str(raw_response.content))
self.logger.error('JsonDecode error, got ' +
str(raw_response.content))
continue
except KeyError:
if 'error' in response:
Expand All @@ -348,8 +350,8 @@ def streaming(raw_response):
self.logger.warn(f'insufficient_quota key: {key}')
continue

print('Find error message in response: ',
str(response['error']))
self.logger.error('Find error message in response: ' +
str(response['error']))
except Exception as error:
print(str(error))
max_num_retries += 1
Expand Down Expand Up @@ -659,14 +661,14 @@ async def _chat(self, messages: List[dict], **gen_params) -> str:
return response['choices'][0]['message'][
'content'].strip()
except aiohttp.ClientConnectionError:
print('Got connection error, retrying...')
self.logger.error('Got connection error, retrying...')
continue
except aiohttp.ClientResponseError as e:
print('Response error, got', str(e))
self.logger.error('Response error, got ' + str(e))
continue
except json.JSONDecodeError:
print('JsonDecode error, got', await
resp.text(errors='replace'))
self.logger.error('JsonDecode error, got ' +
(await resp.text(errors='replace')))
continue
except KeyError:
if 'error' in response:
Expand All @@ -678,8 +680,8 @@ async def _chat(self, messages: List[dict], **gen_params) -> str:
self.logger.warn(f'insufficient_quota key: {key}')
continue

print('Find error message in response: ',
str(response['error']))
self.logger.error('Find error message in response: ' +
str(response['error']))
except Exception as error:
print(str(error))
max_num_retries += 1
Expand Down Expand Up @@ -729,7 +731,7 @@ async def streaming(raw_response):
return
yield choice['delta'].get('content', '')
except Exception as exc:
print(
self.logger.error(
f'response {decoded} lead to exception of {str(exc)}'
)
raise
Expand Down Expand Up @@ -779,10 +781,10 @@ async def streaming(raw_response):
yield msg
return
except aiohttp.ClientConnectionError:
print('Got connection error, retrying...')
self.logger.error('Got connection error, retrying...')
continue
except aiohttp.ClientResponseError as e:
print('Response error, got', str(e))
self.logger.error('Response error, got ' + str(e))
continue
except KeyError:
if 'error' in response:
Expand All @@ -794,8 +796,8 @@ async def streaming(raw_response):
self.logger.warn(f'insufficient_quota key: {key}')
continue

print('Find error message in response: ',
str(response['error']))
self.logger.error('Find error message in response: ' +
str(response['error']))
except Exception as error:
print(str(error))
max_num_retries += 1
Expand Down

0 comments on commit 8d66db6

Please sign in to comment.