Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Self-healing-LLM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ammar Ahmed
Self-healing-LLM
Commits
bafb34c3
Commit
bafb34c3
authored
9 months ago
by
Ammar Ahmed
Browse files
Options
Downloads
Patches
Plain Diff
fixed return values of extract and handled error in test cases
parent
043900de
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
llama/extraction/extract.go
+5
-4
5 additions, 4 deletions
llama/extraction/extract.go
llama/extraction/extract_test.go
+3
-1
3 additions, 1 deletion
llama/extraction/extract_test.go
with
8 additions
and
5 deletions
llama/extraction/extract.go
+
5
−
4
View file @
bafb34c3
package
extraction
package
extraction
import
(
import
(
"fmt"
"strings"
"strings"
)
)
...
@@ -20,17 +21,17 @@ var RustPrompt = "The code should be in the Rust programming language. There sho
...
@@ -20,17 +21,17 @@ var RustPrompt = "The code should be in the Rust programming language. There sho
// }
// }
// Extract extracts the code snippet between ``` and removes the language identifier.
// Extract extracts the code snippet between ``` and removes the language identifier.
func
Extract
(
output
string
)
string
{
func
Extract
(
output
string
)
(
string
,
error
)
{
parts
:=
strings
.
Split
(
output
,
"```"
)
parts
:=
strings
.
Split
(
output
,
"```"
)
if
len
(
parts
)
<
2
{
if
len
(
parts
)
<
2
{
return
""
// Handle the case if format is incorrect: Return empty string
return
""
,
fmt
.
Errorf
(
"the string wasn't in a proper format"
)
// Handle the case if format is incorrect: Return empty string
}
}
// Trim the language identifier like `go` or `rust` from the code
// Trim the language identifier like `go` or `rust` from the code
code
:=
parts
[
1
]
code
:=
parts
[
1
]
lines
:=
strings
.
SplitN
(
code
,
"
\n
"
,
2
)
lines
:=
strings
.
SplitN
(
code
,
"
\n
"
,
2
)
if
len
(
lines
)
>
1
{
if
len
(
lines
)
>
1
{
return
"
\n
"
+
lines
[
1
]
// Return the code without the first line (language identifier)
return
"
\n
"
+
lines
[
1
]
,
nil
// Return the code without the first line (language identifier)
}
}
return
""
return
""
,
fmt
.
Errorf
(
"the string doesn't contain any lines"
)
}
}
This diff is collapsed.
Click to expand it.
llama/extraction/extract_test.go
+
3
−
1
View file @
bafb34c3
...
@@ -71,9 +71,11 @@ var testCases = []struct {
...
@@ -71,9 +71,11 @@ var testCases = []struct {
func
TestExtraction
(
t
*
testing
.
T
)
{
func
TestExtraction
(
t
*
testing
.
T
)
{
for
_
,
tc
:=
range
testCases
{
for
_
,
tc
:=
range
testCases
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
output
:=
Extract
(
tc
.
input
)
output
,
err
:=
Extract
(
tc
.
input
)
if
output
!=
tc
.
expected
{
if
output
!=
tc
.
expected
{
t
.
Errorf
(
"Test %s failed: Expected %q, got %q"
,
tc
.
name
,
tc
.
expected
,
output
)
t
.
Errorf
(
"Test %s failed: Expected %q, got %q"
,
tc
.
name
,
tc
.
expected
,
output
)
t
.
Log
(
err
.
Error
())
}
}
})
})
}
}
...
...
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