Skip to content

Commit

Permalink
recalculate_token_every_question (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaojin3616 committed Jan 29, 2024
2 parents a486465 + 31825e7 commit cd48726
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/bisheng-langchain/bisheng_langchain/chat_models/sensetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,12 @@ def _completion_with_retry(**kwargs: Any) -> Any:
"max_new_tokens": self.max_tokens,
'stream': False#self.streaming
}


token = encode_jwt_token(self.access_key_id, self.secret_access_key)
if isinstance(token, bytes):
token = token.decode('utf-8')
self.client.headers.update({'Authorization': 'Bearer {}'.format(token)})

response = self.client.post(url=url, json=params).json()
return response
rsp_dict = _completion_with_retry(**kwargs)
Expand All @@ -231,6 +236,12 @@ def _completion_with_retry(**kwargs: Any) -> Any:
async def acompletion_with_retry(self, **kwargs: Any) -> Any:
"""Use tenacity to retry the async completion call."""
retry_decorator = _create_retry_decorator(self)

token = encode_jwt_token(self.access_key_id, self.secret_access_key)
if isinstance(token, bytes):
token = token.decode('utf-8')
self.client.headers.update({'Authorization': 'Bearer {}'.format(token)})

if self.streaming:
self.client.headers.update({'Accept': 'text/event-stream'})
else:
Expand Down Expand Up @@ -411,4 +422,4 @@ def _get_invocation_params(self,
@property
def _llm_type(self) -> str:
"""Return type of chat model."""
return 'sense-chat'
return 'sense-chat'

0 comments on commit cd48726

Please sign in to comment.