Skip to content

Commit

Permalink
Revert "Cleanup unused dependencies"
Browse files Browse the repository at this point in the history
This reverts commit c211530.
  • Loading branch information
hlohaus committed Jan 23, 2024
1 parent 55695ed commit 6614dfe
Show file tree
Hide file tree
Showing 6 changed files with 6,989 additions and 17 deletions.
33 changes: 16 additions & 17 deletions g4f/Provider/GptForLove.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
from __future__ import annotations

from aiohttp import ClientSession
import json
from Crypto.Cipher import AES
from Crypto.Util import Padding
import base64
import hashlib
import time
import math
import execjs, os, json

from ..typing import AsyncResult, Messages
from .base_provider import AsyncGeneratorProvider
Expand Down Expand Up @@ -71,13 +65,18 @@ async def create_async_generator(


def get_secret() -> str:
k = '14487141bvirvvG'

This comment has been minimized.

Copy link
@Akash98Sky

Akash98Sky Jan 26, 2024

Contributor

Just the encryption key needs to be updated here.

e = math.floor(time.time())

plaintext = str(e).encode('utf-8')
key = hashlib.md5(k.encode('utf-8')).digest()

cipher = AES.new(key, AES.MODE_ECB)
ciphertext = cipher.encrypt(Padding.pad(plaintext, AES.block_size, style='pkcs7'))

return base64.b64encode(ciphertext).decode()
dir = os.path.dirname(__file__)
include = f'{dir}/npm/node_modules/crypto-js/crypto-js'
source = """
CryptoJS = require({include})
var k = 'fjfsdwiuhfwf'
, e = Math.floor(new Date().getTime() / 1e3);
var t = CryptoJS.enc.Utf8.parse(e)
, o = CryptoJS.AES.encrypt(t, k, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return o.toString()
"""
source = source.replace('{include}', json.dumps(include))
return execjs.compile(source).call('')
12 changes: 12 additions & 0 deletions g4f/Provider/npm/node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

275 changes: 275 additions & 0 deletions g4f/Provider/npm/node_modules/crypto-js/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

1 comment on commit 6614dfe

@Akash98Sky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any specific reason behind including JavaScript here? The Python code exactly does the same.

Please sign in to comment.