Add .gitignore files and clean up tracked files

This commit is contained in:
Russell Ballestrini 2025-09-17 08:36:31 -04:00
parent bde434356c
commit d9a0d9da88
4 changed files with 100 additions and 21 deletions

70
.gitignore vendored Normal file
View file

@ -0,0 +1,70 @@
# C# / .NET
## Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
## Visual Studio
.vs/
*.suo
*.user
*.userosscache
*.sln.docstates
*.userprefs
## Mono auto generated files
mono_crash.*
## .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
## NuGet
*.nupkg
*.snupkg
**/[Pp]ackages/*
!**/[Pp]ackages/build/
*.nuget.props
*.nuget.targets
## Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
## JetBrains Rider
.idea/
*.sln.iml
## macOS
.DS_Store
.AppleDouble
.LSOverride
## Windows
Thumbs.db
ehthumbs.db
Desktop.ini
## Build results
*.dll
*.exe
*.pdb
*.cache
*.ilk
*.log
*.vspscc
*.vssscc

View file

@ -313,7 +313,8 @@ public class Client : IDisposable {
_refreshToken =
responseData?.GetValueOrDefault("refresh_token")?.ToString() ?? "";
var expiresIn = 3600;
if (responseData?.TryGetValue("expires_in", out var expiresInObj) == true) {
if (responseData?.TryGetValue("expires_in", out var expiresInObj) ==
true) {
if (expiresInObj is JsonElement jsonEl) {
expiresIn = jsonEl.GetInt32();
} else {
@ -387,7 +388,8 @@ public class Client : IDisposable {
}
var expiresIn = 3600;
if (responseData?.TryGetValue("expires_in", out var expiresInObj) == true) {
if (responseData?.TryGetValue("expires_in", out var expiresInObj) ==
true) {
if (expiresInObj is JsonElement jsonEl) {
expiresIn = jsonEl.GetInt32();
} else {

View file

@ -129,7 +129,9 @@ public class UniverseManager {
response.TryGetValue("public_universes", out var universesObj)) {
// Handle System.Text.Json
if (universesObj is System.Text.Json.JsonElement jsonElement) {
return System.Text.Json.JsonSerializer.Deserialize<List<Dictionary<string, object>>>(jsonElement.GetRawText());
return System.Text.Json.JsonSerializer
.Deserialize<List<Dictionary<string, object>>>(
jsonElement.GetRawText());
} else if (universesObj is List<Dictionary<string, object>> list) {
return list;
}
@ -151,7 +153,9 @@ public class UniverseManager {
response.TryGetValue("universes", out var universesObj)) {
// Handle System.Text.Json
if (universesObj is System.Text.Json.JsonElement jsonElement) {
return System.Text.Json.JsonSerializer.Deserialize<List<Dictionary<string, object>>>(jsonElement.GetRawText());
return System.Text.Json.JsonSerializer
.Deserialize<List<Dictionary<string, object>>>(
jsonElement.GetRawText());
} else if (universesObj is List<Dictionary<string, object>> list) {
return list;
}
@ -228,10 +232,9 @@ public class ChatManager {
var context = completionResponse.NpcContext;
var moodTransition = completionResponse.MoodTransition;
_client.RaiseDialogueReceived(
new DialogueReceivedEventArgs { Response = content,
Context = context,
MoodTransition = moodTransition });
_client.RaiseDialogueReceived(new DialogueReceivedEventArgs {
Response = content, Context = context, MoodTransition = moodTransition
});
}
return completionResponse;
@ -303,19 +306,23 @@ public class ChatCompletionResponse {
public ChatCompletionResponse(Dictionary<string, object> data) {
Choices = new List<ChatChoice>();
if (data?.ContainsKey("choices") == true) {
var choicesObj = data["choices"];
if (choicesObj is JsonElement choicesJson) {
// Handle JsonElement array
foreach (var choiceElement in choicesJson.EnumerateArray()) {
var choiceDict = JsonSerializer.Deserialize<Dictionary<string, object>>(choiceElement.GetRawText());
var choiceDict =
JsonSerializer.Deserialize<Dictionary<string, object>>(
choiceElement.GetRawText());
Choices.Add(new ChatChoice(choiceDict));
}
} else if (choicesObj is List<object> choicesList) {
Choices = choicesList
?.Select(c => new ChatChoice(c as Dictionary<string, object>))
.ToList() ?? new List<ChatChoice>();
Choices =
choicesList
?.Select(c => new ChatChoice(c as Dictionary<string, object>))
.ToList() ??
new List<ChatChoice>();
}
}
@ -339,7 +346,8 @@ public class ChatChoice {
if (data?.ContainsKey("message") == true) {
var msgObj = data["message"];
if (msgObj is JsonElement msgJson) {
var msgDict = JsonSerializer.Deserialize<Dictionary<string, object>>(msgJson.GetRawText());
var msgDict = JsonSerializer.Deserialize<Dictionary<string, object>>(
msgJson.GetRawText());
Message = new ChatMessage {
Role = msgDict?.GetValueOrDefault("role")?.ToString() ?? "assistant",
Content = msgDict?.GetValueOrDefault("content")?.ToString() ?? ""

13
NPC.cs
View file

@ -67,10 +67,11 @@ public class NPC {
/// </summary>
private void SetupFromData(Dictionary<string, object> npcData) {
// Check if data is nested in "spawned_npc" first
if (npcData.ContainsKey("spawned_npc") && npcData["spawned_npc"] is Dictionary<string, object> spawnedData) {
if (npcData.ContainsKey("spawned_npc") &&
npcData["spawned_npc"] is Dictionary<string, object> spawnedData) {
npcData = spawnedData;
}
// Handle npc_id conversion - API might return String or int
if (npcData.TryGetValue("npc_id", out var npcIdRaw)) {
if (npcIdRaw is JsonElement npcIdJson) {
@ -283,11 +284,9 @@ public class NPC {
/// Convert NPC to dictionary for API params
/// </summary>
public Dictionary<string, object> ToDictionary() {
return new Dictionary<string, object> {
["npc_id"] = NpcId,
["universe_id"] = UniverseId,
["seed"] = Seed
};
return new Dictionary<string, object> { ["npc_id"] = NpcId,
["universe_id"] = UniverseId,
["seed"] = Seed };
}
/// <summary>