|
1 | 1 | [](https://www.ardu-badge.com/ChatGPT_Client) |
2 | | -# ChatGPT Client For Arduino |
3 | 2 |
|
4 | | -This library helps to use ChatGPT in Arduino environment. There are many features, but currently, only the Create chat completion part is implemented. |
5 | | -Since this uses an official API, you must obtain an API Key from openAI to use it. |
| 3 | +## Overview |
| 4 | +The ChatGPT Arduino Library provides a convenient way to interact with the OpenAI GPT models from Arduino environments, such as ESP32 devices. With this library, you can easily send text and vision queries to the ChatGPT API and receive responses directly in your Arduino projects. |
6 | 5 |
|
7 | | -## Authentication |
| 6 | +## Features |
| 7 | +- **Text Generation**: Generate text-based responses to user queries using the ChatGPT models. |
| 8 | +- **Vision Question Answering**: Utilize the vision capabilities of ChatGPT to answer questions about images. |
| 9 | +- **Simple API Integration**: Simple and intuitive API for seamless integration into your Arduino projects. |
8 | 10 |
|
| 11 | +## Authentication |
9 | 12 | The OpenAI API uses API keys for authentication. Visit your API Keys page to retrieve the API key you'll use in your requests. |
10 | 13 |
|
11 | 14 | First, get your SECRET KEY issued here. |
12 | | -https://platform.openai.com/account/api-keys |
| 15 | +https://platform.openai.com/api-keys |
13 | 16 |  |
14 | 17 |
|
15 | 18 | ## Installation |
@@ -38,41 +41,130 @@ Then you should see the examples and be able to include the library in your proj |
38 | 41 | ``` |
39 | 42 |
|
40 | 43 | ## Usage |
| 44 | +1. Include the `ChatGPT.hpp` header file in your Arduino sketch. |
| 45 | +2. Create a `ChatGPT` object and provide your API key and other required parameters. |
| 46 | +3. Use the provided methods to send queries to the ChatGPT API and receive responses. |
| 47 | + |
| 48 | +### Example: |
| 49 | +```cpp |
| 50 | +#include <ChatGPT.hpp> |
| 51 | + |
| 52 | +// Initialize ChatGPT client |
| 53 | +WiFiSSLClient wifiClient; |
| 54 | +ChatGPT<WiFiSSLClient> chatGPT(&wifiClient, "v1", "YOUR_API_KEY", 10000); |
| 55 | + |
| 56 | +void exampleTextQuestion() { |
| 57 | + /* |
| 58 | + model: Model to use for generating the response (e.g., "gpt-4o", "gpt-3.5-turbo"). |
| 59 | + role: Role of the message sender (e.g., "user" or "assistant"). |
| 60 | + content: Content of the message to send. |
| 61 | + max_tokens: Maximum number of tokens to generate in the response. |
| 62 | + content_only: Flag indicating whether to extract only the content of the response. (e.g., true - answer only, false - full response) |
| 63 | + result: Reference to a String variable to store the result of the API call. |
| 64 | + */ |
| 65 | + |
| 66 | + String result; |
| 67 | + Serial.println("\n\n[ChatGPT] - Asking a Text Question"); |
| 68 | + if (chatGPT_Client.chat_message("gpt-3.5-turbo", "user", "What is the best feature of GPT-4o?", 100, false, result)) { |
| 69 | + Serial.print("[ChatGPT] Response: "); |
| 70 | + Serial.println(result); |
| 71 | + } else { |
| 72 | + Serial.print("[ChatGPT] Error: "); |
| 73 | + Serial.println(result); |
| 74 | + } |
| 75 | +} |
41 | 76 |
|
42 | | -Here's a minimal example: |
43 | | -``` |
44 | | -if (chat_gpt.simple_message("gpt-3.5-turbo-0301", "user", "Planning a 3-day trip to San Diego", result)) { |
45 | | - Serial.println("===OK==="); |
| 77 | +void exampleVisionQuestionWithURL() { |
| 78 | + /* |
| 79 | + model: Model to use for generating the response (e.g., "gpt-4o"). |
| 80 | + role: Role of the message sender (e.g., "user" or "assistant"). |
| 81 | + type: Type of content (e.g., "text"). |
| 82 | + text: Text content of the message. |
| 83 | + image_type: Type of the image (e.g., "image_url"). |
| 84 | + image_url: URL of the image. |
| 85 | + detail: Detail level of the image (e.g., "high", "low", "auto"). |
| 86 | + max_tokens: Maximum number of tokens to generate in the response. |
| 87 | + content_only: Flag indicating whether to extract only the content of the response. (e.g., true - answer only, false - full response) |
| 88 | + result: Reference to a String variable to store the result of the API call. |
| 89 | + */ |
| 90 | + String result; |
| 91 | + Serial.println("\n\n[ChatGPT] - Asking a Vision Question"); |
| 92 | + if (chatGPT_Client.vision_question("gpt-4o", "user", "text", "What’s in this image?", "image_url", "https://samplelib.com/lib/preview/jpeg/sample-city-park-400x300.jpg", "auto", 400, false, result)) { |
| 93 | + Serial.print("[ChatGPT] Response: "); |
46 | 94 | Serial.println(result); |
47 | | -} else { |
48 | | - Serial.println("===ERROR==="); |
| 95 | + } else { |
| 96 | + Serial.print("[ChatGPT] Error: "); |
49 | 97 | Serial.println(result); |
| 98 | + } |
50 | 99 | } |
51 | 100 | ``` |
52 | 101 |
|
53 | | -Result |
| 102 | +### Result: |
| 103 | +
|
| 104 | +```json |
| 105 | +[ChatGPT] - Asking a Text Question |
| 106 | +[ChatGPT] Response: { |
| 107 | + "id": "chatcmpl-9QjdlCkqkB4dsVXBzUTRTBYafI7f3", |
| 108 | + "object": "chat.completion", |
| 109 | + "created": 1716158997, |
| 110 | + "model": "gpt-3.5-turbo-0125", |
| 111 | + "choices": [ |
| 112 | + { |
| 113 | + "index": 0, |
| 114 | + "message": { |
| 115 | + "role": "assistant", |
| 116 | + "content": "One of the best features of GPT-4o is its advanced natural language processing capabilities. GPT-4o has a deeper understanding of context, nuance, and complex language structures, allowing it to generate more accurate and coherent responses to a wide range of prompts. Its improved language modeling capabilities make it more versatile and effective in various tasks such as text generation, language translation, and question answering. Overall, the enhanced natural language processing capabilities of GPT-4o make it a powerful tool" |
| 117 | + }, |
| 118 | + "logprobs": null, |
| 119 | + "finish_reason": "length" |
| 120 | + } |
| 121 | + ], |
| 122 | + "usage": { |
| 123 | + "prompt_tokens": 19, |
| 124 | + "completion_tokens": 100, |
| 125 | + "total_tokens": 119 |
| 126 | + }, |
| 127 | + "system_fingerprint": null |
| 128 | +} |
| 129 | +``` |
| 130 | +```json |
| 131 | +[ChatGPT] - Asking a Vision Question |
| 132 | +[ChatGPT] Response: { |
| 133 | + "id": "chatcmpl-9Qjdp5B4wyE5cVbcLOucvm9uoT6rH", |
| 134 | + "object": "chat.completion", |
| 135 | + "created": 1716159001, |
| 136 | + "model": "gpt-4o-2024-05-13", |
| 137 | + "choices": [ |
| 138 | + { |
| 139 | + "index": 0, |
| 140 | + "message": { |
| 141 | + "role": "assistant", |
| 142 | + "content": "The image shows a peaceful lakeside pathway. The path is made of bricks and runs alongside a body of water. There is greenery on both sides of the path with trees providing shade on the right side. Off in the distance, you can see some buildings, possibly residential apartments, and more greenery. The atmosphere appears to be calm and serene." |
| 143 | + }, |
| 144 | + "logprobs": null, |
| 145 | + "finish_reason": "stop" |
| 146 | + } |
| 147 | + ], |
| 148 | + "usage": { |
| 149 | + "prompt_tokens": 268, |
| 150 | + "completion_tokens": 69, |
| 151 | + "total_tokens": 337 |
| 152 | + }, |
| 153 | + "system_fingerprint": "fp_927397958d" |
| 154 | +} |
54 | 155 | ``` |
55 | | -As an AI language model, I don't have personal preferences or can make travel arrangements but here's an outline of what one can experience in San Diego in a 3-day trip: |
56 | 156 |
|
57 | | -Day 1: |
58 | | -- Visit Balboa Park, a 1,200-acre cultural oasis with gardens, museums, theaters, and the famous San Diego Zoo. |
59 | | -- Check out the Gaslamp Quarter, a historic district filled with Victorian-era buildings, trendy restaurants, bars, and shops. |
60 | | -- Take in the stunning panoramic views of the city from Cabrillo National Monument, located on the southern tip of the Point Loma Peninsula. |
| 157 | +### Limitation |
61 | 158 |
|
62 | | -Day 2: |
63 | | -- Spend the day at the beach. San Diego has many beautiful beaches, including La Jolla Cove, Coronado Beach, and Mission Beach. |
64 | | -- Visit the USS Midway Museum, where visitors can board the decommissioned aircraft carrier and explore its 60 exhibits and 29 restored aircraft. |
65 | | -- Check out the Maritime Museum of San Diego, where you can tour historic ships and learn about maritime history. |
| 159 | +AVR and ESP8266 may not operate smoothly due to insufficient memory allocation. It looks like this part will need to be updated again soon. |
66 | 160 |
|
67 | | -Day 3: |
68 | | -- Explore Old Town San Diego, known as the birthplace of California, with its preserved adobe buildings, museums, and shops. |
69 | | -- Go on a whale watching excursion from the San Diego Harbor. |
70 | | -- Visit the San Diego Botanic Garden, which boasts 37 acres of gardens and includes a tropical rainforest, desert, and bamboo groves. |
| 161 | +# Updates |
71 | 162 |
|
72 | | -Overall, San Diego offers a wide range of attractions and activities for all tastes and ages. |
73 | | -``` |
| 163 | + - v0.2.0 |
| 164 | + - Support Vision Question (GPT-4o) |
| 165 | + - Support larger payloads |
| 166 | + - ArduinoJson 7 |
74 | 167 |
|
75 | | -# Updates |
76 | 168 | - v0.1.2 |
77 | 169 | - Demo Bugs Fixed |
78 | 170 |
|
|
0 commit comments