Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: Error: 'list' object has no attribute 'get' when using the preview window conversation function of the chat API #1690

Closed
metasavvy opened this issue Jul 24, 2024 · 3 comments
Labels
question Further information is requested

Comments

@metasavvy
Copy link

metasavvy commented Jul 24, 2024

Describe your problem

api/apps/api_app.py

def rename_field(ans):
for chunk_i in ans['reference'].get('chunks', []):
chunk_i['doc_name'] = chunk_i['docnm_kwd']
chunk_i.pop('docnm_kwd')

Ans ['reference '] needs to be typed, otherwise an exception will be thrown (' list 'object has no attribute' get ')

image

@metasavvy metasavvy added the question Further information is requested label Jul 24, 2024
@KevinHuSh
Copy link
Collaborator

fixed.

@zzlTim
Copy link

zzlTim commented Aug 12, 2024

@metasavvy @KevinHuSh
metasavvy 所以怎么才能解决,我拉取最新代码还是不行。要重新拉镜像吗?我去看你们的历史版本,也没有说修复了#1690的bug呀
so how to solve this problem? i have pulled the newest ragflow codes but it still doesn't works. do you mean that you will fix it in the next version?

@beautifulboySoSo
Copy link

@zzlTim Try this one.
Router /completion of /api/apps/api_app.py:
If the 'stream' param is passed as True, add some lines to the rename_field funtion

def rename_field(ans):
          # print(ans['reference'], flush=True)
          if isinstance(ans['reference'], list):
              temp = ans['reference'][::1]
              ans['reference'] = {
                  'chunks': temp
              }
          for chunk_i in ans['reference'].get('chunks', []):
              chunk_i['doc_name'] = chunk_i['docnm_kwd']
              chunk_i.pop('docnm_kwd')

And if the 'stream' param is passed as False, add some lines to the other case as above

if req.get("stream", True):
          resp = Response(stream(), mimetype="text/event-stream")
          resp.headers.add_header("Cache-control", "no-cache")
          resp.headers.add_header("Connection", "keep-alive")
          resp.headers.add_header("X-Accel-Buffering", "no")
          resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8")
          return resp
      else:
          answer = None
          for ans in chat(dia, msg, **req):
              answer = ans
              fillin_conv(ans)
              API4ConversationService.append_message(conv.id, conv.to_dict())
              break
          if isinstance(answer['reference'], list):
              temp = answer['reference'][::1]
              answer['reference'] = {
                  'chunks': temp
              }
          for chunk_i in answer['reference'].get('chunks',[]):
              chunk_i['doc_name'] = chunk_i['docnm_kwd']
              chunk_i.pop('docnm_kwd')

          return get_json_result(data=answer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants