Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Llama Index
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
Llama Index
Commits
ece8f2dd
Unverified
Commit
ece8f2dd
authored
11 months ago
by
Bryce Freshcorn
Committed by
GitHub
11 months ago
Browse files
Options
Downloads
Patches
Plain Diff
ReAct output parser changes (#13459)
parent
07a0c666
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
llama-index-core/llama_index/core/agent/react/output_parser.py
+5
-4
5 additions, 4 deletions
...-index-core/llama_index/core/agent/react/output_parser.py
llama-index-core/tests/agent/react/test_react_output_parser.py
+16
-0
16 additions, 0 deletions
...-index-core/tests/agent/react/test_react_output_parser.py
with
21 additions
and
4 deletions
llama-index-core/llama_index/core/agent/react/output_parser.py
+
5
−
4
View file @
ece8f2dd
...
...
@@ -15,7 +15,7 @@ from llama_index.core.types import BaseOutputParser
def
extract_tool_use
(
input_text
:
str
)
->
Tuple
[
str
,
str
,
str
]:
pattern
=
(
r
"
\s*Thought: (.*?)\nAction: ([a-zA-Z0-9_]+).*?\nAction Input: .*?(\{.*\})
"
r
"
\s*Thought: (.*?)\n
+
Action: ([a-zA-Z0-9_]+).*?\n
+
Action Input: .*?(\{.*\})
"
)
match
=
re
.
search
(
pattern
,
input_text
,
re
.
DOTALL
)
...
...
@@ -97,15 +97,16 @@ class ReActOutputParser(BaseOutputParser):
is_streaming
=
is_streaming
,
)
# An "Action" should take priority over an "Answer"
if
"
Action:
"
in
output
:
return
parse_action_reasoning_step
(
output
)
if
"
Answer:
"
in
output
:
thought
,
answer
=
extract_final_response
(
output
)
return
ResponseReasoningStep
(
thought
=
thought
,
response
=
answer
,
is_streaming
=
is_streaming
)
if
"
Action:
"
in
output
:
return
parse_action_reasoning_step
(
output
)
raise
ValueError
(
f
"
Could not parse output:
{
output
}
"
)
def
format
(
self
,
output
:
str
)
->
str
:
...
...
This diff is collapsed.
Click to expand it.
llama-index-core/tests/agent/react/test_react_output_parser.py
+
16
−
0
View file @
ece8f2dd
...
...
@@ -22,6 +22,22 @@ def test_extract_tool_use() -> None:
mock_input_text
=
"""
\
Thought: I need to use a tool to help me answer the question.
Action: add
Action Input: {
"
a
"
: 1,
"
b
"
: 1}
"""
thought
,
action
,
action_input
=
extract_tool_use
(
mock_input_text
)
assert
thought
==
"
I need to use a tool to help me answer the question.
"
assert
action
==
"
add
"
assert
action_input
==
'
{
"
a
"
: 1,
"
b
"
: 1}
'
def
test_extract_tool_use_multiline
()
->
None
:
mock_input_text
=
"""
\
Thought: I need to use a tool to help me answer the question.
Action: add
Action Input: {
"
a
"
: 1,
"
b
"
: 1}
"""
thought
,
action
,
action_input
=
extract_tool_use
(
mock_input_text
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment