parse stuff
This commit is contained in:
parent
512ebf5be6
commit
fbbed0475b
2
Makefile
2
Makefile
|
@ -2,7 +2,7 @@ VERSION = $(shell git describe --tags)
|
|||
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
||||
|
||||
default: install
|
||||
regex --json tmp/regex.55128216-e93b-4339-8854-622ca11af890.gemini-api-request.128.json
|
||||
regex --json tmp/regex.07812e1a-a60c-4e2f-8180-fbbf3fa6a9e7.gemini-api-request.19.json
|
||||
|
||||
vet:
|
||||
@GO111MODULE=off go vet
|
||||
|
|
17
json.go
17
json.go
|
@ -45,10 +45,7 @@ type FunctionResponse struct {
|
|||
Response map[string]interface{} `json:"response"`
|
||||
}
|
||||
|
||||
// parseJSON opens the given file, reads it, and unmarshals it into our structs.
|
||||
func parseJSON(filename string) (*GeminiRequest, error) {
|
||||
log.Infof("Attempting to parse file: %s\n", filename)
|
||||
|
||||
func parsePB(filename string) (*chatpb.GeminiRequest, error) {
|
||||
// Read the entire file
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
|
@ -58,6 +55,18 @@ func parseJSON(filename string) (*GeminiRequest, error) {
|
|||
if err := pb.UnmarshalJSON(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return pb, nil
|
||||
}
|
||||
|
||||
// parseJSON opens the given file, reads it, and unmarshals it into our structs.
|
||||
func parseJSON(filename string) (*GeminiRequest, error) {
|
||||
log.Infof("Attempting to parse file: %s\n", filename)
|
||||
|
||||
// Read the entire file
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, log.Errorf("failed to read file %s: %w", filename, err)
|
||||
}
|
||||
|
||||
// Unmarshal the JSON data
|
||||
var req *GeminiRequest
|
||||
|
|
43
main.go
43
main.go
|
@ -8,6 +8,8 @@ package main
|
|||
import (
|
||||
"embed"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"go.wit.com/dev/alexflint/arg"
|
||||
|
@ -65,21 +67,42 @@ func main() {
|
|||
_ = aiClient
|
||||
|
||||
if argv.JsonFile != "" {
|
||||
jstruct, err := parseJSON(argv.JsonFile)
|
||||
/*
|
||||
jstruct, err := parseJSON(argv.JsonFile)
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
log.Info("parseJSON() ok. model =", jstruct.Model)
|
||||
|
||||
// Marshal this JSON file into a protobuf
|
||||
genaiContent, err := convertToGenai(jstruct)
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
log.Info("Successfully converted JSON to genai.Content")
|
||||
// Here you would now use the 'genaiContent' to send to the API
|
||||
_ = genaiContent // Prevent unused variable error for now
|
||||
*/
|
||||
|
||||
// now try to Marshal() into a protobuf
|
||||
pb, err := parsePB(argv.JsonFile)
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
log.Info("parseJSON() ok. model =", jstruct.Model)
|
||||
log.Info("GeminiContent pb.Marshal() worked len =", len(pb.Contents))
|
||||
_, filename := filepath.Split(argv.JsonFile)
|
||||
parts := strings.Split(filename, ".")
|
||||
|
||||
// Marshal this JSON file into a protobuf
|
||||
genaiContent, err := convertToGenai(jstruct)
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
if len(parts) == 5 {
|
||||
uuid := parts[1]
|
||||
log.Info(uuid, parts)
|
||||
// newEntry := new(chatpb.ChatEntry)
|
||||
// newEntry.GeminiRequest = pb
|
||||
if chat := me.chats.FindByUuid(uuid); chat != nil {
|
||||
log.Info("FOUND CHAT", uuid)
|
||||
}
|
||||
} else {
|
||||
}
|
||||
log.Info("Successfully converted JSON to genai.Content")
|
||||
// Here you would now use the 'genaiContent' to send to the API
|
||||
_ = genaiContent // Prevent unused variable error for now
|
||||
|
||||
okExit("")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue