Python Forum
I'm trying to make my Alexa/Echo dot 3 powered by ChatGPT....
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I'm trying to make my Alexa/Echo dot 3 powered by ChatGPT....
#1
Hello.

I'm trying to make my Alexa/Echo dot 3 powered by ChatGPT. I would like to integrate ChatGPT into my Alexa / Echo dot 3. I want to have more engaging and natural conversations with my smart speaker. To achieve the goal I found a Step-By-Step guide. The relevant steps to do are :


https://pastebin.ubuntu.com/p/dMsfQzj33g/


Unfortunately I haven't been able to understand what to do to make my Alexa Echo dot 3 reply to my questions using the chat gpt style because I found some problems before reaching the end of the tutorial. This is what I did :


on Debian x64 bit : (IP number = 192.168.1.2)


a) Opened bing chat on Edge and copied my cookies to cookies.json using the extension cookie-editor

b) mounted the zpool zroot2 with the following command :


zpool import -f -R /mnt/zroot2 zroot2


the project files are stored under the path : -----> /mnt/zroot2/zroot2/ChatGPT/BingChatGPT


2. on the jetson nano (where I have installed ubuntu 20.04 for arm64) :


a) mounted the zpool with the following command :


sshfs -o allow_other,default_permissions [email protected]:/mnt/zroot2/zroot2 /mnt/fisso


b) python server.py

Output:
* Serving Flask app 'server' * Debug mode: off WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on http://127.0.0.1:8080 Press CTRL+C to quit
When I open that link using Firefox,I see the error :


Output:
"The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again"
and on the Terminal :


Output:
127.0.0.1 - - [08/Apr/2023 16:18:59] "GET / HTTP/1.1" 404 - 127.0.0.1 - - [08/Apr/2023 16:19:01] "GET /favicon.ico HTTP/1.1" 404 - 127.0.0.1 - - [08/Apr/2023 16:19:28] "GET / HTTP/1.1" 404
As a further experiment I've re-configured everything to make it work on my X64 Debian 11 workstation. I've opened the address : 127.0.0.1:8080 with Edge but I've got the same error as before :

Output:
Not Found. The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
And on the terminal I see :


Output:
marietto@marietto:/mnt/zroot2/zroot2/ChatGPT/BingChatGPT/amd64$ python server.py * Serving Flask app 'server' * Debug mode: off WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on http://127.0.0.1:8080 Press CTRL+C to quit 127.0.0.1 - - [08/Apr/2023 21:32:08] "GET / HTTP/1.1" 404 - 127.0.0.1 - - [08/Apr/2023 21:32:09] "GET /favicon.ico HTTP/1.1" 404 - 127.0.0.1 - - [08/Apr/2023 22:16:21] "GET / HTTP/1.1" 404 - 127.0.0.1 - - [08/Apr/2023 22:16:21] "GET /favicon.ico HTTP/1.1" 404 - 127.0.0.1 - - [08/Apr/2023 22:16:28] "GET / HTTP/1.1" 404
But why ? Maybe there is some mistake with the cookies.json file ? Can you give a look ? You can find the json file here :


https://pastebin.ubuntu.com/p/ZfQQDqPqcb/


To be honest I haven't understood why I should save the cookies inside the json file,so probably the error is inside that file.


As a final consideration : I don't see errors between the python libraries installed by the project :


