I hope you can choose the QA of the file itself for uploading #5115

Closed
opened 2026-02-21 18:09:27 -05:00 by yindo · 1 comment
Owner

Originally created by @401557122 on GitHub (Aug 19, 2024).

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

In order to avoid using a large model to generate QA pairs, which is too slow, I modified the following code and standardized the file header. However, I did not use LLMS during QA preview. Why did I still use a large model to generate QA during encoding and the final result
def generate_qa_document(cls, tenant_id: str, query, document_language: str):
prompt = GENERATOR_QA_PROMPT.format(language=document_language)
#首先使用正则表达式提取原始问答
import re
match = re.search(r'questions:\s*(.?)\s;\sanswers:\s(.*)', query, re.DOTALL)
if match:
one_question = match.group(1).strip()
one_answer = match.group(2).strip()
answer = 'Q1:'+one_question+'\n'+'A1:'+one_answer
else:
model_manager = ModelManager()
model_instance = model_manager.get_default_model_instance(
tenant_id=tenant_id,
model_type=ModelType.LLM,
)

        prompt_messages = [
            SystemPromptMessage(content=prompt),
            UserPromptMessage(content=query)
        ]

        response = model_instance.invoke_llm(
            prompt_messages=prompt_messages,
            model_parameters={
                'temperature': 0.01,
                "max_tokens": 2000
            },
            stream=False
        )

        answer = response.message.content
    return answer.strip()

2. Additional context or comments

No response

3. Can you help us with this feature?

  • I am interested in contributing to this feature.
Originally created by @401557122 on GitHub (Aug 19, 2024). ### Self Checks - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### 1. Is this request related to a challenge you're experiencing? Tell me about your story. In order to avoid using a large model to generate QA pairs, which is too slow, I modified the following code and standardized the file header. However, I did not use LLMS during QA preview. Why did I still use a large model to generate QA during encoding and the final result def generate_qa_document(cls, tenant_id: str, query, document_language: str): prompt = GENERATOR_QA_PROMPT.format(language=document_language) #首先使用正则表达式提取原始问答 import re match = re.search(r'questions:\s*(.*?)\s*;\s*answers:\s*(.*)', query, re.DOTALL) if match: one_question = match.group(1).strip() one_answer = match.group(2).strip() answer = 'Q1:'+one_question+'\n'+'A1:'+one_answer else: model_manager = ModelManager() model_instance = model_manager.get_default_model_instance( tenant_id=tenant_id, model_type=ModelType.LLM, ) prompt_messages = [ SystemPromptMessage(content=prompt), UserPromptMessage(content=query) ] response = model_instance.invoke_llm( prompt_messages=prompt_messages, model_parameters={ 'temperature': 0.01, "max_tokens": 2000 }, stream=False ) answer = response.message.content return answer.strip() ### 2. Additional context or comments _No response_ ### 3. Can you help us with this feature? - [ ] I am interested in contributing to this feature.
yindo added the 🙋‍♂️ question label 2026-02-21 18:09:27 -05:00
yindo closed this issue 2026-02-21 18:09:27 -05:00
Author
Owner

@crazywoola commented on GitHub (Aug 21, 2024):

Duplicated https://github.com/langgenius/dify/issues/6904

@crazywoola commented on GitHub (Aug 21, 2024): Duplicated https://github.com/langgenius/dify/issues/6904
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5115