Skip to content

Commit

Permalink
fix: check result should be string. (langgenius#1959)
Browse files Browse the repository at this point in the history
  • Loading branch information
GarfieldDai authored Jan 5, 2024
1 parent 87832ed commit a8cedea
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions api/core/external_data_tool/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def query(self, inputs: dict, query: Optional[str] = None) -> str:
if not api_based_extension:
raise ValueError("[External data tool] API query failed, variable: {}, "
"error: api_based_extension_id is invalid"
.format(self.config.get('variable')))
.format(self.variable))

# decrypt api_key
api_key = encrypter.decrypt_token(
Expand All @@ -74,7 +74,7 @@ def query(self, inputs: dict, query: Optional[str] = None) -> str:
)
except Exception as e:
raise ValueError("[External data tool] API query failed, variable: {}, error: {}".format(
self.config.get('variable'),
self.variable,
e
))

Expand All @@ -87,6 +87,10 @@ def query(self, inputs: dict, query: Optional[str] = None) -> str:

if 'result' not in response_json:
raise ValueError("[External data tool] API query failed, variable: {}, error: result not found in response"
.format(self.config.get('variable')))
.format(self.variable))

if not isinstance(response_json['result'], str):
raise ValueError("[External data tool] API query failed, variable: {}, error: result is not string"
.format(self.variable))

return response_json['result']

0 comments on commit a8cedea

Please sign in to comment.