TODAM-tw / todam-ticket-system

The frontend with gradio and combined with the API endpoints for the ticket system.
Apache License 2.0
0 stars 0 forks source link

[Enhancement] Bedrock Lambda Function Output #17

Open 1chooo opened 1 month ago

1chooo commented 1 month ago

現有的 Bedrock Output 格式包裝的層數過多,可參考下方使用,需要進很多層才能拿到跟之前一樣的 output,但是又多了 ``json, \```,才能找到subject,transcript,caseId` 等資訊,因此需要簡化目前的 output 結構

https://github.com/TODAM-tw/todam-ticket-system/blob/04f5d9c6f5fcb8c955a51122c4cf8fb91879ff6c/toy_example/bedrock_model.py#L65-L84

1chooo commented 1 month ago

現有 Model 可能回傳的資訊還是會出現 Error,需要調查是否還有沒 Handle 到的 output

Traceback (most recent call last):
  File "/Users/hugolin/Developer/todam-ticket-system/venv/lib/python3.11/site-packages/gradio/queueing.py", line 527, in process_events
    response = await route_utils.call_process_api(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hugolin/Developer/todam-ticket-system/venv/lib/python3.11/site-packages/gradio/route_utils.py", line 270, in call_process_api
    output = await app.get_blocks().process_api(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hugolin/Developer/todam-ticket-system/venv/lib/python3.11/site-packages/gradio/blocks.py", line 1887, in process_api
    result = await self.call_function(
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hugolin/Developer/todam-ticket-system/venv/lib/python3.11/site-packages/gradio/blocks.py", line 1472, in call_function
    prediction = await anyio.to_thread.run_sync(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hugolin/Developer/todam-ticket-system/venv/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hugolin/Developer/todam-ticket-system/venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2144, in run_sync_in_worker_thread
    return await future
           ^^^^^^^^^^^^
  File "/Users/hugolin/Developer/todam-ticket-system/venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 851, in run
    result = context.run(func, *args)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hugolin/Developer/todam-ticket-system/venv/lib/python3.11/site-packages/gradio/utils.py", line 808, in wrapper
    response = f(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^
  File "/Users/hugolin/Developer/todam-ticket-system/app/cases/ticket_summarized.py", line 76, in get_summarized_ticket_content
    content_text = extract_content_text(body)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hugolin/Developer/todam-ticket-system/app/utils/summarized.py", line 129, in extract_content_text
    content_text: dict = json.loads(content["text"])
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

related: #28, #40