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