-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
797a95d
commit 8145eca
Showing
7 changed files
with
170 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from weakref import WeakValueDictionary | ||
import re | ||
|
||
blob_store = WeakValueDictionary() | ||
|
||
class Blob: | ||
""" | ||
Represents multi-modal data as part of an LMQL prompt. | ||
""" | ||
def __init__(self, data): | ||
self.data = data | ||
self.id = str(hash(data)) | ||
|
||
blob_store[self.id] = self | ||
|
||
@staticmethod | ||
def resolve(id): | ||
return blob_store.get(id) | ||
|
||
def __str__(self): | ||
return f"<Blob {[str(self.data)]}>" | ||
|
||
def __repr__(self): | ||
return str(self) | ||
|
||
@staticmethod | ||
def decode(text): | ||
print("decode", [text]) | ||
pattern = r"<lmql:media([^>]*)\>" | ||
# split text by pattern matches, and replace each match with the resolved blob | ||
parts = re.split(pattern, text) | ||
for i in range(1, len(parts), 2): | ||
id = parts[i].split("id='")[1].split("'")[0] | ||
print([id]) | ||
parts[i] = Blob.resolve(id) | ||
return text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters