main
py 18 lines 623 Bytes
Raw
1 from helpers.api import ApiHandler, Input, Output, Request, Response
2
3 from helpers import tokens
4
5
6 class GetCtxWindow(ApiHandler):
7 async def process(self, input: Input, request: Request) -> Output:
8 ctxid = input.get("context", [])
9 context = self.use_context(ctxid)
10 agent = context.streaming_agent or context.agent0
11 window = agent.get_data(agent.DATA_NAME_CTX_WINDOW)
12 if not window or not isinstance(window, dict):
13 return {"content": "", "tokens": 0}
14
15 text = window["text"]
16 tokens = window["tokens"]
17
18 return {"content": text, "tokens": tokens}