feat: creating events and attaching locations
This commit is contained in:
@@ -23,9 +23,12 @@ It is possible that there is no location or event on an image.
|
||||
|
||||
You should ask for a list of locations, as the user is likely to have this location saved. Reuse existing locations where possible.
|
||||
|
||||
Always reuse existing locations from listLocations. Do not create duplicates.
|
||||
|
||||
Do not create an event if you don't see any dates, or a name indicating an event.
|
||||
|
||||
Always reuse existing locations from listLocations . Do not create duplicates.
|
||||
Events can have an associated location, if you think there is a location, then you must either use a location from listLocations or you must create it first.
|
||||
Wherever possible, find the location in the image.
|
||||
`
|
||||
|
||||
// TODO: this should be read directly from a file on load.
|
||||
@@ -64,23 +67,6 @@ const TOOLS = `
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "attachImageLocation",
|
||||
"description": "Add a location to an image. You must use UUID.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"locationId": {
|
||||
"type": "string",
|
||||
"description": "UUID of an existing location, you can use listLocations to get values, or use the return value of createLocation"
|
||||
}
|
||||
},
|
||||
"required": ["locationId"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
@@ -139,6 +125,12 @@ type AttachImageLocationArguments struct {
|
||||
LocationId string `json:"locationId"`
|
||||
}
|
||||
|
||||
type CreateEventArguments struct {
|
||||
Name string `json:"name"`
|
||||
Datetime string `json:"datetime"`
|
||||
LocationId string `json:"locationId"`
|
||||
}
|
||||
|
||||
func (agent EventLocationAgent) GetLocations(userId uuid.UUID, imageId uuid.UUID, imageName string, imageData []byte) error {
|
||||
var tools any
|
||||
err := json.Unmarshal([]byte(TOOLS), &tools)
|
||||
@@ -299,6 +291,8 @@ func NewLocationEventAgent(locationModel models.LocationModel, eventModel models
|
||||
},
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@@ -312,6 +306,34 @@ func NewLocationEventAgent(locationModel models.LocationModel, eventModel models
|
||||
},
|
||||
}
|
||||
|
||||
toolHandler.Handlers["createEvent"] = ToolHandler[CreateEventArguments, model.Events]{
|
||||
FunctionName: "createEvent",
|
||||
Parse: func(stringArgs string) (CreateEventArguments, error) {
|
||||
args := CreateEventArguments{}
|
||||
err := json.Unmarshal([]byte(stringArgs), &args)
|
||||
|
||||
return args, err
|
||||
},
|
||||
Fn: func(info ToolHandlerInfo, args CreateEventArguments, call ToolCall) (model.Events, error) {
|
||||
ctx := context.Background()
|
||||
|
||||
event, err := agent.eventModel.Save(ctx, info.userId, model.Events{
|
||||
Name: args.Name,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return event, err
|
||||
}
|
||||
|
||||
locationId, err := uuid.Parse(args.LocationId)
|
||||
if err != nil {
|
||||
return event, err
|
||||
}
|
||||
|
||||
return agent.eventModel.UpdateLocation(ctx, event.ID, locationId)
|
||||
},
|
||||
}
|
||||
|
||||
agent.toolHandler = toolHandler
|
||||
|
||||
return agent, nil
|
||||
|
||||
Reference in New Issue
Block a user