juzeon / SydneyQt

A cross-platform desktop client for the jailbroken New Bing AI Copilot (Sydney ver.) built with Go and Wails (previously based on Python and Qt).
The Unlicense
816 stars 76 forks source link

[FEATURE] Can you please add the generate image feature in the v1 SydneyQt? Thanks!! #186

Closed JayGarland closed 7 months ago

JayGarland commented 7 months ago

Checks

Is your feature request related to a problem? Please describe.

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] I want to have the image create feature as well in v1 sydneyqt

Describe the solution you'd like

A clear and concise description of what you want to happen. I want to have the image create feature as well in v1 sydneyqt

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context or screenshots about the feature request here.

here are some codes I previously wrote but still strugling in implementing it.

from main.py:

elif msg_type == "GenerateContentQuery":
                            if message['contentType'] == 'IMAGE':
                                replied = True
                                #todo needs approve
                                # try:
                                # image = sydney.GenerateImageResult()
                                url = "https://www.bing.com/images/create?" + urllib.parse.urlencode({
                                    "partner": "sydney",
                                    "re": "1",
                                    "showselective": "1",
                                    "sude": "1",
                                    "kseed": "8500",
                                    "SFX": "4",
                                    "q": urllib.parse.quote(message["text"]),  # Ensure proper URL encoding
                                    "iframeid": message["messageId"],
                                })
                                generative_image = sydney.GenerativeImage(message["text"], url)
                                image = await sydney.generate_image(proxy, generative_image, cookies)

from sydney.py:


_HEADERS_INIT_CREATIMG = {
    "authority":                 "www.bing.com",
    "accept":                    "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
    "accept-language":           "en-US,en;q=0.9",
    "cache-control":             "no-cache",
    "referer":                   "https://www.bing.com/search?q=Bing+AI&showconv=1",
    "upgrade-insecure-requests": "1",
    "user-agent":                "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1722.46",
    "x-forwarded-for":           _FORWARDED_IP,
    "Sec-Fetch-Dest":            "iframe",
}

@dataclass
class GenerativeImage:
    text: str
    url: str

@dataclass
class GenerateImageResult:
    generative_image: GenerativeImage
    image_urls: list[str]
    # duration: float  # Representing time.Duration in Python

import re
import asyncio
async def generate_image(
    proxy: str | None = _PROXY,
    generative_image: GenerativeImage | None = None,
    cookies: list[dict] | None = None,
) -> (GenerateImageResult, Exception | None):

    formatted_cookies = {}
    if cookies:
        for cookie in cookies:
            formatted_cookies[cookie["name"]] = cookie["value"]

    async with aiohttp.ClientSession(
        headers=_HEADERS_INIT_CREATIMG, cookies=formatted_cookies
    ) as session:
        try:
            async with session.get(generative_image.url, proxy=proxy) as resp:
                resp.raise_for_status()
                text = await resp.text()

                # Extract result ID
                matches = re.findall(
                    r"/images/create/async/results/(.*?)\?", text
                )
                if not matches or len(matches) < 2:
                    return None, Exception("Cannot find image creation result")
                result_id = matches[1]

                # Await image creation
                result_url = f"https://www.bing.com/images/create/async/results/{result_id}?q={urllib.parse.quote(generative_image.text)}&partner=sydney&showselective=1&IID=images.as"
                for _ in range(15):
                    await asyncio.sleep(3)
                    async with session.get(result_url, proxy=proxy) as result_resp:
                        result_resp.raise_for_status()
                        text = await result_resp.text()

                        # Check for rejection
                        if "Please try again or come back later" in text:
                            return None, Exception("Prompt rejected by Bing")

                        # Extract image URLs
                        image_urls = re.findall(r'<img class="mimg".*?src="(.*?)"', text)
                        if image_urls:
                            return GenerateImageResult(
                                generate_image=generative_image,
                                image_urls=image_urls,
                            ), None

        except aiohttp.ClientError as err:
            return None, err

    return None, Exception("Image creation timeout")
juzeon commented 7 months ago

v1 is no longer maintained.