Soulter / hugging-chat-api

HuggingChat Python API🤗
GNU Affero General Public License v3.0
859 stars 123 forks source link

Not able to trigger URL Fetcher with Cohere Model anymore #252

Closed nugen closed 3 months ago

nugen commented 3 months ago

We use Hugchat with the cohere model and the URL fetcher tool. We were able to run queries using tool URL fetcher and retrieve used urls with tools_used. But recently this is broken: tools_used no longer contains anything. When looking at the Hugging Face chat interface, no Call tool url fetcher is mentioned. However, if we create a new chat directly in the Hugging Face interface with exactly the same system and user prompt, the call to the URL Fetcher tool is triggered correctly, and leads to a correct answer.

To Reproduce 1/ Use Hugchat library to query Cohere Model passing (an) url(s) to retrieve an answer and fetched Url(s) No urls are fetched and the answer clearly shows that the url were not used. 2/ Use huggingface chat directly (manually), set the system prompt for the cohere model same as the one used in point 1/. And ask the same question. This time the call to the URL Fetcher tool is triggered correctly, and leads to a correct answer Here's our test code in python :

def test():
      user_prompt = "Can you tell me when Paul McCartney will play in Argentina ?"+"\ncall tool URL Fetcher :\nhttps://www.paulmccartney.com/news/paul-announces-2024-dates-for-the-got-back-tour\n\n"
      sysprompt = "Use the url provided by the user to give the correct answer"
      chatbot = hugchat.ChatBot(cookie_path='./cookies_snapshot/xxxxxxxx.json', system_prompt=sysprompt, default_llm=CHATMODEL)
      query_result = chatbot.chat(user_prompt, web_search=True) #Or chatbot.chat(user_input,) 
      fetched = query_result.tools_used

      return {"answer": query_result.text,  "fetched": fetched}

Expected behavior We should be able to trigger URL fetch Tool via Hugchat query call.

Screenshot of our code result

Ourcoderesult

Screenshot of huggingface/chat of the conversation created with Hugchat and our code

UsingHugchat

The answer is not from the provided URL. And no tool are mentionned.

Screenshot of huggingface/chat of the conversation created manually with same prompts

Manually

The answer is taken from the provided URL. And the URL fetched tool is mentionned.

Additional context Python 3.9 The issue happens in both Hugchat 0.4.10 and 0.4.8

Thanks for your coool work !

github-actions[bot] commented 3 months ago

Hi! Thanks for your issue, we will deal with your issue as soon as possible.

nugen commented 3 months ago

Hi !

I've been able to make it work again editing hugchat.py at Line 682 in order to set tools value (hardcoded for testing):

 req_json = {
            "id": message_id,
            "inputs": text,
            "is_continue": False,
            "is_retry": is_retry,
            "web_search": web_search,
            "tools": {"fetch_url": True,"websearch": False}

Maybe adding a tools parameter to the chat method could help choosing the tools ?