Skip to content

Commit 4c15433

Browse files
authored
Update Docs.md
1 parent 17bc1f9 commit 4c15433

File tree

1 file changed

+128
-9
lines changed

1 file changed

+128
-9
lines changed

Docs.md

Lines changed: 128 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,19 @@ Before using the AI Chat Library, you need to set your API keys for the respecti
2929
AIChatbot chatbot;
3030

3131
void setup() {
32-
Serial.begin(115200);
32+
chatbot.begin(115200);
3333

3434
// Set API keys
3535
chatbot.setKey("YOUR_CHATGPT_API_KEY", "chatgpt");
3636
chatbot.setKey("YOUR_HUGGING_FACE_API_KEY", "huggingface");
3737

38-
// Begin WiFi connection
39-
WiFi.begin("SSID", "PASSWORD");
40-
while (WiFi.status() != WL_CONNECTED) {
41-
delay(1000);
42-
Serial.println("Connecting to WiFi...");
38+
// Connect to WiFi
39+
if (!chatbot.connectWiFi("SSID", "PASSWORD")) {
40+
Serial.println("Failed to connect to WiFi");
41+
while (true); // Halt if WiFi connection fails
4342
}
44-
Serial.println("Connected to WiFi");
4543

46-
// Select AI and optionally specify version
44+
// Select AI service and optionally specify version
4745
chatbot.selectAI("chatgpt", "gpt-3.5-turbo");
4846
}
4947

@@ -55,6 +53,28 @@ void loop() {
5553

5654
### 📄Functions
5755

56+
### `begin(long baudRate)`
57+
58+
- **Description**: Initializes the serial communication with the specified baud rate.
59+
- **Parameters**:
60+
- `baudRate`: The baud rate for serial communication (e.g., 115200).
61+
- **Example**:
62+
```cpp
63+
chatbot.begin(115200);
64+
65+
#### `connectWiFi(const char* ssid, const char* password, unsigned long timeoutMs = 10000)`
66+
67+
- **Description**: Connects to a WiFi network with the given SSID and password.
68+
- **Parameters**:
69+
- `ssid`: WiFi SSID(Name).
70+
- `password`: WiFi password.
71+
- `timeoutMs`: (optional): Connection timeout in milliseconds (default is 10 seconds).
72+
- **Example**:
73+
```cpp
74+
if (!chatbot.connectWiFi("YourSSID", "YourPassword")) {
75+
Serial.println("WiFi connection failed");
76+
}
77+
5878
#### `selectAI(const String& aiName, const String& aiVersion = "gpt-3.5-turbo")`
5979

6080
- **Description**: Selects the AI service to use.
@@ -75,7 +95,7 @@ void loop() {
7595
```cpp
7696
chatbot.setKey("YOUR_CHATGPT_API_KEY", "chatgpt");
7797

78-
#### `send(const String& message)`
98+
#### `getResponse(const String& message)`
7999

80100
- **Description**: Sends a message to the selected AI service manually.
81101
- **Parameters**:
@@ -93,3 +113,102 @@ void loop() {
93113
void loop() {
94114
chatbot.update();
95115
}
116+
117+
### `sanitizeInput(const String& input)`
118+
119+
- **Description**: Sanitizes the input string to prevent issues with special characters.
120+
- **Parameters**:
121+
- `input`:The input string to sanitize.
122+
123+
124+
### 🔧 Internal Functions (Private)
125+
126+
These functions are used internally by the library and are not intended to be called directly by users.
127+
128+
`sendToChatGPT(const String& message)`
129+
130+
- Sends a message to the OpenAI ChatGPT API and returns the response.
131+
132+
`sendToHuggingFace(const String& message)`
133+
134+
- Sends a message to the Hugging Face API and returns the response.
135+
136+
`makeHttpRequest(const String& url, const String& payload, const String& apiKey)`
137+
138+
-Makes an HTTP POST request to the specified URL with the given payload and API key.
139+
140+
### 📚 Header File (AIChatbot.h)
141+
142+
```h
143+
#ifndef AI_CHATBOT_H
144+
#define AI_CHATBOT_H
145+
146+
#include <Arduino.h>
147+
148+
#if defined(ESP32)
149+
#include <WiFi.h>
150+
#include <WiFiClientSecure.h>
151+
#include <HTTPClient.h>
152+
#define PLATFORM_NAME "ESP32"
153+
#elif defined(ESP8266)
154+
#include <ESP8266WiFi.h>
155+
#include <ESP8266HTTPClient.h>
156+
#define PLATFORM_NAME "ESP8266"
157+
#endif
158+
159+
class AIChatbot {
160+
public:
161+
AIChatbot();
162+
bool connectWiFi(const char* ssid, const char* password, unsigned long timeoutMs = 10000);
163+
bool validateKeys();
164+
void begin(long baudRate);
165+
void update();
166+
void setKey(const String& key, const String& aiName);
167+
void selectAI(const String& aiName, const String& aiVersion = "gpt-3.5-turbo");
168+
String sanitizeInput(const String& input);
169+
String getResponse(const String& message);
170+
171+
private:
172+
String chatGPTApiKey;
173+
String huggingFaceApiKey;
174+
String selectedAI;
175+
String selectedAIVersion;
176+
String sendToChatGPT(const String& message);
177+
String sendToHuggingFace(const String& message);
178+
String makeHttpRequest(const String& url, const String& payload, const String& apiKey);
179+
};
180+
181+
#endif // AI_CHATBOT_H
182+
```
183+
184+
### 🔧 Example Sketches
185+
186+
`AITranslation.ino`: Demonstrates translation capabilities using the library.
187+
188+
`ChatGPT.ino`: Example of integrating with ChatGPT for general conversation.
189+
190+
`DataTest.ino`: Verifies communication and tests various AI responses.
191+
192+
`HuggingFace.ino`: Shows usage with Hugging Face models.
193+
194+
`QuestionAnswering.ino`: Example for question-answering tasks.
195+
196+
`TextGeneration.ino`: Demonstrates text generation capabilities.
197+
198+
`TextSummarization.ino`: Example for summarizing input text.
199+
200+
### 📈 Roadmap
201+
202+
- Add support for more AI services.
203+
204+
- Improve error handling and debugging tools.
205+
206+
- Enhance documentation with more detailed examples.
207+
208+
- Voice & Image Cration.
209+
210+
### 🛠️ Support
211+
212+
For [issues](https://github.com/bayeggex/Arduino-AI-Chat-Library/issues/new), [feature requests](https://github.com/bayeggex/Arduino-AI-Chat-Library/issues/new), or [Contributions](https://github.com/bayeggex/Arduino-AI-Chat-Library/pulls), please visit the [GitHub repository](https://github.com/bayeggex/Arduino-AI-Chat-Library).
213+
214+
This library is maintained by [BayEggex](https://github.com/bayeggex). Contributions are welcome!

0 commit comments

Comments
 (0)