Coder Social home page Coder Social logo

prsaw's Introduction

Hi there, I'm Swastik - aka Swas.py 👋

I'm a Student, Youtuber, and a Developer!!

  • 🔭 I’m currently working on vscode.py
  • 👯 I’m looking to collaborate with other content creators and developers!
  • 🥅 2024 Goals: Contribute to more Open Source projects!
  • ⚡ Fun fact: I am a verified bot developer on discord

Connect with me:

cws | YouTube cws | Twitter cws | Reddit

⚡ GitHub Stats
CodeWithSwastik's GitHub Stats

prsaw's People

Contributors

codewithswastik avatar dorukyum avatar falsedev avatar izxxr avatar null8626 avatar pgamerx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

prsaw's Issues

httpcore.ConnectTimeout error when using `async_mode`.

I'm getting the following error when I'm using the async_mode.

 File "/home/nerdguyahmad/.local/lib/python3.6/site-packages/httpcore/_async/connection.py", line 93, in arequest
    self.socket = await self._open_socket(timeout)
  File "/home/nerdguyahmad/.local/lib/python3.6/site-packages/httpcore/_async/connection.py", line 124, in _open_socket
    local_address=self.local_address,
  File "/home/nerdguyahmad/.local/lib/python3.6/site-packages/httpcore/_backends/auto.py", line 45, in open_tcp_stream
    hostname, port, ssl_context, timeout, local_address=local_address
  File "/home/nerdguyahmad/.local/lib/python3.6/site-packages/httpcore/_backends/asyncio.py", line 271, in open_tcp_stream
    stream_reader=stream_reader, stream_writer=stream_writer
  File "/usr/lib/python3.6/contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/nerdguyahmad/.local/lib/python3.6/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
    raise to_exc(exc) from None
httpcore.ConnectTimeout

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/nerdguyahmad/.local/lib/python3.6/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "main.py", line 255, in on_message
    response= await rs.get_ai_response(msg.content)
  File "/home/nerdguyahmad/.local/lib/python3.6/site-packages/apiclient/core.py", line 104, in async_call
    response = await self.session.send(httpx_request)
  File "/home/nerdguyahmad/.local/lib/python3.6/site-packages/httpx/_client.py", line 1411, in send
    history=[],
  File "/home/nerdguyahmad/.local/lib/python3.6/site-packages/httpx/_client.py", line 1448, in _send_handling_auth
    history=history,
  File "/home/nerdguyahmad/.local/lib/python3.6/site-packages/httpx/_client.py", line 1476, in _send_handling_redirects
    response = await self._send_single_request(request, timeout)
  File "/home/nerdguyahmad/.local/lib/python3.6/site-packages/httpx/_client.py", line 1507, in _send_single_request
    ext={"timeout": timeout.as_dict()},
  File "/usr/lib/python3.6/contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/nerdguyahmad/.local/lib/python3.6/site-packages/httpx/_exceptions.py", line 343, in map_exceptions
    raise mapped_exc(message, **kwargs) from exc  # type: ignore
httpx.ConnectTimeout
Future exception was never retrieved
future: <Future finished exception=gaierror(-3, 'Temporary failure in name resolution')>
Traceback (most recent call last):
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.6/socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

When I don't enable async_mode it only raises the socket.gaierror: [Errno -3] Temporary failure in name resolution error.

Add more jokes

Hey! I am using this bot, and its a great one. I just want you to add more jokes and stories. It would become better that way. Please do that as soon as u can, and u can also ping me, if there's a way by which I can add more jokes.

Thanks in advance

No module named 'prsaw'

I installed the plugin for my project in python, and the terminal says that there is no module called "prsaw"

Error:

C:\Users\zip\Desktop\AI_Chat>py ai_bot.py
Traceback (most recent call last):
File "C:\Users\zip\Desktop\AI_Chat\ai_bot.py", line 3, in
from prsaw import RandomStuff
ModuleNotFoundError: No module named 'prsaw'

Im getting some unusual errors

Traceback (most recent call last):
File "main.py", line 6, in
from prsaw import RandomStuff
File "C:\Users\ansh0\AppData\Local\Programs\Python\Python38-32\lib\site-packages\prsaw_init_.py", line 1, in
from .PRSAW import *
File "C:\Users\ansh0\AppData\Local\Programs\Python\Python38-32\lib\site-packages\prsaw\PRSAW.py", line 2, in
from apiclient import APIClient, APIRouter, Get, endpoint
ImportError: cannot import name 'APIClient' from 'apiclient' (C:\Users\ansh0\AppData\Local\Programs\Python\Python38-32\lib\site-packages\apiclient_init_.py)

