-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: configurable model; ref: json reponse format
- Loading branch information
Showing
8 changed files
with
88 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,23 @@ | ||
package wingman | ||
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
) | ||
|
||
type Response struct { | ||
Command string | ||
Explanation string | ||
Command string `json:"command"` | ||
Explanation string `json:"explanation"` | ||
} | ||
|
||
// example: | ||
// ai noise | ||
// [COMMAND]: | ||
// ls -la | ||
// the command is multiline | ||
// [EXPLANATION]: | ||
// list all files in the current directory | ||
// this is a multiline explanation | ||
// [END] | ||
// ai noise | ||
func ParseResponseJSON(response string) (Response, error) { | ||
|
||
func ParseResponse(response string) (Response, error) { | ||
lines := strings.Split(response, "\n") | ||
response = strings.Trim(response, "\n\r ") | ||
res := Response{} | ||
|
||
sbCommand := strings.Builder{} | ||
sbExplanation := strings.Builder{} | ||
|
||
var sbCurrent *strings.Builder | ||
|
||
for _, line := range lines { | ||
if strings.HasPrefix(line, "[COMMAND]:") { | ||
sbCurrent = &sbCommand | ||
continue | ||
} | ||
|
||
if strings.HasPrefix(line, "[EXPLANATION]:") { | ||
sbCurrent = &sbExplanation | ||
continue | ||
} | ||
|
||
if strings.HasPrefix(line, "[END]") { | ||
break | ||
} | ||
|
||
if sbCurrent == nil { | ||
continue | ||
} | ||
sbCurrent.WriteString(line) | ||
sbCurrent.WriteString("\n") | ||
if err := json.Unmarshal([]byte(response), &res); err != nil { | ||
return Response{}, err | ||
} | ||
|
||
return Response{ | ||
Command: strings.Trim(sbCommand.String(), "\n"), | ||
Explanation: strings.Trim(sbExplanation.String(), "\n"), | ||
}, nil | ||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters