Skip to content

Add indicator_openai_api demo #71

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/indicator_openai_api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
5 changes: 5 additions & 0 deletions examples/indicator_openai_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## changelog

### v1.0.0 ###

* Initial version.
14 changes: 14 additions & 0 deletions examples/indicator_openai_api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)

set(EXTRA_COMPONENT_DIRS ../../components)

add_compile_options(-fdiagnostics-color=always -w)

project(indicator_openai)

# 添加esp_http_client和esp_crt_bundle组件
set(COMPONENT_REQUIRES esp_http_client esp_crt_bundle)
78 changes: 78 additions & 0 deletions examples/indicator_openai_api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Indicator OpenAI API Demo

This demo is a modified version of the **indicator openai demo**, removing the DALL·E image generation feature and adapting to more large language models compatible with the **OpenAI API format**, such as **DeepSeek**, **Qwen**, **Claude**, etc.

## Function
- [x] Time display.
- [x] CO2, tVOC, Temperature and Humidity data real-time display.
- [x] CO2, tVOC, Temperature and Humidity history data display.
- [x] Wifi config.
- [x] Display config.
- [x] Time config.
- [x] Chat with selectable large language models

## How to use example

Please first read the [User Guide](https://wiki.seeedstudio.com/SenseCAP_Indicator_Get_Started) of the SenseCAP Indicator Board to learn about its software and hardware information.

When using LLM-related functions, you must first configure the necessary parameters through the ESP32 serial port using the following commands:

### Available Commands

1. **Set OpenAI API Key**

```
openai_api -k <your key>
```
Sets your API key for authentication with the LLM service. Maximum length is 164 bytes.

2. **Set API URL**

```
openai_api -u <your url>
```
Sets the API endpoint URL. Default is "https://api.openai.com/v1" for OpenAI. For other providers, use their specific endpoints. Maximum length is 100 bytes.

Examples:
- DeepSeek: `openai_url -u https://api.deepseek.com/v1`
- SiliconFlow: `openai_url -u https://api.siliconflow.com/v1`

3. **Set Model**

```
openai_model <model_name>
```
Sets the model to use for chat completions. Maximum length is 50 bytes.

Examples:
- OpenAI: `openai_model gpt-3.5-turbo`
- DeepSeek: `openai_model deepseek-chat`
- Qwen: `openai_model qwen-7b`

4. **Set System Prompt**

```
openai_system <prompt>
```
Sets the system prompt that defines the assistant's behavior. Maximum length is 256 bytes.

Default prompt:
```
Your are SenseCAP Indicator, developed by Seeed Studio, has been launched on April 20th, 2023. You are a 4-inch touch screen driven by ESP32 and RP2040 dual-MCU, and support Wi-Fi/BLE/LoRa communication. You are a fully open-source powerful IoT development platform for developers. You are on behalf of Seeed Studio to answer requests. Each time your answer text should not exceed 100 words.
```

### Build and Flash

1. The project configure PSRAM with Octal 120M by default. please see [here](../../tools/patch/README.md#idf-patch) to enable `PSRAM Octal 120M` feature.
2. Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.

(To exit the serial monitor, type ``Ctrl-]``.)

See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) for full steps to configure and use ESP-IDF to build projects.

## To-do List
- [ ] Optimize the Set API Key UI elements and display; currently, UI element modifications don't synchronize with the information used by the LLM
- [ ] Test more LLM service providers (currently tested: DeepSeek, SiliconFlow, Alibaba Cloud Bailian)
- [ ] Conduct more comprehensive feature testing and bug testing
- [ ] Optimize the UI
- [ ] Change images
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/indicator_openai_api/docs/ChatGPT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/indicator_openai_api/docs/OpenAI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions examples/indicator_openai_api/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set(UI_DIR ./ui)
file(GLOB_RECURSE UI_SOURCES ${UI_DIR}/*.c)

set(MODEL_DIR ./model)
file(GLOB_RECURSE MODEL_SOURCES ${MODEL_DIR}/*.c)

set(VIEW_DIR ./view)
file(GLOB_RECURSE VIEW_SOURCES ${VIEW_DIR}/*.c)

set(CONTROLLER_DIR ./controller)
file(GLOB_RECURSE CONTROLLER_SOURCES ${CONTROLLER_DIR}/*.c)

set(UTIL_DIR ./util)
file(GLOB_RECURSE UTIL_SOURCES ${UTIL_DIR}/*.c)

idf_component_register(
SRCS "main.c" "lv_port.c" ${UI_SOURCES} ${MODEL_SOURCES} ${VIEW_SOURCES} ${CONTROLLER_SOURCES} ${UTIL_SOURCES}
INCLUDE_DIRS "." ${UI_DIR} ${MODEL_DIR} ${VIEW_DIR} ${CONTROLLER_DIR} ${UTIL_DIR}
EMBED_TXTFILES timeapi_cert.pem)
34 changes: 34 additions & 0 deletions examples/indicator_openai_api/main/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@


#ifndef CONFIG_H
#define CONFIG_H


#include <stdbool.h>
#include <string.h>
#include <time.h>
#include "esp_system.h"
#include "esp_err.h"
#include "esp_log.h"
#include "esp_event_base.h"
#include "bsp_board.h"

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#ifdef __cplusplus
extern "C" {
#endif


ESP_EVENT_DECLARE_BASE(VIEW_EVENT_BASE);

extern esp_event_loop_handle_t view_event_handle;



#ifdef __cplusplus
}
#endif

#endif
Loading