Output:
marietto@marietto:/mnt/zroot2/zroot2/ChatGPT/BingChatGPT/amd64$ pip install -r requirements.txt Defaulting to user installation because normal site-packages is not writeable Requirement already satisfied: EdgeGPT==0.0.60 in /home/marietto/.local/lib/python3.10/site-packages (from -r requirements.txt (line 1)) (0.0.60) Requirement already satisfied: Flask==2.2.3 in /home/marietto/.local/lib/python3.10/site-packages (from -r requirements.txt (line 2)) (2.2.3) Requirement already satisfied: rich in /home/marietto/.local/lib/python3.10/site-packages (from EdgeGPT==0.0.60->-r requirements.txt (line 1)) (13.3.3) Requirement already satisfied: websockets in /home/marietto/.local/lib/python3.10/site-packages (from EdgeGPT==0.0.60->-r requirements.txt (line 1)) (11.0.1) Requirement already satisfied: prompt-toolkit in /home/marietto/.local/lib/python3.10/site-packages (from EdgeGPT==0.0.60->-r requirements.txt (line 1)) (3.0.38) Requirement already satisfied: httpx in /home/marietto/.local/lib/python3.10/site-packages (from EdgeGPT==0.0.60->-r requirements.txt (line 1)) (0.23.3) Requirement already satisfied: certifi in /home/marietto/.local/lib/python3.10/site-packages (from EdgeGPT==0.0.60->-r requirements.txt (line 1)) (2022.12.7) Requirement already satisfied: asyncio in /home/marietto/.local/lib/python3.10/site-packages (from EdgeGPT==0.0.60->-r requirements.txt (line 1)) (3.4.3) Requirement already satisfied: itsdangerous>=2.0 in /home/marietto/.local/lib/python3.10/site-packages (from Flask==2.2.3->-r requirements.txt (line 2)) (2.1.2) Requirement already satisfied: Jinja2>=3.0 in /home/marietto/.local/lib/python3.10/site-packages (from Flask==2.2.3->-r requirements.txt (line 2)) (3.1.2) Requirement already satisfied: Werkzeug>=2.2.2 in /home/marietto/.local/lib/python3.10/site-packages (from Flask==2.2.3->-r requirements.txt (line 2)) (2.2.3) Requirement already satisfied: click>=8.0 in /home/marietto/.local/lib/python3.10/site-packages (from Flask==2.2.3->-r requirements.txt (line 2)) (8.1.3) Requirement already satisfied: MarkupSafe>=2.0 in /home/marietto/.local/lib/python3.10/site-packages (from Jinja2>=3.0->Flask==2.2.3->-r requirements.txt (line 2)) (2.1.2) Requirement already satisfied: sniffio in /home/marietto/.local/lib/python3.10/site-packages (from httpx->EdgeGPT==0.0.60->-r requirements.txt (line 1)) (1.3.0) Requirement already satisfied: rfc3986[idna2008]<2,>=1.3 in /home/marietto/.local/lib/python3.10/site-packages (from httpx->EdgeGPT==0.0.60->-r requirements.txt (line 1)) (1.5.0) Requirement already satisfied: httpcore<0.17.0,>=0.15.0 in /home/marietto/.local/lib/python3.10/site-packages (from httpx->EdgeGPT==0.0.60->-r requirements.txt (line 1)) (0.16.3) Requirement already satisfied: wcwidth in /home/marietto/.local/lib/python3.10/site-packages (from prompt-toolkit->EdgeGPT==0.0.60->-r requirements.txt (line 1)) (0.2.6) Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /home/marietto/.local/lib/python3.10/site-packages (from rich->EdgeGPT==0.0.60->-r requirements.txt (line 1)) (2.14.0) Requirement already satisfied: markdown-it-py<3.0.0,>=2.2.0 in /home/marietto/.local/lib/python3.10/site-packages (from rich->EdgeGPT==0.0.60->-r requirements.txt (line 1)) (2.2.0) Requirement already satisfied: h11<0.15,>=0.13 in /home/marietto/.local/lib/python3.10/site-packages (from httpcore<0.17.0,>=0.15.0->httpx->EdgeGPT==0.0.60->-r requirements.txt (line 1)) (0.14.0) Requirement already satisfied: anyio<5.0,>=3.0 in /home/marietto/.local/lib/python3.10/site-packages (from httpcore<0.17.0,>=0.15.0->httpx->EdgeGPT==0.0.60->-r requirements.txt (line 1)) (3.6.2) Requirement already satisfied: mdurl~=0.1 in /home/marietto/.local/lib/python3.10/site-packages (from markdown-it-py<3.0.0,>=2.2.0->rich->EdgeGPT==0.0.60->-r requirements.txt (line 1)) (0.1.2) Requirement already satisfied: idna in /home/marietto/.local/lib/python3.10/site-packages (from rfc3986[idna2008]<2,>=1.3->httpx->EdgeGPT==0.0.60->-r requirements.txt (line 1)) (3.4)
server.py

