Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.5 json parsing fix #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/langchain/langchain/chat_models/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def _create_retry_decorator(llm: ChatOpenAI) -> Callable[[Any], Any]:
| retry_if_exception_type(openai.error.APIConnectionError)
| retry_if_exception_type(openai.error.RateLimitError)
| retry_if_exception_type(openai.error.ServiceUnavailableError)
| retry_if_exception_type(ValueError)
),
before_sleep=before_sleep_log(logger, logging.WARNING),
)
Expand Down
6 changes: 5 additions & 1 deletion libs/langchain/langchain/output_parsers/openai_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import json5
from typing import Any, Dict, List, Type, Union

from pydantic import BaseModel, root_validator
Expand Down Expand Up @@ -79,7 +80,10 @@ def validate_schema(cls, values: Dict) -> Dict:
def parse_result(self, result: List[Generation]) -> Any:
_result = super().parse_result(result)
if self.args_only:
pydantic_args = self.pydantic_schema.parse_raw(_result) # type: ignore
_parsed_result = json5.loads(_result)
_cleaned_result = json.dumps(_parsed_result)

pydantic_args = self.pydantic_schema.parse_raw(_cleaned_result) # type: ignore
else:
fn_name = _result["name"]
_args = _result["arguments"]
Expand Down
Loading