mirror of
https://github.com/nolen777/eagle0.git
synced 2026-07-29 00:15:42 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8d7e03afe |
@@ -26,14 +26,17 @@ namespace eagle {
|
||||
|
||||
private readonly HashSet<IClientTextListener> _listeners = new();
|
||||
|
||||
public void Clear() { _streamingTexts.Clear(); }
|
||||
public void Clear() {
|
||||
lock (this) { _streamingTexts.Clear(); }
|
||||
}
|
||||
|
||||
public Dictionary<String, TextEntry> All() {
|
||||
return new Dictionary<string, TextEntry>(_streamingTexts);
|
||||
lock (this) { return new Dictionary<string, TextEntry>(_streamingTexts); }
|
||||
}
|
||||
|
||||
public String
|
||||
HandleNewStreamingText(String llmId, String newText, Int32 knownByteCount, bool completed) {
|
||||
lock (this) {
|
||||
var currentText = "";
|
||||
if (_streamingTexts.TryGetValue(llmId, out var entry)) { currentText = entry.Text; }
|
||||
|
||||
@@ -49,8 +52,10 @@ namespace eagle {
|
||||
|
||||
return updatedText;
|
||||
}
|
||||
}
|
||||
|
||||
public TextEntry GetTextEntry(string streamId) {
|
||||
lock (this) {
|
||||
if (String.IsNullOrEmpty(streamId)) return new TextEntry("", false);
|
||||
|
||||
if (ClientPregeneratedText.Provider.TryGetText(streamId, out var text)) {
|
||||
@@ -59,15 +64,20 @@ namespace eagle {
|
||||
|
||||
return _streamingTexts.GetValueOrDefault(streamId, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddListener(IClientTextListener listener) {
|
||||
lock (this) {
|
||||
if (listener.TextId() is {} textId && !String.IsNullOrEmpty(textId)) {
|
||||
_listeners.Add(listener);
|
||||
var entry = GetTextEntry(textId);
|
||||
if (entry != null) { listener.OnTextUpdate(entry.Text, entry.Completed); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveListener(IClientTextListener listener) { _listeners.Remove(listener); }
|
||||
public void RemoveListener(IClientTextListener listener) {
|
||||
lock (this) { _listeners.Remove(listener); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user