Strvm / meta-ai-api

Llama 3 API (MetaAI Reverse Engineered)
236 stars 43 forks source link

Invalid json respones? #4

Closed niknak6 closed 5 months ago

niknak6 commented 5 months ago

Seem to be getting invalid json responses/html responses instead of json, intended?

Strvm commented 5 months ago

Hi, the python method will return a python dictionary (which could be converted into JSON). Could I see the code you are using?

Thanks!

niknak6 commented 5 months ago

I'm likely not handling the response correctly.

I attempted to just make a super simple Redbot based Discord bot as a proof of concept, using the command !meta [query]:

from redbot.core import commands
from meta_ai_api import MetaAI

class MetaBot(commands.Cog):

    def __init__(self, bot):
        self.bot = bot
        self.ai = MetaAI()

    @commands.command()
    async def meta(self, ctx, *, query: str):
        """Send a query to Meta AI and get a response."""
        try:
            response = self.ai.prompt(message=query)
            if response:
                await ctx.send(response['message'])
                if 'sources' in response:
                    sources = '\n'.join([f"[{src['title']}]({src['link']})" for src in response['sources']])
                    await ctx.send(f"**Sources:**\n{sources}")
            else:
                await ctx.send("No response received from Meta AI.")
        except Exception as e:
            await ctx.send(f"Error occurred: {str(e)}")
Strvm commented 5 months ago

I was able to get sources using similar code to yours:

response = ai.prompt(message="Whats the weather in San Francisco today? And what is the date?", stream=False)
sources = '\n'.join([f"[{src['title']}]({src['link']})" for src in response['sources']])
print(sources)
[WolframAlpha](https://www.wolframalpha.com/input?i=San+Francisco+weather+today+and+date)
[San Francisco 14 Day Extended Forecast - Weather - Time and Date](https://www.timeanddate.com/weather/usa/san-francisco/ext)
[Hourly forecast for San Francisco, California, USA - Time and Date](https://www.timeanddate.com/weather/usa/san-francisco/hourly)
[Past Weather in San Francisco, California, USA - Time and Date](https://www.timeanddate.com/weather/usa/san-francisco/historic)
[Weather for San Francisco, California, USA - Time and Date](https://www.timeanddate.com/weather/usa/san-francisco)

Not sure what seems to be the issue on your side, do you get an error?

niknak6 commented 5 months ago

Thanks for trying to help, I figured it was just a novice mistake somewhere along the way. Error:

File "{HOME}/redenv/lib/python3.11/site-packages/requests/models.py", line 975, in json raise RequestsJSONDecodeError(e.msg, e.doc, e.pos) requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)