Welcome to Raspbot V2 repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
6.Dual-model agent application
Dual-Model Intelligent Agent Application
Dual-Model Intelligent Agent ApplicationExperimental PurposeExperimental Quick Start StepsExperimental ResultsMain Source Code AnalysisDepends on local dify configuration
Experimental Purpose
By communicating with a smart car through language, the smart car, powered by dual AI models, will be able to perform motion and scene analysis based on non-fixed semantics.
Experimental Quick Start Steps
- First, power on the computer, wait for the IP address to appear on the OLED screen, and then log in remotely via VNC to the Raspberry Pi desktop.
- Open a new terminal and enter the command:
cd /home/pi/project_demo/09.AI_Big_Model/- Modify the file configuration:
xxxxxxxxxxgedit API_KEY.pySet AI_Agent = Flase, as shown in the image.

- Then, fill in TONYI_KEY for the Chinese version and openAI_KEY for the English version according to the prerequisite configuration document. Save and exit the API_KEY.py file, then run the following command:
xxxxxxxxxx#Start the Chinese version commandpython3 AI_CarAgent/AI_Car_ImageMain.pyxxxxxxxxxx#Start the English version commandpython3 AI_CarAgent_en/AI_Car_ImageMain.py- The car enters the wakeup state. For domestic users, the wakeup phrase is for international users, "Hi,yahboom".
- After successfully waking up, the car will respond with a horn sound. After waiting for 1 second, you can then specify the desired action or visual movement for the car.
- Based on the semantics, the smart car first analyzes the results using the language model at the decision layer. This result is then passed to the model at the execution layer for action execution. Finally, the car executes the series of action commands and provides some dialogue feedback.
- This concludes the conversation process. To continue the conversation, repeat steps 5-8.
Experimental Results
- Waiting for wakeup

- Start recording

- After speech recognition, provide feedback and execute corresponding action commands

