vsakkas / sydney.py

Python Client for Copilot (formerly named Bing Chat), also known as Sydney.
MIT License
239 stars 31 forks source link

Is it possible to grab the "block code" automatically? #134

Closed RexsyBima closed 6 months ago

RexsyBima commented 6 months ago

is it possible to get the value of the block code only? for an exampl, its the json data generated from my prompt

image

altho i can do it manually, my prompt is

async def get_newsletter(url):
    async with SydneyClient(style="balanced") as sydney:
        return await sydney.ask("i want your answer to be started ONLY with ""here is the answer : and then ended the final sentence with NOTHING"f". go to this url ONLY {url} and write me a unique newsletter that differs from other sources about it. make sure it retains its accuracy to information. then followed by some formatting, and only formatted in JSON with keys of the title, the newsletter, and the citation.", context=url, raw=True)        

and then

response = asyncio.run(get_newsletter(url))
data = data.replace("Here is the answer:\n\n```json\n", "").replace("```", "").replace("\n", "")
output = ast.literal_eval(data)

unfortunately this workaround is not consistent, sometimes its not working because Bing answer the question in different way

vsakkas commented 6 months ago

Hi @RexsyBima

I don't think the API provides an obvious way to force Bing Chat to output only code, but there a few things that you could try:

The last tip could become a parameter in Sydney it self, but first I will need to check if it's consistent. That being said, I think it's worth trying it as, it should give you better results that using replace.

RexsyBima commented 6 months ago

ah got it, i think by found the consistent solution by adjusting the prompt to be more straightforward and using precise mode. Thanks!!