from flask import Flask, request, jsonify
import json
import sys
import asyncio
import random
from EdgeGPT import Chatbot, ConversationStyle
import threading
cookies = None
import time

with open('./cookies.json', 'r') as f:
    cookies = json.load(f)

app = Flask(__name__)

responses_final_list = {}

def generate_code():
    code = ""
    for i in range(2):
        code += str(random.randint(0, 9))
    return str(code)


@app.route('/res/<codes>', methods=['GET'])
def lidar_com_resposta(codes):
    codes = codes.replace("%20","").replace(" ", "")
    print("Password: " + str(codes))
    if codes in responses_final_list:
        return responses_final_list[codes]
    else:
        time.sleep(6)
        if codes in responses_final_list:
            return responses_final_list[codes]
        else:
            return "Invalid code, try again in 1 minute."


async def ask_stream_task(question, codes):
    wrote = 0
    finished = False
    bot = Chatbot(cookies=cookies)
    response_list = []
    while not finished:
        async for final, response in bot.ask_stream(prompt=question, conversation_style=ConversationStyle.creative):
            if not final:
                response_list.append(response[wrote:])
                wrote = len(response)
                sys.stdout.flush()
            else:
                response_list.clear()
                response_list.append(response["item"]["messages"][-1]["text"])
                responses_final_list[str(codes)] = response["item"]["messages"][-1]["text"]
                finished = True
                print("Finished: " + str(codes))

def between_callback(prompt, codes):
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)

    loop.run_until_complete(ask_stream_task(prompt, codes))
    loop.close()

@app.route("/api")
async def api():
    prompt = request.args.get("prompt")
    timeout = 6
    codes = generate_code()
    asyncio.create_task(ask_stream_task(prompt, codes))
    _thread = threading.Thread(target=between_callback, args=(prompt, codes))
    _thread.start()
    return codes

if __name__ == "__main__":
    app.run(port=8080)
Reply
#2
It seems like the Flask app is not able to find the URL you are requesting, which leads to a 404 error. There could be several reasons why this is happening. Here are a few things you can try to debug the issue:

1. Check if the server is running: First, make sure that the server is running by running the command python server.py and checking the output. If you see the message "Running on http://127.0.0.1:8080", it means that the server is up and running.

2. Check if the cookies are correct: Double-check the contents of the cookies.json file and make sure that it contains the correct cookies for your Bing chat session. One way to do this is to open the chat in your browser and check the cookies manually.

3. Check if the URL is correct: Make sure that you are requesting the correct URL. In the tutorial, the URL is http://localhost:8080, but you mentioned that you are using 127.0.0.1:8080 and 192.168.1.2. Try using the original URL mentioned in the tutorial and see if that works.

4. Try a different browser: If the above steps don't work, try accessing the URL in a different browser. Some browsers may have security settings that prevent the cookies from being passed to the Flask app.

5. Check if the ports are open: Make sure that the ports used by the server are open and accessible from your machine. You can use a tool like nmap to check if the port is open. For example, if you are using port 8080, run the command nmap -p 8080 localhost to check if the port is open.

6. Check if the Flask app is serving on the correct port: Make sure that the Flask app is serving on the correct port. You can specify the port number by adding the port parameter to the app.run() method. For example, to serve on port 8080, use app.run(port=8080).

Hope these steps help you debug the issue.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  disable subprocess.popen prompt echo paul18fr 1 2,031 Feb-04-2021, 02:50 AM
Last Post: Larz60+
  how to set echo ON in Python call to Oracle SQL nmrt 4 3,765 Sep-21-2019, 05:40 AM
Last Post: nmrt
  Echo call to VLC bash using subprocess.Popen on Linux LuukS001 17 9,729 Jan-07-2019, 03:58 AM
Last Post: LuukS001

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020