qt-openai
is a C++ library that provides an intuitive interface for interacting with OpenAI's API using the Qt framework. This project leverages the power of OpenAI's language models while utilizing Qt's robust networking and JSON capabilities to create seamless integrations for your Qt applications.
- Asynchronous API Calls: Leverages Qt's
QNetworkAccessManager
for non-blocking API requests. - Simple Interface: Provides a clean and easy-to-use interface for making requests to OpenAI's API.
- JSON Parsing: Parses and handles JSON responses efficiently using
QJsonDocument
. - Extendable: Designed to be extended for additional OpenAI API endpoints.
- Qt 5.15+ or Qt 6.x
- C++17 or later
- A valid OpenAI API key
-
Clone the repository:
git clone https://github.com/muman613/qt-openai.git cd qt-openai
-
Include the project in your Qt application:
- Add the library source files to your project.
- Update your
.pro
file or CMake configuration to include the necessary headers and sources.
-
Install dependencies:
- Ensure your Qt installation supports
QNetworkAccessManager
andQJsonDocument
.
- Ensure your Qt installation supports
-
Set up the library in your project: Include the
OpenAIClient
class and related files. -
Initialize the client:
#include "OpenAIClient.h" OpenAIClient client("your_openai_api_key");
-
Make a request:
// Example: Sending a prompt to OpenAI's ChatGPT API QString prompt = "What is the capital of France?"; client.sendChatRequest(prompt, [](const QString& response) { qDebug() << "OpenAI Response:" << response; });
-
Handle responses: Use the provided callback mechanism or signals/slots for handling responses.
- See the example directory for sample applications demonstrating various use cases.
Contributions are welcome! If you find a bug or have a feature request, please open an issue or submit a pull request.
- Fork the repository.
- Create a feature branch:
git checkout -b feature/your-feature-name
- Commit your changes:
git commit -m "Add your message here"
- Push your branch and open a pull request:
git push origin feature/your-feature-name
This project is licensed under the MIT License. See the LICENSE file for details.
- OpenAI for providing the API and inspiration.
- The Qt Project for the robust C++ framework that powers this library.
Thank you for using qt-openai
. If you have any questions, feel free to open an issue or contact the maintainer.