langchain[patch]: Add missing type annotations (#24889)

Adds missing type annotations in preparation for pydantic 2 upgrade.
This commit is contained in:
Eugene Yurtsev 2024-07-31 14:09:22 -04:00 committed by GitHub
parent 30f18c7b02
commit 2019e31bc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 7 additions and 7 deletions

View File

@ -1,6 +1,6 @@
import json import json
import re import re
from typing import Union from typing import Pattern, Union
from langchain_core.agents import AgentAction, AgentFinish from langchain_core.agents import AgentAction, AgentFinish
from langchain_core.exceptions import OutputParserException from langchain_core.exceptions import OutputParserException
@ -17,7 +17,7 @@ class ChatOutputParser(AgentOutputParser):
format_instructions: str = FORMAT_INSTRUCTIONS format_instructions: str = FORMAT_INSTRUCTIONS
"""Default formatting instructions""" """Default formatting instructions"""
pattern = re.compile(r"^.*?`{3}(?:json)?\n(.*?)`{3}.*?$", re.DOTALL) pattern: Pattern = re.compile(r"^.*?`{3}(?:json)?\n(.*?)`{3}.*?$", re.DOTALL)
"""Regex pattern to parse the output.""" """Regex pattern to parse the output."""
def get_format_instructions(self) -> str: def get_format_instructions(self) -> str:

View File

@ -1,6 +1,6 @@
import json import json
import re import re
from typing import Union from typing import Pattern, Union
from langchain_core.agents import AgentAction, AgentFinish from langchain_core.agents import AgentAction, AgentFinish
from langchain_core.exceptions import OutputParserException from langchain_core.exceptions import OutputParserException
@ -42,7 +42,7 @@ class ReActJsonSingleInputOutputParser(AgentOutputParser):
""" """
pattern = re.compile(r"^.*?`{3}(?:json)?\n?(.*?)`{3}.*?$", re.DOTALL) pattern: Pattern = re.compile(r"^.*?`{3}(?:json)?\n?(.*?)`{3}.*?$", re.DOTALL)
"""Regex pattern to parse the output.""" """Regex pattern to parse the output."""
def get_format_instructions(self) -> str: def get_format_instructions(self) -> str:

View File

@ -3,7 +3,7 @@ from __future__ import annotations
import json import json
import logging import logging
import re import re
from typing import Optional, Union from typing import Optional, Pattern, Union
from langchain_core.agents import AgentAction, AgentFinish from langchain_core.agents import AgentAction, AgentFinish
from langchain_core.exceptions import OutputParserException from langchain_core.exceptions import OutputParserException
@ -23,7 +23,7 @@ class StructuredChatOutputParser(AgentOutputParser):
format_instructions: str = FORMAT_INSTRUCTIONS format_instructions: str = FORMAT_INSTRUCTIONS
"""Default formatting instructions""" """Default formatting instructions"""
pattern = re.compile(r"```(?:json\s+)?(\W.*?)```", re.DOTALL) pattern: Pattern = re.compile(r"```(?:json\s+)?(\W.*?)```", re.DOTALL)
"""Regex pattern to parse the output.""" """Regex pattern to parse the output."""
def get_format_instructions(self) -> str: def get_format_instructions(self) -> str:

View File

@ -16,7 +16,7 @@ from tests.unit_tests.llms.fake_llm import FakeLLM
class DummyLLM(LLM): class DummyLLM(LLM):
last_prompt = "" last_prompt: str = ""
def __init__(self, **kwargs: Any): def __init__(self, **kwargs: Any):
super().__init__(**kwargs) super().__init__(**kwargs)