Skip to content

Commit

Permalink
fix model_garden models (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkuligin authored Aug 22, 2024
1 parent 0150996 commit af264d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
19 changes: 8 additions & 11 deletions libs/vertexai/langchain_google_vertexai/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,22 +374,19 @@ def _parse_response(self, predictions: "Prediction") -> LLMResult:
return LLMResult(generations=generations)

def _parse_prediction(self, prediction: Any) -> str:
if isinstance(prediction, str):
if prediction.startswith("Prompt:\n"):
result = re.search(r"(?s:.*)\nOutput:\n(.*)", prediction)
def _clean_response(response: str) -> str:
if response.startswith("Prompt:\n"):
result = re.search(r"(?s:.*)\nOutput:\n((?s:.*))", response)
if result:
return result[1]
return prediction
return response

if isinstance(prediction, str):
return _clean_response(prediction)

if self.result_arg:
try:
if prediction[self.result_arg].startswith("Prompt:\n"):
result = re.search(
r"(?s:.*)\nOutput:\n(.*)", prediction[self.result_arg]
)
if result:
return result[1]
return prediction[self.result_arg]
return _clean_response(prediction[self.result_arg])
except KeyError:
if isinstance(prediction, str):
error_desc = (
Expand Down
2 changes: 1 addition & 1 deletion libs/vertexai/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langchain-google-vertexai"
version = "1.0.9"
version = "1.0.10"
description = "An integration package connecting Google VertexAI and LangChain"
authors = []
readme = "README.md"
Expand Down

0 comments on commit af264d1

Please sign in to comment.