I dont think this is an issue with my code

Custom Endpoints

PGamerX

I saw the code, you're using PGamerX's endpoints. He recently added ratelimits, as this is getting quite popular the chances that this would impact the module is huge.

Custom Endpoints

You could try and make your API which returns JSON using AI or however PGamerX did it.
For instance: https://codewithswastik.github.io/endpoints/api?message="e"

Doing this makes the module last without any worries.
Eventually you know you would have to do this, or go to some API where you can abuse ratelimits lmao.

I'm trying to make endpoints and I'm somewhere there.

Warning

It's great , however raising some "json decode errors" frequently , is most cases it's replying although raising error , and sometimes not replying.... is it any issue?

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) 

code:

from prsaw import RandomStuff


api_key = api_key
rs = RandomStuff(api_key = api_key)

response =  rs.get_ai_response("How are you?")
print(response)

rs.close()```

error:------------------------------------------------
```py
Ignoring exception in on_message
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "main.py", line 41, in on_message
    response = await client.get_ai_response(msg.content)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/randomstuff/client.py", line 554, in get_ai_response
    _check_status(response)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/randomstuff/_helper.py", line 33, in _check_status
    raise PlanNotAllowed(response.text)
randomstuff.errors.PlanNotAllowed: <bound method ClientResponse.text of <ClientResponse(https://api.pgamerx.com/v5//ai?message=how+are+you&server=main&uid=zcjZxFd4Z3C5UC4erGm6F77l2NmMBK&bot_name=Random+Stuff+API&bot_master=PGamerX&bot_gender=Male&bot_age=19&bot_company=PGamerX+Studio&bot_location=India&bot_email=admin@pgamerx.com&bot_build=Public&bot_birth_year=2002&bot_birth
Traceback (most recent call last):
  File "main.py", line 50, in <module>
    loop.run_until_complete(start())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
Traceback (most recent call last):
  File "main.py", line 125, in <module>
    response =  rs.get_ai_response("How are you?")
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/apiclient/core.py", line 95, in __call__
Traceback (most recent call last):
  File "main.py", line 125, in <module>
    response =  rs.get_ai_response("How are you?")
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/apiclient/core.py", line 95, in __call__
    return self.sync_call(httpx_request)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/apiclient/core.py", line 100, in sync_call
    response = post_processor(response)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/prsaw/PRSAW.py", line 25, in <lambda>
    self._post_processors.append(lambda res: res.json()) File "/opt/virtualenvs/python3/lib/python3.8/site-packages/httpx/_models.py", line 1116, in json
    return jsonlib.loads(self.text, **kwargs)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
 ```

Old method

from prsaw import RandomStuff
rs = RandomStuffV2()

During import at the first line there is NameError: name 'RandomStuffV2' is not defined.
That error is noticed on the page https://pypi.org/project/prsaw/

from prsaw import RandomStuffV2
rs = RandomStuffV2()

Unrelated answers

I programmed my AI bot using the PRSAW package and it used to work fine. But recently it's giving a lot of unrelated answers to questions.
For example :
Question: "How are you ?"
Answer from the bot: "What do you like to eat?"

Were there any recent updates to this wrapper? Or am I doing something wrong?

Kinda worried about this

image
If you send something random it sends something random back meaning it is possible for it to swear or say bad words etc.

Unrelated Answers

Hey!

I am using this API in my discord bot, and it answers with unrelated things. Idk what's the problem. I saw another issue, which didn't continue, so I opened mine. Here is the code to the same -->

@bot.listen('on_message')
async def ai(message):
	await bot.wait_until_ready()
	if message.author == bot.user:
		return
	channel = message.channel
	if message.channel.id != 835564299854020628:
		return
	if message.channel.id == 835564299854020628:
		reply = await bot.rs.get_ai_response(message)
		await message.channel.send(reply)

Ik it's all messed up (the spacing and stuff), but please bear with me. If u want, contact me on discord, would be much easier. Here is me USER ID --> нυηтєя#8785. Please ping me if anyone knows the solution to this!

Thanks!

'AsyncClient' object has no attribute 'close'

I used prsaw in my discord.py bot to have a chatbot kind of thing. U used it with the exact syntax in https://pypi.org/project/prsaw/
I used it with async_mode=True obviously because im doing it for a discord bot. That is when i discovered this error. In https://pypi.org/project/prsaw/ it says using rs.close() is recommended. This is the code im using

    @commands.command(aliases=["c", "talk"])
    @cooldown(1, 3, BucketType.user)
    async def chat(self, ctx, *, args : str = None):
        if args is None:
            return await ctx.send("To use the chatbot function, you need to specify a second argument. Try Again")
        rs = RandomStuff()
        response = rs.get_ai_response(args, lang='en')

        await ctx.send(response)
        try:
            rs.close()
        except Exception as e:
            return await ctx.send(e)

when i execute this command, it sends the response obviously because it is above but afterward throws the error in the title

Unexpected?

Literally copy pasted the code and tried to run it but got an unexpected error ew
<coroutine object RandomStuff.get_ai_response at 0x01FD3A68> test.py:11: RuntimeWarning: coroutine 'RandomStuff.close' was never awaited rs.close() RuntimeWarning: Enable tracemalloc to get the object allocation traceback sys:1: RuntimeWarning: coroutine 'RandomStuff.get_ai_response' was never awaited RuntimeWarning: Enable tracemalloc to get the object allocation traceback Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x0188E730>

Misc does not work!

response = await rs.get_ai_response(message.content.casefold(),dev_name="MetallicWeb7080",bot_name="Tancraft Network")
await message.reply(response[0]["message"], mention_author=False)
rs.close()
The misc for dev_name and bot_name is not working

keyerror

Traceback (most recent call last):
  File "main.py", line 7, in <module>
    response = rs.get_ai_response("How are you?")
  File "D:\Anaconda3\lib\site-packages\apiclient\core.py", line 95, in __call__
    return self.sync_call(httpx_request)
  File "D:\Anaconda3\lib\site-packages\apiclient\core.py", line 100, in sync_cal
l
    response = post_processor(response)
  File "D:\Anaconda3\lib\site-packages\prsaw\PRSAW.py", line 115, in _post_get_i
mage
    return res[0]
KeyError: 0

im getting the following error. why is that happening?

Session Can't Close on Async Mode

Hi! There's a big problem with prsaw that I already told False about.

You can't close the session when it is on async mode

Someone on help channels in TCA had this problem. I thought u had to just await it, but it's not like that since the function is not asynchronous. It gave this error:

'AsyncClient' object has no attribute 'close'

I did some research about this and...

I saw that the close function only applies to httpx.Client which is the default client used

But async mode uses httpx.AsyncClient which uses a coroutine named aclose to close the session

Please find a way to fix this problem, ty!

New Prsaw coding

Now we can't use old prsaw
Where can I get new prsaw coding
Plz help me

Upgrade to version 3

Kindly support version-3 of my API
I know it's not my duty to update you guys but thought you might be busy.
Within next 2 weeks Version 2 will be gone, reduced to atoms as I said last month that Version 4 will be end for version 2
So please

Not at all working

Code:

from prsaw import RandomStuffV2

rs = RandomStuffV2() 

response = rs.get_ai_response("How are you?")
print(response)

rs.close()

Error:

Traceback (most recent call last):
  File "main.py", line 8, in <module>
    response = rs.get_ai_response("How are you?")
  File "/home/runner/ChatBot/venv/lib/python3.8/site-packages/apiclient/core.py", line 95, in __call__
    return self.sync_call(httpx_request)
  File "/home/runner/ChatBot/venv/lib/python3.8/site-packages/apiclient/core.py", line 100, in sync_call
    response = post_processor(response)
  File "/home/runner/ChatBot/venv/lib/python3.8/site-packages/prsaw/PRSAW.py", line 115, in _post_get_image
    return res[0]
KeyError: 0

And yes i am using replit.com

Language issue

Hi, using this package and I can't get response on Russian or Hebrew (idk if there're other languages)

from prsaw import RandomStuff    


rs = RandomStuff(async_mode=True)


@commands.Cog.listener()
    async def on_message(self, message):
        if self.client.user == message.author:
            return
        post = {'_id':message.guild.id} 
        data = coll.find_one(post) # coll - MongoDataBase
        if data != None: #Checking if guild has specific channel
            if message.channel.id == data['id']: #If exists it tries to find channel with chatbot
                if message.content == f'{pref(self.client, message)}chatbotdel' or message.content == f'{pref(self.client, message)}chatbotset' or message.content == f'{pref(self.client, message)}chatbot': #Commands, that i can run in channel with chatbot
                    return await self.client.process_commands(message)
                response = await rs.get_ai_response(message.content) #Getting response
                await message.reply(response) #Sending response

                return
        else:
            await self.client.process_commands(message) #If not chatbot, its usual command

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.