Skip to content

Commit 9a4cce0

Browse files
committed
Fix POI storage.
Signed-off-by: Katharine Berry <[email protected]>
1 parent 9681818 commit 9a4cce0

File tree

6 files changed

+37
-43
lines changed

6 files changed

+37
-43
lines changed

service/assistant/feedback/feedback.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type ReportedThread struct {
4444
ReportTime time.Time `json:"report_time"`
4545
ReportText string `json:"report_text"`
4646
ThreadContent []persistence.SerializedMessage `json:"thread_content"`
47-
ContextStorage map[string]any `json:"thread_context"`
47+
ContextStorage persistence.StoredContext `json:"thread_context"`
4848
}
4949

5050
func HandleFeedback(rw http.ResponseWriter, r *http.Request) {
@@ -86,7 +86,7 @@ func HandleReport(rw http.ResponseWriter, r *http.Request) {
8686
}
8787
}
8888
var messages []persistence.SerializedMessage
89-
var contextStorage map[string]any
89+
var contextStorage persistence.StoredContext
9090
if threadContext != nil {
9191
messages = threadContext.Messages
9292
contextStorage = threadContext.ContextStorage

service/assistant/feedback/report.html

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,14 @@ <h1>Reported thread</h1>
5151
{{if .ContextStorage}}
5252
<div class="context-storage">
5353
<h2>Context Storage</h2>
54-
<table>
55-
<tr>
56-
<th>Key</th>
57-
<th>Value</th>
58-
</tr>
59-
{{range $key, $value := .ContextStorage}}
60-
<tr>
61-
<td><code>{{$key}}</code></td>
62-
<td><pre class="arg-context-storage-{{$key}}">{{$value}}</pre></td>
63-
</tr>
54+
{{if .ContextStorage.POIs}}
55+
<h3>POIs</h3>
56+
<ol>
57+
{{range .ContextStorage.POIs}}
58+
<li><code>{{.}}</code></li>
6459
{{end}}
65-
</table>
60+
</ol>
61+
{{end}}
6662
</div>
6763
{{end}}
6864
<div class="thread">

service/assistant/functions/poi.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,8 @@ type POIQuery struct {
3636
Units string
3737
}
3838

39-
type POI struct {
40-
Name string
41-
Address string
42-
Categories []string
43-
OpeningHours []string
44-
CurrentlyOpen bool
45-
PhoneNumber string
46-
PriceLevel string
47-
StarRating float64
48-
RatingCount int64
49-
DistanceKilometers float64 `json:"DistanceKilometers,omitempty"`
50-
DistanceMiles float64 `json:"DistanceMiles,omitempty"`
51-
Coordinates util.Coords `json:"Coordinates,omitempty"`
52-
}
53-
5439
type POIResponse struct {
55-
Results []POI
40+
Results []util.POI
5641
Warning string `json:"CriticalRequirement,omitempty"`
5742
}
5843

@@ -161,7 +146,7 @@ func searchPoi(ctx context.Context, quotaTracker *quota.Tracker, args any) any {
161146

162147
log.Printf("Found %d POIs", len(results.Places))
163148

164-
var pois []POI
149+
var pois []util.POI
165150
var attributions map[string]any
166151
for _, place := range results.Places {
167152
var distMiles, distKm float64
@@ -171,7 +156,7 @@ func searchPoi(ctx context.Context, quotaTracker *quota.Tracker, args any) any {
171156
haversine.Coord{userLocation.Lat, userLocation.Lon},
172157
haversine.Coord{place.Location.Latitude, place.Location.Longitude})
173158
}
174-
poi := POI{
159+
poi := util.POI{
175160
Name: place.DisplayName.Text,
176161
Address: place.ShortFormattedAddress,
177162
Categories: place.Types,
@@ -199,7 +184,7 @@ func searchPoi(ctx context.Context, quotaTracker *quota.Tracker, args any) any {
199184
}
200185

201186
threadContext := query.ThreadContextFromContext(ctx)
202-
threadContext.ContextStorage["poi_results"] = pois
187+
threadContext.ContextStorage.POIs = pois
203188

204189
var attributionList []string
205190
for provider := range attributions {

service/assistant/persistence/persistence.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"encoding/json"
2020
"github.com/google/uuid"
2121
"github.com/honeycombio/beeline-go"
22+
"github.com/pebble-dev/bobby-assistant/service/assistant/util"
2223
"github.com/redis/go-redis/v9"
2324
"google.golang.org/genai"
2425
"time"
@@ -31,16 +32,18 @@ type SerializedMessage struct {
3132
FunctionResponse *genai.FunctionResponse `json:"functionResponse,omitempty"`
3233
}
3334

35+
type StoredContext struct {
36+
POIs []util.POI `json:"pois"`
37+
}
38+
3439
type ThreadContext struct {
3540
ThreadId uuid.UUID `json:"threadId"`
3641
Messages []SerializedMessage `json:"messages"`
37-
ContextStorage map[string]any `json:"contextStorage"`
42+
ContextStorage StoredContext `json:"contextStorage"`
3843
}
3944

4045
func NewContext() *ThreadContext {
41-
return &ThreadContext{
42-
ContextStorage: map[string]any{},
43-
}
46+
return &ThreadContext{}
4447
}
4548

4649
func LoadThread(ctx context.Context, r *redis.Client, id string) (*ThreadContext, error) {

service/assistant/util/poi.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package util
2+
3+
type POI struct {
4+
Name string
5+
Address string
6+
Categories []string
7+
OpeningHours []string
8+
CurrentlyOpen bool
9+
PhoneNumber string
10+
PriceLevel string
11+
StarRating float64
12+
RatingCount int64
13+
DistanceKilometers float64 `json:"DistanceKilometers,omitempty"`
14+
DistanceMiles float64 `json:"DistanceMiles,omitempty"`
15+
Coordinates Coords `json:"Coordinates,omitempty"`
16+
}

service/assistant/widgets/map.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"context"
66
_ "embed"
77
"encoding/base64"
8-
"fmt"
9-
"github.com/pebble-dev/bobby-assistant/service/assistant/functions"
108
"github.com/pebble-dev/bobby-assistant/service/assistant/query"
119
"github.com/pebble-dev/bobby-assistant/service/assistant/util"
1210
"github.com/pebble-dev/bobby-assistant/service/assistant/util/pbi"
@@ -49,11 +47,7 @@ func mapWidget(ctx context.Context, markerString, includeLocationString string)
4947
includeLocation := strings.EqualFold(includeLocationString, "true")
5048
markers := make(map[string]util.Coords)
5149
threadContext := query.ThreadContextFromContext(ctx)
52-
poiInfoAny, ok := threadContext.ContextStorage["poi_results"]
53-
if !ok {
54-
return nil, fmt.Errorf("no POI results found in context storage")
55-
}
56-
poiInfo := poiInfoAny.([]functions.POI)
50+
poiInfo := threadContext.ContextStorage.POIs
5751
markerString = strings.ReplaceAll(markerString, "\"", "")
5852
for _, marker := range strings.Split(markerString, ",") {
5953
parts := strings.Split(marker, ":")

0 commit comments

Comments
 (0)