Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit 8c00244

Browse files
.
1 parent daf699e commit 8c00244

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

sdk/go/examples/textgeneration/toolcalling.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ func GenerateTextWithTools(prompt string) (string, error) {
130130

131131
// This function will return the current time in a given time zone.
132132
func getCurrentTime(tz string) (string, error) {
133+
if !localtime.IsValidTimeZone(tz) {
134+
return "", errors.New("Invalid time zone.")
135+
}
136+
133137
now, err := localtime.NowInZone(tz)
134138
if err != nil {
135139
return "", err

sdk/go/pkg/localtime/localtime.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,9 @@ func GetLocation(tz string) (*time.Location, error) {
6161
}
6262
return hostGetTimeLocation(tz)
6363
}
64+
65+
// IsValidTimeZone returns true if the given time zone is valid.
66+
func IsValidTimeZone(tz string) bool {
67+
_, err := hostGetTimeInZone(tz)
68+
return err == nil
69+
}

0 commit comments

Comments
 (0)