Introduction
Control Yourself. Achieving success is not difficult for a person. In my youth, I read a book called “Karl Maintains Education,” which tells the story of a father raising a child with cerebral palsy to become a PhD. I believe the essence of the book is about controlling oneself and developing good habits. It mentions that if one can persist in something long enough until it becomes as natural as eating and sleeping, then that thing will surely be done well. Take programming as an example: if today I write 10,000 lines of code and then do not touch it for three years, I will naturally not learn it well. But if I write 1,000 lines a day and persist for three years, that amounts to 1.1 million lines of code. This shows that controlling oneself and persisting over the years can yield astonishing results. Sometimes I find it hard to control myself; when I feel anxious, I can spend three to four hours on my phone, which certainly does not indicate strong self-control. Therefore, I must strive to make programming as natural as eating and sleeping; otherwise, it will be hard not to succeed. Keep it up!
[277]——–>There is a life photo at the bottom
[Keywords] python, mini program, basic inquiry, streaming processing
1. Mini Program Related (Level 1)
1. Basic Inquiry Data Return (Level 2)
Description: The data return processing for the mini program is completed and awaiting testing. The corresponding chat records on the ragflow side have not been saved and need to be processed.
Start:
Step 1: Save Chat Records (Level 3)
20250212 Wednesday Time Period: 10:37-11:00
a. Test Sending (Level 4)
20250212 Wednesday Time Period: 10:51-11:00
Modify the initial sending program as follows:
Figure 7a-1
Note: This ensures that the initial send and reply are sent together and guarantees that it is sent only once. The test results are acceptable, as shown in the screenshot below:
Figure 7a-2
Note: Next, save the sent data in ragflow.
b. Save Sent Data (Level 4)
It is necessary to save both the sent data and the questions. Modify the program as follows:
Figure 7a-3
Note: This is for saving data; run it to see the effect. The effect is as follows:
Figure 7a-4
Note: The online test is acceptable; next, ask the mini program a complex question and go through the entire process.
Step 2: Complex Questions (Level 3)
20250212 Wednesday Time Period: 12:01-12:30
Ask a complex question and go through the entire process; the following issues were encountered:
Figure 7a-5
Note: The basic inquiry was completed, but it did not proceed further.
conversation_id: b31c3ae7e8fe11efbc9bf020ff63f4c4
Note: Next, write a test case to handle this issue.
a. Test Case (Level 4)
20250212 Wednesday Time Period: 15:34-16:00
Write the test case as follows:
Figure 7a-6
Note: Run it to see the test results; still use the mini program for testing. The test found that it could eventually ask successfully, but it disconnected.
b. Why Did It Disconnect? (Level 4)
20250212 Wednesday Time Period: 18:31-19:00
20250213 Thursday Time Period: 10:16-10:30
First, open phpstudy and run the proxy service; the screenshot is as follows:
Figure 7a-7
Note: Next, process the mini program to resolve the final disconnection issue.
c. Expert Diagnosis of Disconnection (Level 4)
20250213 Thursday Time Period: 10:40-11:00
Now running reports an error, as follows:
Figure 7a-8
Note: Check if there is an error with the proxy; test the interface using Postman.
The test results are as follows:
Figure 7a-9
Note: Why was it not discovered? Check the configuration file. The configuration file is fine; it was found that chat_sev was not started, which caused the issue. Next, find the reason for the disconnection.
Look for the historical records to find and resolve a streaming issue first.
Step 3: Streaming Issue (Level 3)
20250213 Thursday Time Period: 11:19-11:30
Currently, there is a situation: ragflow returns data in 10 seconds, and after chat_sev receives it, it is given to the mini program, which directly displays it. It means that the mini program has to wait 10 seconds before displaying the data. The reason is that chat_sev does not perform streaming reception and needs to be processed.
First, find the method to modify, which is: chat_direct_base_question
This method is used to obtain basic questions and needs to receive data in a streaming manner.
a. chat_direct_base_question Streaming Reception (Level 4)
20250213 Thursday Time Period: 11:26-11:30
def chat_direct_base_question(conversation_id:str,pure_question:str,question,is_stream:bool=True):
'''
Basic inquiry, directly ask the general question
'''
url = f"{RAG.BASE_URL}/api/chat_direct_bs_question"
resp = requests.post(
url = url,
json = json.dumps({
"conversation_id": conversation_id,
"pure_question": pure_question,
"question": question,
"is_stream":is_stream
}, default=custom_serializer),
headers = {
"Content-type": "application/json",
"Authorization": f"Bearer {RAG.API_KEY}"
}
)
if not 200 <= resp.status_code < 300:
raise Exception(f"GET {url} status_code {resp.status_code}.")
if not is_stream:
resp_json = resp.json()
if not resp_json.get('retcode') == 0:
raise Exception(f"chat completion fail,{resp_json}")
log.info(f"question:{question},answer:{resp_json}")
return resp_json['data']
return resp
Note: This does not use the streaming request interface; modify as follows:
Figure 7a-10
Note: It seems that just adding a parameter is enough; in fact, this parameter already exists, is_stream. Let’s run it to see the effect.
The effect is as follows:
Figure 7a-11
Note: This discovery is feasible and very fast. Next, change the expert diagnosis and general diagnosis to streaming as well.
b. Expert Diagnosis (Level 4)
20250213 Thursday Time Period: 14:47-15:00
20250213 Thursday Time Period: 15:08-15:30
Make the expert diagnosis streaming as well; modify the code as follows:
Figure 7a-12
Note: Test it to see how it works, and also handle the connection between basic inquiry and expert diagnosis. First, check the effect; the effect is as follows:
Figure 7a-13
Note: In the end, it disconnected inexplicably, and the reason needs to be investigated.
c. Unexplained Disconnection (Level 4)
20250213 Thursday Time Period: 15:31-16:00
The reason for the disconnection is generally an error reported by the backend. Check the reason as follows:
The reason is that the ragflow side got stuck; write a test case to measure what happened.
Unable to find the reason, recompile and see if it works.
d. Recompilation (Level 4)
20250213 Thursday Time Period: 16:53-17:00
Download the latest code and run the following command:
npm install --registry=https://registry.npmmirror.com
The screenshot is as follows:
Figure 7a-14
Note: Running still reports an error; the error screenshot is as follows:
Figure 7a-15
Note: The difference from before is that the dist folder contains node_modules, while the previous version did not. Therefore, this needs to be run again in the dist folder with the npm command:
Still not working; thinking of restarting the computer and reinstalling.
Before restarting, first uninstall the WeChat developer tool and try again; if it doesn’t work, try installing an older version.
e. Old Version Installation (Level 4)
20250213 Thursday Time Period: 17:44-18:00
Install the old version first to see if it works. The old version works, as shown in the screenshot below:
Figure 7a-16
Note: Next, continue to handle the connection between the expert diagnosis after the basic inquiry is completed.
2. Life Photos
Taken on 2019/2/17 at 12:35, when the eldest was one year and two months old. In fact, life is not difficult. In my childhood, in our village, there were rich people, but most were poor. The reason lies in their habits. Many people would work in the fields for a while in the morning, eat, work a bit more, and then play cards until evening, work a bit more, and then play cards until midnight before sleeping. Throughout the year, they relied on a few acres of land, earning only a few thousand yuan. However, I know an uncle whose parents died early. He learned to make tofu from his cousin and did not receive much education. He started making tofu at a young age, and after getting married, he would soak the beans at night, get up in the middle of the night to make tofu, and sell it before 9 AM. He could earn about 150 yuan a day. After 50 years, he is still making tofu, and people call him to order tofu. He can earn about 5,000 yuan a month, plus income from the land, making him a well-off family. Therefore, developing good habits may not lead to great wealth, but it certainly prevents starvation.
Figure 7b-1
The End