mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-10 05:20:39 +00:00
Core: fix Anthropic json issue in streaming (#16670)
**Description:** fix ChatAnthropic json issue in streaming **Issue:** https://github.com/langchain-ai/langchain/issues/16423 **Dependencies:** n/a --------- Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
This commit is contained in:
parent
e451c8adc1
commit
6ef718c5f4
@ -138,7 +138,7 @@ def parse_json_markdown(
|
||||
The parsed JSON object as a Python dictionary.
|
||||
"""
|
||||
# Try to find JSON string within triple backticks
|
||||
match = re.search(r"```(json)?(.*)```", json_string, re.DOTALL)
|
||||
match = re.search(r"```(json)?(.*)(```)?", json_string, re.DOTALL)
|
||||
|
||||
# If no match found, assume the entire string is a JSON string
|
||||
if match is None:
|
||||
|
@ -137,6 +137,43 @@ TEXT_BEFORE_AND_AFTER = """Action: Testing
|
||||
```
|
||||
This should do the trick"""
|
||||
|
||||
WITHOUT_END_BRACKET = """Here is a response formatted as schema:
|
||||
|
||||
```json
|
||||
{
|
||||
"foo": "bar"
|
||||
|
||||
|
||||
"""
|
||||
|
||||
WITH_END_BRACKET = """Here is a response formatted as schema:
|
||||
|
||||
```json
|
||||
{
|
||||
"foo": "bar"
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
WITH_END_TICK = """Here is a response formatted as schema:
|
||||
|
||||
```json
|
||||
{
|
||||
"foo": "bar"
|
||||
}
|
||||
```
|
||||
"""
|
||||
|
||||
WITH_END_TEXT = """Here is a response formatted as schema:
|
||||
|
||||
```
|
||||
{
|
||||
"foo": "bar"
|
||||
|
||||
```
|
||||
This should do the trick
|
||||
"""
|
||||
|
||||
TEST_CASES = [
|
||||
GOOD_JSON,
|
||||
JSON_WITH_NEW_LINES,
|
||||
@ -148,6 +185,10 @@ TEST_CASES = [
|
||||
TEXT_BEFORE,
|
||||
TEXT_AFTER,
|
||||
TEXT_BEFORE_AND_AFTER,
|
||||
WITHOUT_END_BRACKET,
|
||||
WITH_END_BRACKET,
|
||||
WITH_END_TICK,
|
||||
WITH_END_TEXT,
|
||||
]
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user