Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
luyaxi committed Oct 17, 2024
1 parent 85648aa commit 0bf5a7b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
22 changes: 3 additions & 19 deletions codelinker/events/processer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def unlisten(self, func: callable):
def wait(self, tags: ChannelTag | Iterable[ChannelTag]):
return self.sink.wait(tags)

def get(self,tag: ChannelTag, return_dumper: Callable|Literal['str','json','identity'] = 'str'):
def get(self,tag: ChannelTag) -> SEvent:
"""Get last event in the channel."""
def tag_filter(event: SEvent):
if tag is None:
Expand All @@ -43,26 +43,10 @@ def tag_filter(event: SEvent):
if tag in event.tags:
return True
return False


gathered_events = list(filter(tag_filter, self.sink.all_events))
if isinstance(return_dumper,str):
match return_dumper:
case 'str':
return_dumper = str
case 'json':
import json
return_dumper = partial(json.dumps, ensure_ascii=False,sort_keys=False)
case 'identity':
return_dumper = lambda x: x

assert callable(return_dumper), "return_dumper must be a callable'"

gathered_events = list(filter(tag_filter, self.sink.all_events))
event = gathered_events[-1]
if event.source == self.name:
return {'role': 'assistant', 'content': event.content}
else:
return {'role': 'user', 'content': return_dumper(event)}
return event


def gather(self, tags: ChannelTag | Iterable[ChannelTag] | None = None, return_dumper: Callable|Literal['str','json','identity'] = 'str') -> Iterable[dict]:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "codelinker"
version = "0.3.24"
version = "0.3.25"
description = "A tool to link the code with large language models."
authors = ["luyaxi <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 0bf5a7b

Please sign in to comment.