parse stuff

This commit is contained in:
Jeff Carr 2025-08-30 18:07:41 -05:00
parent 512ebf5be6
commit fbbed0475b
3 changed files with 47 additions and 15 deletions

View File

@ -2,7 +2,7 @@ VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d_%H%M) BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
default: install 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: vet:
@GO111MODULE=off go vet @GO111MODULE=off go vet

17
json.go
View File

@ -45,10 +45,7 @@ type FunctionResponse struct {
Response map[string]interface{} `json:"response"` Response map[string]interface{} `json:"response"`
} }
// parseJSON opens the given file, reads it, and unmarshals it into our structs. func parsePB(filename string) (*chatpb.GeminiRequest, error) {
func parseJSON(filename string) (*GeminiRequest, error) {
log.Infof("Attempting to parse file: %s\n", filename)
// Read the entire file // Read the entire file
data, err := os.ReadFile(filename) data, err := os.ReadFile(filename)
if err != nil { if err != nil {
@ -58,6 +55,18 @@ func parseJSON(filename string) (*GeminiRequest, error) {
if err := pb.UnmarshalJSON(data); err != nil { if err := pb.UnmarshalJSON(data); err != nil {
return nil, err 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 // Unmarshal the JSON data
var req *GeminiRequest var req *GeminiRequest

43
main.go
View File

@ -8,6 +8,8 @@ package main
import ( import (
"embed" "embed"
"os" "os"
"path/filepath"
"strings"
"github.com/google/uuid" "github.com/google/uuid"
"go.wit.com/dev/alexflint/arg" "go.wit.com/dev/alexflint/arg"
@ -65,21 +67,42 @@ func main() {
_ = aiClient _ = aiClient
if argv.JsonFile != "" { 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 { if err != nil {
badExit(err) 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 if len(parts) == 5 {
genaiContent, err := convertToGenai(jstruct) uuid := parts[1]
if err != nil { log.Info(uuid, parts)
badExit(err) // 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("") okExit("")
} }