Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

* It uses playwright and chromium to open browser and parse html.
* It is an unoffical api for development purpose only.
* It includes a client script that starts a chat REPL in the command line.


# How to install
## How to install

* Make sure that python and virual environment is installed.

Expand All @@ -30,23 +30,28 @@ pip install -r requirements.txt
playwright install
```

* Now run the server
## How to run

* Run the server at port `5001`. If you want to change, you can change it in server.py

```
python server.py
```

* The server runs at port `5001`. If you want to change, you can change it in server.py
* Start a chat REPL in the command line

```sh
python client.py
```

# Api Documentation
## Api Documentation

* There is a single end point only. It is available at `/chat`

```sh
curl -XGET http://localhost:5001/chat?q=Write%20a%20python%20program%20to%20reverse%20a%20list
```

# Credit
## Credit

* All the credit for this script goes to [Daniel Gross's whatsapp gpt](https://github.com/danielgross/whatsapp-gpt) package. I have just taken the script as an individual file and added documentation for how to install and run it.
39 changes: 39 additions & 0 deletions client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import urllib.parse
import requests
import readline
import sys
from builtins import input

def process_query(query):
if query == "quit":
print("Exiting.")
sys.exit()

# Define the base URL
base_url = "http://localhost:5001/chat"

# URI encode the string argument
encoded_arg = urllib.parse.quote(query)

# Append the encoded argument to the base URL
url = base_url + "?q=" + encoded_arg

# Make a GET request to the URL
response = requests.get(url)

# Print the response
print(response.text)

def loop():
# Set up the REPL loop
while True:
# Prompt the user for input
query = input("⎊: ")
print("--")

# Evaluate the user's input
process_query(query)
print("--")

if __name__ == "__main__":
loop()