https://github.com/thisago/dirtygpt
A dirty and free way to use ChatGPT in Nim
https://github.com/thisago/dirtygpt
ai chatgpt free implementation library nim
Last synced: about 12 hours ago
JSON representation
A dirty and free way to use ChatGPT in Nim
- Host: GitHub
- URL: https://github.com/thisago/dirtygpt
- Owner: thisago
- License: mit
- Created: 2023-08-21T22:43:54.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-10-08T15:32:40.000Z (over 2 years ago)
- Last Synced: 2024-05-02T04:17:51.263Z (about 2 years ago)
- Topics: ai, chatgpt, free, implementation, library, nim
- Language: Nim
- Homepage:
- Size: 46.9 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- License: license
Awesome Lists containing this project
README

# DirtyGPT
#### A dirty and free way to use ChatGPT in Nim
**[About](#about) - [How it works?](#how-it-works) - [Installation](#installation) - [Usage](#usage)** - [License](#license)
## About
Prompt in ChatGPT web using Nim!
See this lib working at [cligpt](https://github.com/thisago/cligpt)
## How it works?
When you create a new instance of `DirtyGPT`, an http web server starts
asynchronously, it accept multiple websocket connections and when you query the
prompt in lib, the server will add your prompt to the queue, and the connected
userscripts will request a prompt. When the server sends the prompt to a client
(userscript), it saves the client ID in prompt and if for some reason the client
disconnects, the items bound to that client ID will be cleaned and wait to be
asked, in higher priority than others.
The client userscript controls the ChatGPT webpage, when it receives the prompt,
it fills up the input and clicks in the button to send. When AI is answering, the
button changes, when it returns to their original form, the userscript reads the
output HTML, converts it to Markdown and sends back to server (lib). Then it's
available to another prompt, the loop will request the next one.
## Installation
Install the lib with Nimble:
```bash
nimble install dirtygpt
```
And at installation end you'll see something like this:
```text
[...]
Please, don't forget to install the client userscript in your browser: ~/.nimble/pkgs2/dirtygpt-version-hash/userscript.user.js
```
Install the provided Javascript userscript path in a userscript manager in your
browser, like [Greasemonkey][greasemonkey] (Violentmonkey doesn't works, the
browser blocks you to open localhost WS)
## Usage
After installed the library and userscript, make sure that you have an open tab
with [ChatGPT][chatgpt] logged in.
The usage is simple:
[`prompt.nim`](examples/prompt.nim)
```nim
import std/asyncdispatch
import pkg/dirtygpt
let gpt = newDirtyGpt()
echo waitFor gpt.prompt "Hello, are you Google Bard?"
stop gpt
```
stdout
```text
No, I'm not Google Bard. I'm ChatGPT, an AI language model created by OpenAI. While both Google Bard and I are AI language models designed to generate text-based responses, we come from different organizations and have different underlying technologies. How can I assist you today?
```
## TODO
- [x] Add pinging because `connectedClients` is just updated when exceeds timeout
## License
This piece of software is libre, licensed over the MIT license. Feel free to use!
[greasemonkey]: https://www.greasespot.net/
[chatgpt]: https://chat.openai.com