Skip to content

Commit dd47c1d

Browse files
committed
Patch 🩹
1 parent dc50936 commit dd47c1d

File tree

4 files changed

+22
-33
lines changed

4 files changed

+22
-33
lines changed

examples/Datatest/Datatest.ino

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ void setup() {
99
chatbot.setKey("YOUR_CHATGPT_API_KEY", "chatgpt");
1010

1111
//Begin WiFi connection
12-
WiFi.begin("SSID", "PASSWORD");
13-
while (WiFi.status() != WL_CONNECTED) {
14-
delay(1000);
15-
Serial.println("Connecting to WiFi...");
16-
}
17-
Serial.println("Connected to WiFi");
12+
chatbot.connectWiFi("YOUR_SSID", "YOUR_PASSWORD");
1813

1914
// Select AI and optionally specify version
2015
chatbot.selectAI("chatgpt", "gpt-3.5-turbo");

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name=AIChatBot
2-
version=0.1.0
2+
version=1.1.0
33
author=bay_Eggex <https://github.com/bayeggex>
44
maintainer=bay_Eggex
55
sentence=AI Chat Library for Arduino
66
paragraph=Arduino library for integrating AI chat like OpenAIs ChatGPT, Hugging Face Transformers, and more.
77
category=Communication
88
url=https://github.com/bayeggex/Arduino-AI-Chat-Library
99
architectures=*
10-
includes=AIChatbot.h
10+
includes=AIChatbot.h

src/AIChatbot.cpp

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
#include "AIChatbot.h"
22

3-
AIChatbot::AIChatbot() : chatGPTApiKey(""), huggingFaceApiKey(""), selectedAI(""), selectedAIVersion("gpt-3.5-turbo") {}
3+
AIChatbot::AIChatbot()
4+
: chatGPTApiKey(""), huggingFaceApiKey(""), selectedAI(""), selectedAIVersion("gpt-3.5-turbo") {}
45

56
void AIChatbot::begin(long baudRate) {
67
Serial.begin(baudRate);
7-
// WiFi.begin("SSID", "PASSWORD");
8-
// while (WiFi.status() != WL_CONNECTED) {
9-
// delay(1000);
10-
// Serial.println("Connecting to WiFi...");
11-
// }
12-
// Serial.println("Connected to WiFi");
8+
}
9+
10+
void AIChatbot::connectWiFi(const char* ssid, const char* password) {
11+
WiFi.begin(ssid, password);
12+
while (WiFi.status() != WL_CONNECTED) {
13+
delay(1000);
14+
Serial.println("Connecting to WiFi...");
15+
}
16+
Serial.println("Connected to WiFi");
1317
}
1418

1519
void AIChatbot::update() {
@@ -54,13 +58,6 @@ String AIChatbot::sendToChatGPT(const String& message) {
5458
return "ChatGPT API key not set.";
5559
}
5660

57-
if(selectedAIVersion.isEmpty()) {
58-
return "Check the Spelling or Write the name of the AI Model Correctly, if is not take a look catalog ""https://platform.openai.com/docs/models/overview";
59-
}
60-
if(selectedAIVersion == "DALL" && "DALL-E" && "Whisper"){
61-
return "Its not supported at this point, try to use gpt-4-turbo, gpt-3.5-turbo or other GPT modules, also take a look catalog ""https://platform.openai.com/docs/models/overview"" for more information";
62-
}
63-
6461
String url = "https://api.openai.com/v1/chat/completions";
6562
String payload = "{\"model\": \"" + selectedAIVersion + "\", \"messages\": [{\"role\": \"user\", \"content\": \"" + message + "\"}]}";
6663

@@ -72,16 +69,6 @@ String AIChatbot::sendToHuggingFace(const String& message) {
7269
return "Hugging Face API key not set.";
7370
}
7471

75-
if(selectedAIVersion.isEmpty()) {
76-
return "Check the Spelling or Write the name of the AI Model Correctly, if is not take a look catalog ""https://huggingface.co/models";
77-
}
78-
79-
if (huggingFaceApiKey.isEmpty() && selectedAIVersion.isEmpty())
80-
{
81-
return "Hugging Face API key and AI Model not set. please look up the doc ""https://github.com/bayeggex/Arduino-AI-Chat-Library/blob/main/Docs.md""";
82-
}
83-
84-
8572
String url = "https://api-inference.huggingface.co/models/" + selectedAIVersion;
8673
String payload = "{\"inputs\": \"" + message + "\"}";
8774

src/AIChatbot.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
#define AI_CHATBOT_H
33

44
#include <Arduino.h>
5+
6+
#ifdef ESP32
57
#include <WiFi.h>
68
#include <HTTPClient.h>
9+
#elif defined(ESP8266)
10+
#include <ESP8266WiFi.h>
11+
#include <ESP8266HTTPClient.h>
12+
#endif
713

814
class AIChatbot {
915
public:
1016
AIChatbot();
1117
void begin(long baudRate);
18+
void connectWiFi(const char* ssid, const char* password);
1219
void update();
1320
void setKey(const String& key, const String& aiName);
1421
void selectAI(const String& aiName, const String& aiVersion = "gpt-3.5-turbo");
@@ -24,4 +31,4 @@ class AIChatbot {
2431
String makeHttpRequest(const String& url, const String& payload, const String& apiKey);
2532
};
2633

27-
#endif
34+
#endif // AI_CHATBOT_H

0 commit comments

Comments
 (0)