diff --git a/models/uapi.xlsx b/models/uapi.xlsx index 8ec69c0..1e775a5 100644 Binary files a/models/uapi.xlsx and b/models/uapi.xlsx differ diff --git a/test/.t.py.swp b/test/.t.py.swp index 8ca3b4a..7bc7f23 100644 Binary files a/test/.t.py.swp and b/test/.t.py.swp differ diff --git a/test/t.py b/test/t.py index 14c6730..d7a1670 100644 --- a/test/t.py +++ b/test/t.py @@ -18,10 +18,13 @@ async def main(): uapi = UAPI() params = { 'baseurl':'https://qianfan.baidubce.com', - 'model':'ernie-3.5-8k', - 'prompt':'who are you', + 'model':'deepseek-v3', + 'prompt':'北京今天天气如何,适合跑步吗?', } - async for line in uapi('MRXYc49LwTjyTLuOVk89R', '0', params=params): + upapiid = 'R47xUJay76dCCt1sLmWvE' # 百度智能搜索 + # MRXYc49LwTjyTLuOVk89R 百度文生文 + + async for line in uapi(upapiid, '0', params=params): print(line) if __name__ == '__main__': diff --git a/uapi/appapi.py b/uapi/appapi.py index ab6df9b..c8025ed 100644 --- a/uapi/appapi.py +++ b/uapi/appapi.py @@ -98,14 +98,15 @@ class UAPI: method = api.httpmethod headers = await self.rendertmpl(api.headers) headers = json.loads(headers) - body = await self.rendertmpl(api.body) + body = await self.rendertmpl(api.data) if body: bdy = json.loads(body) bdy['stream'] = True - body = bdy.dumps(bdy, ensure_ascii=False) + body = json.dumps(bdy, ensure_ascii=False) _params = await self.rendertmpl(api.params) if _params: _params = json.loads(_params) + debug(f'{headers=}, {body=}. {method=}, {url=}') shc = StreamHttpClient() gen = shc(method, url, headers=headers, @@ -114,11 +115,17 @@ class UAPI: chunk_match = api.chunk_match or '' cmlen = len(chunk_match) async for line in liner(gen): + line = line.decode('utf-8') if line.startswith(chunk_match): - cvt_line = self.streamline_handle(line[cmlen:], + line = line[cmlen:] + cvt_line = await self.streamline_handle(line, api.streamresponse) if cvt_line is not None: yield cvt_line + else: + debug(f'{line=} after convert is None') + else: + debug(f'{chunk_match=},{line=} not matched') async def streamline_handle(self, line, resptmpl): try: @@ -127,7 +134,7 @@ class UAPI: jstr = await self.rendertmpl(resptmpl, params=dic) jstr += '\n' else: - jstr = json.dumps(self.resp_json, ensure_ascii=False) + '\n' + jstr = json.dumps(dic, ensure_ascii=False) + '\n' return jstr except Exception as e: exception(f'{line=}\n{e=},{format_exc()}') @@ -175,8 +182,8 @@ where a.id = b.upappid raise e r = recs[0] return DictObject(**{ - 'apikey':r.apikey, - 'secretkey':r.secretkey, + 'apikey':password_decode(r.apikey), + 'secretkey':password_decode(r.secretkey), 'apisetid': r.apisetid, 'auth_apiid': r.auth_apiid, 'myappid': r.myappid