feat: attaching both to image
This commit is contained in:
@ -283,26 +283,21 @@ func NewLocationEventAgent(locationModel models.LocationModel, eventModel models
|
||||
return args, err
|
||||
},
|
||||
Fn: func(info ToolHandlerInfo, args CreateLocationArguments, call ToolCall) (model.Locations, error) {
|
||||
return agent.locationModel.Save(context.Background(), info.userId, model.Locations{
|
||||
ctx := context.Background()
|
||||
|
||||
location, err := agent.locationModel.Save(ctx, info.userId, model.Locations{
|
||||
Name: args.Name,
|
||||
Address: args.Address,
|
||||
Coordinates: args.Coordinates,
|
||||
})
|
||||
},
|
||||
|
||||
if err != nil {
|
||||
return location, err
|
||||
}
|
||||
|
||||
// I'm not sure this one actually makes sense either.
|
||||
// I think the earlier tool can do more.
|
||||
toolHandler.Handlers["attachImageLocation"] = ToolHandler[AttachImageLocationArguments, model.ImageLocations]{
|
||||
FunctionName: "attachImageLocation",
|
||||
Parse: func(stringArgs string) (AttachImageLocationArguments, error) {
|
||||
args := AttachImageLocationArguments{}
|
||||
err := json.Unmarshal([]byte(stringArgs), &args)
|
||||
_, err = agent.locationModel.SaveToImage(ctx, info.imageId, location.ID)
|
||||
|
||||
return args, err
|
||||
},
|
||||
Fn: func(info ToolHandlerInfo, args AttachImageLocationArguments, call ToolCall) (model.ImageLocations, error) {
|
||||
return agent.locationModel.SaveToImage(context.Background(), info.imageId, uuid.MustParse(args.LocationId))
|
||||
return location, err
|
||||
},
|
||||
}
|
||||
|
||||
@ -325,6 +320,11 @@ func NewLocationEventAgent(locationModel models.LocationModel, eventModel models
|
||||
return event, err
|
||||
}
|
||||
|
||||
_, err = agent.eventModel.SaveToImage(ctx, info.imageId, event.ID)
|
||||
if err != nil {
|
||||
return event, err
|
||||
}
|
||||
|
||||
locationId, err := uuid.Parse(args.LocationId)
|
||||
if err != nil {
|
||||
return event, err
|
||||
|
@ -38,20 +38,15 @@ func (m EventModel) Save(ctx context.Context, userId uuid.UUID, event model.Even
|
||||
return insertedEvent, err
|
||||
}
|
||||
|
||||
func (m EventModel) SaveToImage(ctx context.Context, userId uuid.UUID, imageId uuid.UUID, event model.Events) error {
|
||||
event, err := m.Save(ctx, userId, event)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func (m EventModel) SaveToImage(ctx context.Context, imageId uuid.UUID, eventId uuid.UUID) (model.ImageEvents, error) {
|
||||
insertImageEventStmt := ImageEvents.
|
||||
INSERT(ImageEvents.ImageID, ImageEvents.EventID).
|
||||
VALUES(imageId, event.ID)
|
||||
VALUES(imageId, eventId)
|
||||
|
||||
_, err = insertImageEventStmt.ExecContext(ctx, m.dbPool)
|
||||
imageEvent := model.ImageEvents{}
|
||||
err := insertImageEventStmt.QueryContext(ctx, m.dbPool, &imageEvent)
|
||||
|
||||
return err
|
||||
return imageEvent, err
|
||||
}
|
||||
|
||||
func (m EventModel) UpdateLocation(ctx context.Context, eventId uuid.UUID, locationId uuid.UUID) (model.Events, error) {
|
||||
|
Reference in New Issue
Block a user