KUNAL SHAW commited on
Implement compatibility for ForwardRef._evaluate
Browse filesAdd compatibility shim for typing.ForwardRef._evaluate.
app.py
CHANGED
|
@@ -14,6 +14,46 @@ An enterprise-grade, production-ready intelligent query routing system that leve
|
|
| 14 |
import streamlit as st
|
| 15 |
import os
|
| 16 |
from typing import List, Dict, Any
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
import cassio
|
| 18 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 19 |
from langchain_community.document_loaders import WebBaseLoader
|
|
|
|
| 14 |
import streamlit as st
|
| 15 |
import os
|
| 16 |
from typing import List, Dict, Any
|
| 17 |
+
|
| 18 |
+
# Compatibility shim for different typing.ForwardRef._evaluate signatures
|
| 19 |
+
# ------------------------------------------------------------
|
| 20 |
+
# Some Python/typing/pydantic versions expect ForwardRef._evaluate to accept
|
| 21 |
+
# recursive_guard as a keyword-only argument, while other versions accept it
|
| 22 |
+
# positionally. When a third-party library calls ForwardRef._evaluate using the
|
| 23 |
+
# older calling convention, it can raise:
|
| 24 |
+
# TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard'
|
| 25 |
+
#
|
| 26 |
+
# This shim wraps/monkeypatches typing.ForwardRef._evaluate so it accepts both
|
| 27 |
+
# calling conventions. It should be safe and only applied at import time.
|
| 28 |
+
try:
|
| 29 |
+
from typing import ForwardRef as _ForwardRef
|
| 30 |
+
|
| 31 |
+
_orig_forwardref_evaluate = getattr(_ForwardRef, "_evaluate", None)
|
| 32 |
+
if _orig_forwardref_evaluate is not None:
|
| 33 |
+
def _evaluate_compat(self, globalns, localns, *args, **kwargs):
|
| 34 |
+
"""
|
| 35 |
+
Compatibility wrapper that attempts to call the original _evaluate
|
| 36 |
+
with whatever args/kwargs were passed. If a TypeError occurs (typical
|
| 37 |
+
when the underlying implementation requires recursive_guard as
|
| 38 |
+
keyword-only), call the original with recursive_guard provided as a
|
| 39 |
+
keyword using the first positional arg if available or an empty set.
|
| 40 |
+
"""
|
| 41 |
+
try:
|
| 42 |
+
return _orig_forwardref_evaluate(self, globalns, localns, *args, **kwargs)
|
| 43 |
+
except TypeError:
|
| 44 |
+
# Older callers passed recursive_guard positionally; newer
|
| 45 |
+
# implementations require recursive_guard as a keyword-only arg.
|
| 46 |
+
recursive_guard = args[0] if args else set()
|
| 47 |
+
return _orig_forwardref_evaluate(self, globalns, localns, recursive_guard=recursive_guard)
|
| 48 |
+
|
| 49 |
+
# Monkeypatch the ForwardRef implementation with the compatibility wrapper
|
| 50 |
+
_ForwardRef._evaluate = _evaluate_compat
|
| 51 |
+
except Exception:
|
| 52 |
+
# If anything goes wrong here, do not prevent app import — let original
|
| 53 |
+
# behavior surface later (so the original error will be visible).
|
| 54 |
+
pass
|
| 55 |
+
# ------------------------------------------------------------
|
| 56 |
+
|
| 57 |
import cassio
|
| 58 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 59 |
from langchain_community.document_loaders import WebBaseLoader
|