From e883fbce2072760155e8cd870551cb701c4647b7 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 17 Apr 2024 18:31:29 +0800 Subject: [PATCH] bugfix --- ahserver/llm_client.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/ahserver/llm_client.py b/ahserver/llm_client.py index 1ff03d2..4b4f120 100644 --- a/ahserver/llm_client.py +++ b/ahserver/llm_client.py @@ -1,5 +1,6 @@ import re import json +from traceback import print_exc from aiohttp import web from appPublic.dictObject import DictObject from appPublic.httpclient import HttpClient, RESPONSE_TEXT, RESPONSE_JSON, RESPONSE_BIN,RESPONSE_FILE, RESPONSE_STREAM @@ -17,17 +18,34 @@ class LlmProxy: self.ac = ArgsConvert('${', '}') def line_chunk_match(self, l): - if self.chunk_match: - match = re.search(self.chunk_match, l) + if self.api.chunk_match: + match = re.search(self.api.chunk_match, l) if match: return match.group(1) return l - async def write_chunk(self, l): + async def write_chunk(self, ll): + def eq(a, b): + return a == b + def ne(a, b): + return a != b + opfuncs = { + '==':eq, + '!=':ne + } try: - print('write_chunk(),l=', l) - l = self.line_chunk_match(l) + print('write_chunk(),l=', ll) + l = self.line_chunk_match(ll) d = DictObject(** json.loads(l)) + if self.api.chunk_filter: + v = d.get_data_by_keys(self.api.chunk_filter.name) + v1 = self.api.chunk_filter.value + op = self.api.chunk_filter.op + f = opfuncs.get(op) + if f and f(v,v1): + print('filtered', v, op, v1, f) + return + j = {} for r in self.api.resp or []: j[r.name] = d.get_data_by_keys(r.value); @@ -37,7 +55,8 @@ class LlmProxy: await self.resp.write(bin) await self.resp.drain() except Exception as e: - print(f'Write_chunk("{l}") errpr:{e=}') + print(f'Error:Write_chunk(),{l=} error:{e=}') + print_exc() async def stream_handle(self, chunk): chunk = chunk.decode('utf-8')