ragflow icon indicating copy to clipboard operation
ragflow copied to clipboard

[Question]: How to show quotes while using API (Openai API)

Open mcwongaagpt opened this issue 8 months ago • 5 comments

Self Checks

  • [x] I have searched for existing issues search for existing issues, including closed ones.
  • [x] I confirm that I am using English to submit this report (Language Policy).
  • [x] Non-english title submitions will be closed directly ( 非英文标题的提交将会被直接关闭 ) (Language Policy).
  • [x] Please do not modify this template :) and fill in all the required fields.

Describe your problem

Hi All Do anyone know how to show quotes like below while using API? I cannot find doc mention it

mcwongaagpt avatar Apr 23 '25 07:04 mcwongaagpt

To display quotes while using the OpenAI API, you can use the parser_txt method in the RAGFlowTxtParser class. This method utilizes regular expressions to identify and process text segments enclosed in quotes, such as backticks, and formats them accordingly [1].

If you're looking for specific configuration settings in the OpenAI API that might affect text formatting, you can adjust parameters like Temperature, Top P, Presence Penalty, Frequency Penalty, and Max Tokens to influence the model's output style and length [2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Apr 23 '25 07:04 dosubot[bot]

@dosu Thank you for your help You mentioned the method of parse the text When I look at the response from the API, I cannot find the info related to quotes that chatbot found in database , where should I look at it

mcwongaagpt avatar Apr 23 '25 07:04 mcwongaagpt

You can find information related to quotes identified by the chatbot in the database by checking the section of the code where self._param.symbols_datatype == "quotes". This section processes the API response for quotes and maps various fields such as 'Selling Price', 'Buying Price', 'Commodity Code', 'Stock Exchange', 'Highest Price', 'Yesterday’s Closing Price', 'Lowest Price', 'Opening Price', 'Latest Price', and 'Market Quote Time'. The processed data is then appended to jin10_res as a markdown table using pd.DataFrame(response['data']).to_markdown() [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Apr 23 '25 07:04 dosubot[bot]

@mcwongaagpt

在 ragflow\api\db\services\dialog_service.py 的chat 中 kbinfos

你需要在 ragflow\api\apps\sdk\session.py 中的 api /chats_openai/<chat_id>/chat/completions
yield 前添加 reference = ans.get("reference") response['reference'] = reference

Image

且 ragflow\api\db\services\dialog_service.py 中 chat 修改 stream=True 时的返回

if stream:
    refs_openai = deepcopy(kbinfos)
    if not refs_openai:
        refs_openai  = {}

    last_ans = ""
    answer = ""
    for ans in chat_mdl.chat_streamly(prompt + prompt4citation, msg[1:], gen_conf):
        if thought:
            ans = re.sub(r"<think>.*</think>", "", ans, flags=re.DOTALL)
        answer = ans
        delta_ans = ans[len(last_ans) :]
        if num_tokens_from_string(delta_ans) < 16:
            continue
        last_ans = answer
        yield {"answer": thought + answer, "reference": refs_openai.get('doc_aggs', []), "audio_binary": tts(tts_mdl, delta_ans)}
    delta_ans = answer[len(last_ans) :]
    if delta_ans:
        yield {"answer": thought + answer, "reference": refs_openai.get('doc_aggs', []) or [], "audio_binary": tts(tts_mdl, delta_ans)}
    yield decorate_answer(thought + answer)

Image

docker 中的文件需要修改你可以直接修改docker中的相应文件 也可以使用docker volumes文件, 重新构建 ragflow docker compose -f docker/docker-compose.yml up -d ragflow

Image

改完后, 长这样, 祝你好运 Image

rookie-python avatar Apr 29 '25 07:04 rookie-python

@mcwongaagpt

在 ragflow\api\db\services\dialog_service.py 的chat 中 kbinfos

你需要在 ragflow\api\apps\sdk\session.py 中的 api /chats_openai/<chat_id>/chat/completions yield 前添加 reference = ans.get("reference") response['reference'] = reference

Image

且 ragflow\api\db\services\dialog_service.py 中 chat 修改 stream=True 时的返回

if stream:
    refs_openai = deepcopy(kbinfos)
    if not refs_openai:
        refs_openai  = {}

    last_ans = ""
    answer = ""
    for ans in chat_mdl.chat_streamly(prompt + prompt4citation, msg[1:], gen_conf):
        if thought:
            ans = re.sub(r"<think>.*</think>", "", ans, flags=re.DOTALL)
        answer = ans
        delta_ans = ans[len(last_ans) :]
        if num_tokens_from_string(delta_ans) < 16:
            continue
        last_ans = answer
        yield {"answer": thought + answer, "reference": refs_openai.get('doc_aggs', []), "audio_binary": tts(tts_mdl, delta_ans)}
    delta_ans = answer[len(last_ans) :]
    if delta_ans:
        yield {"answer": thought + answer, "reference": refs_openai.get('doc_aggs', []) or [], "audio_binary": tts(tts_mdl, delta_ans)}
    yield decorate_answer(thought + answer)

Image

docker 中的文件需要修改你可以直接修改docker中的相应文件 也可以使用docker volumes文件, 重新构建 ragflow docker compose -f docker/docker-compose.yml up -d ragflow

Image

改完后, 长这样, 祝你好运 Image

Do you add manually add volumes to docker-compose.yml and then run compose -f docker/docker-compose.yml up -d ?

vanalexgr avatar Jun 16 '25 11:06 vanalexgr