groq / groq-python

The official Python Library for the Groq API
Apache License 2.0
365 stars 25 forks source link

Pending tool call #110

Closed sus2790 closed 2 weeks ago

sus2790 commented 1 month ago

I often got a call_id pending tool call, it seems like it is missing :

{
    "tool_call": {
        "id": "pending",
        "type": "function",
        "function": {
            "name": "researches"
        },
        "parameters": {
            "query": "..."
        }
    }
}
</tool-use>

Python 3.12.5 & Groq 0.9.0 Pip List: pastebin Code: pastebin

sus2790 commented 2 weeks ago

any updates?

hozen-groq commented 2 weeks ago

@sus2790 Hi there! 👋 I suggest posting this in the #help channel of our developer community on Discord if the following suggestions don't help.

I'm wondering if the way you're parsing your function arguments is leading to an issue. You're passing **function_args to the function call, but it's a JSON string that needs to be parsed first. Try replacing with:

function_args = json.loads(tool_call.function.arguments)
function_response = await function_to_call(**function_args)

Also try modifying your _researches function to accept **kwargs:

async def _researches(**kwargs):
    query = kwargs.get('query')
    language = kwargs.get('language', 'zh-TW')
    try:
        result = await researches.asearch(query, hl=language)
        return orjson.dumps({"result": result}).decode("utf-8")
    except Exception as e:
        return orjson.dumps({"error": str(e)}).decode("utf-8")
sus2790 commented 2 weeks ago

I found a solution here that seems to have resolved my issue. However, I don’t think this is the best solution. Still, thank you for your help