forked from SciSharp/BotSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebSearchUserLocation.cs
More file actions
48 lines (42 loc) · 1.4 KB
/
WebSearchUserLocation.cs
File metadata and controls
48 lines (42 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
namespace BotSharp.Plugin.OpenAI.Models.Web;
/// <summary>
/// Approximate user location hint passed to the OpenAI web search tool.
/// Mirrors the shape of OpenAI's user_location payload (country, region, city, timezone).
/// </summary>
public class WebSearchUserLocation
{
private static readonly JsonSerializerOptions _jsonOptions = new()
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
AllowTrailingCommas = true,
ReadCommentHandling = JsonCommentHandling.Skip,
NumberHandling = JsonNumberHandling.AllowReadingFromString,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
public string? Country { get; set; }
public string? Region { get; set; }
public string? City { get; set; }
public string? Timezone { get; set; }
[JsonIgnore]
public bool HasAnyValue =>
!string.IsNullOrEmpty(Country)
|| !string.IsNullOrEmpty(Region)
|| !string.IsNullOrEmpty(City)
|| !string.IsNullOrEmpty(Timezone);
public static WebSearchUserLocation? FromJson(string? json)
{
if (string.IsNullOrWhiteSpace(json))
{
return null;
}
try
{
return JsonSerializer.Deserialize<WebSearchUserLocation>(json, _jsonOptions);
}
catch (JsonException)
{
return null;
}
}
}