mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-18 18:53:10 +00:00
IMPROVEMENT self-query template (#13305)
- [ ] https://github.com/langchain-ai/langchain/pull/12694#discussion_r1391334719 -> keep date - [x] https://github.com/langchain-ai/langchain/pull/12694#discussion_r1391336586
This commit is contained in:
parent
b46f88d364
commit
50a5c919f0
@ -1,4 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
import warnings
|
||||||
from typing import Any, Literal, Optional, Sequence, Union
|
from typing import Any, Literal, Optional, Sequence, Union
|
||||||
|
|
||||||
from typing_extensions import TypedDict
|
from typing_extensions import TypedDict
|
||||||
@ -55,6 +56,8 @@ GRAMMAR = r"""
|
|||||||
|
|
||||||
|
|
||||||
class ISO8601Date(TypedDict):
|
class ISO8601Date(TypedDict):
|
||||||
|
"""A date in ISO 8601 format (YYYY-MM-DD)."""
|
||||||
|
|
||||||
date: str
|
date: str
|
||||||
type: Literal["date"]
|
type: Literal["date"]
|
||||||
|
|
||||||
@ -140,11 +143,11 @@ class QueryTransformer(Transformer):
|
|||||||
item = str(item).strip("\"'")
|
item = str(item).strip("\"'")
|
||||||
try:
|
try:
|
||||||
datetime.datetime.strptime(item, "%Y-%m-%d")
|
datetime.datetime.strptime(item, "%Y-%m-%d")
|
||||||
except ValueError as e:
|
except ValueError:
|
||||||
raise ValueError(
|
warnings.warn(
|
||||||
"Dates are expected to be provided in ISO 8601 date format "
|
"Dates are expected to be provided in ISO 8601 date format "
|
||||||
"(YYYY-MM-DD)."
|
"(YYYY-MM-DD)."
|
||||||
) from e
|
)
|
||||||
return {"date": item, "type": "date"}
|
return {"date": item, "type": "date"}
|
||||||
|
|
||||||
def string(self, item: Any) -> str:
|
def string(self, item: Any) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user