Main Source Code Analysis
xdef play_agent_image(): print("start") global response,agent_plan_output,xuanxin while True: if detect_keyword(): xuanxin = 1 os.system("pkill mplayer") Car_Reset() #Carriage reset time.sleep(.2) if os.path.exists(SAVE_FILE): os.remove(SAVE_FILE) time.sleep(0.2) start_recording() time.sleep(0.2) if TTS_IAT_Tongyi: rectext = rec_wav_music_Tongyi() else: rectext = rec_wav_music() if rectext != "": print("Q:"+ rectext) try: agent_plan_output = eval(Car_decision_Plan(rectext)) response = agent_plan_output['response'] except: display_text = "Decision failed, please try again..." print(display_text) continue print("A:"+response) else : print('"No information was recognized, please try again"') if rectext == 0: breakdetect_keyword: Wake-up function for the wake-up word start_recording: API for starting recording
- Chinese version-specific configuration rec_wav_music_Tongyi: Tongyi Qianwen speech recognition, effective when TTS_IAT_Tongyi = True and the Chinese version is used rec_wav_music: iFlytek Spark speech recognition solution, effective when TTS_IAT_Tongyi = False and the Chinese version is used TTS_IAT_Tongyi: Configured in API_KEY.py
Car_tonyi_agent_online: This API executes actions based on the agent configured on the Tongyi Qianwen platform. When AI_Agent = True, configure the viewing selection section. Car_decision_Plan(rectext): This API uses information from the decision-making model in the locally deployed Car_decision_agent.py to make action decisions.
In the Car_execute_api.py file, there are:
Car_Tongyi_Image_Agent: The action-performing agent. This combines with the online deployment to execute actions on the car. This takes effect when AI_Agent = True.
Car_Agent_Plan_Image: The action-performing agent. This combines with the locally deployed Car_agent_Image.py to execute actions on the car. This takes effect when AI_Agent = False.
- The English version's speech synthesis and recognition are already packaged and are not required here.
Modify the recording duration, start threshold, and end threshold
- Enter
shellin the terminal #Chinese Version cd /home/pi/project_demo/09.AI_Big_Model/AI_CarAgent/ gedit Car_audio.py
#English Version cd /home/pi/project_demo/09.AI_Big_Model/AI_CarAgent_en/ gedit Car_audio.py
xxxxxxxxxx2. Find the source code shown below.- start_threshold: The threshold for starting recording when sound is detected (can be lowered to 5000 in quiet environments, increased to 150000+ in noisy environments)- end_threshold: The threshold for stopping recording when sound is detected. Recommended value is 30-50% of start_threshold- endlast: Determines the number of times to stop recording. Here, it's 15. For example, if 15 consecutive sound levels meet the stop threshold, recording will automatically terminate.- max_record_time: Recording duration. Here, it's 5.Note: start_threshold > end_threshold. This is a required rule; its value can be determined based on the environment.### Overall flow chart of this experiment## (Selected Section)### 1. Customizing the English Version**Modifying the Execution Layer**#### Configuration Not Dependent on Dify0. First, change the DIFY_SWITCH variable in the API_KEY.py file to False.1. Enter the following command in the terminal:
cd /home/pi/project_demo/09.AI_Big_Model/AI_CarAgent_en/ gedit Car_agent_Image.py
xxxxxxxxxxSimply modify this file. Note: Do not change the content in the green box. You can add, but not delete or modify.You can modify this file to use the action interface. This requires some basic knowledge and is not recommended for beginners.2. After the modification is complete, you can replace the large model by editing **Car_Online_API.py**.```shellcd /home/pi/project_demo/09.AI_Big_Model/AI_CarAgent_en/gedit Car_Online_API.py
Then modify the model indicated by the red box.

Learn about the replaceable models First, visit the website openrouter
To replace Google: Gemini Take 2.0 as an example (select a model that can analyze images):


Depends on local dify configuration
- dify is disabled by default in the image. You need to enable it by executing the above command.
xxxxxxxxxxcd ~/dify-1.6.0/docker./docker-compose-linux-aarch64 up -dThis will enable it.
If you don't want dify to be running all the time (not recommended for 2GB of memory), execute the following command to disable it.
xxxxxxxxxxcd ~/dify-1.6.0/docker./docker-compose-linux-aarch64 down- First, rename the file in the API_KEY.py file. Set the DIFY_SWITCH variable to True; otherwise, the Dify model will not be used.
- To view the large model, use the configuration settings and configure all Dify-related environment settings.
- Open a browser on a computer on the same network segment as the OLED screen's displayed IP address. Enter the IP address in the URL bar and press Enter.
- Click "Studio" and select the "RaspbotV2_Car" application.

- To customize the model, modify the settings as shown in the image.

- Instructions
- 1: This is where you can change the model. The model you are changing to must be capable of analyzing images. The model with the icon shown in the image indicates it is a vision model.
After changing the model, remember to enable the vision function.

- 2: This is to limit the input and output of the large model. You can obtain it from "/home/pi/project_demo/09.AI_Big_Model/AI_CarAgent_en/Car_agent_Image.py" or from "Intelligent agent prompt words.md". Copy and paste it into the text box in step 2.
- 3: This is to add the knowledge base. You must first add files to the knowledge base. This example provides the car motion knowledge base "action-knowledge_base.md" and some training examples "Training examples.xlsx". These two files have already been added. If you need to add or delete content, simply rewrite them and add them again.
After updating, click the button in the upper right corner and republish to use the modified intelligent agent.

- Configuring a Knowledge Base (Optional)
- Select the Knowledge option and click "Create knowledge" to create a new knowledge base. This example provides two existing knowledge bases: "action-knowledge_base.md" and "Training examples.xlsx," which contains some training examples.

- Here, we'll use "action-knowledge_base.md" as an example.

- After selecting your desired configuration, click "Save & Process" to complete the knowledge base addition.

- To bind the added knowledge base, return to the "Studio" workspace, then go to the application and click Add Knowledge Base.

Select the knowledge base you want to add to this app. The image here only adds the action-knowledge_base.md knowledge base. If you want to add training cases, select this as well.

- After adding, publish the app to update it. If you add a knowledge base but don't publish an update, the app won't save the added knowledge base and will revert to the pre-addition version.

Modify the decision layer model Terminal input
xxxxxxxxxxcd /home/pi/project_demo/09.AI_Big_Model/AI_CarAgent_en/gedit Car_decision_agent.pyYou can modify the content within the red box; the green box remains unchanged.

Learn about replaceable models First, visit this website openrouter
Terminal input
xxxxxxxxxxcd /home/pi/project_demo/09.AI_Big_Model/AI_CarAgent_en/gedit Car_Online_API.pyUsing deepseak as an example:


Verify the changes and run the startup command
xxxxxxxxxxcd /home/pi/project_demo/09.AI_Big_Model/python3 AI_CarAgent_en/AI_Car_ImageMain.pyIf the decision layer also wants to be similar to the execution layer, press the execution layer to start the agent. In this case, the decision layer is in the .py file
Tips List some dialogues
- Drive forward for 2 seconds, then change the taillights to gold, then turn left half a circle. Finally, describe what you saw.
- Change the taillights to a more romantic color and play Jay Chou's "Rice Fragrance."
- Turn in a circle and perform face tracking.
- Change the lights to green and track the object next to xx (xx is an object that can be named).
Notes:
- When entering the Tracking and Line Patrol cases, you need to select the displayed image and press the lowercase 'q' on your keyboard to exit these cases. You can also end the normal visual tracking by waking them up.
- Line Patrol and Follow Colors: Normally, only red, yellow, blue, and green are available. Black allows you to follow a line on a map with black lines on a white background without tracking.