Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web search not working. #187

Closed
FBRDCYB3R opened this issue Mar 7, 2024 · 7 comments
Closed

Web search not working. #187

FBRDCYB3R opened this issue Mar 7, 2024 · 7 comments
Labels
bug bug!

Comments

@FBRDCYB3R
Copy link

I am using the outline provided in the readme, and I am able to access the site but its not able to search the web. When I ask it "todays news" it defaults to the date of August 13, 2023 and nor am I able to switch llm, it keeps defaulting to Mistral Ai, even when I specify
`chatbot.switch_llm(1) # Switch to the second model

Get information about the current conversation

#info = chatbot.get_conversation_info()
#print(info.id, info.title, info.model, info.system_prompt, info.history)

Assistant

assistant = chatbot.search_assistant(assistant_name="ChatGpt") # assistant name list in https://huggingface.co/chat/assistants
assistant_list = chatbot.get_assistant_list_by_page(page=0)
chatbot.new_conversation(assistant=assistant, switch_to=True) # create a new conversation with assistant

`
and here is my version of the code I changed up a bit:

`from hugchat import hugchat
from hugchat.login import Login

Log in to huggingface and grant authorization to huggingchat

EMAIL = "[email protected]"
PASSWD = "Wordpass197900"
cookie_path_dir = "./cookies"
sign = Login(EMAIL, PASSWD)
cookies = sign.login(cookie_dir_path=cookie_path_dir, save_cookies=True)

Create your ChatBot

chatbot = hugchat.ChatBot(cookies=cookies.get_dict())

Function to get user input for query

def get_user_query():
query = input("Enter your query: ")
return query

Main loop

while True:
user_query = get_user_query()
if user_query.lower() == "quit":
break

# Non-stream response
query_result = chatbot.chat(user_query)
print(query_result)

# Stream response
print("Streaming response:")
response_text = ""
for resp in chatbot.query(user_query, stream=True):
    if resp.get("type") == "stream" and resp.get("token"):
        response_text += resp["token"]
print(response_text)
chatbot.switch_llm(1) # Switch to the second model

Get information about the current conversation

#info = chatbot.get_conversation_info()
#print(info.id, info.title, info.model, info.system_prompt, info.history)

Assistant

assistant = chatbot.search_assistant(assistant_name="ChatGpt") # assistant name list in https://huggingface.co/chat/assistants
assistant_list = chatbot.get_assistant_list_by_page(page=0)
chatbot.new_conversation(assistant=assistant, switch_to=True) # create a new conversation with assistant

# Web search (new feature)
query_result = chatbot.query(user_query, web_search=True)
print("\nWeb search results:")
for source in query_result.web_search_sources:
    print(f"Link: {source.link}")
    print(f"Title: {source.title}")
    print(f"Hostname: {source.hostname}")
    print()

`

@FBRDCYB3R FBRDCYB3R added the bug bug! label Mar 7, 2024
@reflectored
Copy link
Contributor

I also have different problems with web_search. Here's the info about the version of hugchat:

pip show hugchat
Name: hugchat
Version: 0.4.1
Summary: A huggingchat python api.
Home-page: https://github.com/Soulter/hugging-chat-api
Author: Soulter
Author-email: [email protected]
License: GNU Affero General Public License v3.0
Location: /home/folder/lib/python3.11/site-packages
Requires: requests, requests-toolbelt
Required-by:

I have tried the following prompt first with web_search disabled:

>>> result = chatbot.chat('Hi, tell me a joke', web_search=False)
>>> print(result)
DEBUG:root:conversation 6616a49674912884dc720453 last message id: f5e42a5b-ad89-4f98-9e2a-71e915c0a731
DEBUG:urllib3.connectionpool:https://huggingface.co:443 "POST /chat/conversation/6616a49674912884dc720453 HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:Resetting dropped connection: huggingface.co
DEBUG:urllib3.connectionpool:https://huggingface.co:443 "POST /chat/conversation/6616a49674912884dc720453/__data.json HTTP/1.1" 200 None
DEBUG:root:conversation 6616a49674912884dc720453 history: [MessageNode(id='f5e42a5b-ad89-4f98-9e2a-71e915c0a731', role='system', content='', created_at=1712752758.921, updated_at=1712752758.921), MessageNode(id='a61bca8c-75f4-473e-a2c6-4a08c344125e', role='user', content='Hi, tell me a joke', created_at=1712752767.43, updated_at=1712752767.43), MessageNode(id='c1975a27-f77e-4291-bf53-3ac141099d6c', role='assistant', content=" Sure! Here's one:\n\nWhy don't scientists trust atoms?\n\nBecause they make up everything!\n\nI hope you found that amusing. Let me know if there is anything else I can help with.", created_at=1712752767.43, updated_at=1712752777.168)]
 Sure! Here's one:

Why don't scientists trust atoms?

Because they make up everything!

I hope you found that amusing. Let me know if there is anything else I can help with.

With web_search enabled:

>>> result = chatbot.chat('Find me a joke about boeing', web_sear
ch=True)
>>> print(result)
DEBUG:root:conversation 6616a49674912884dc720453 last message id: c44b1e12-78a6-4cf6-ba9b-640295d6a006
DEBUG:urllib3.connectionpool:https://huggingface.co:443 "POST /chat/conversation/6616a49674912884dc720453 HTTP/1.1" 200 None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/folder/lib/python3.11/site-packages/hugchat/message.py", line 224, in __str__
    return self.wait_until_done()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/folder/lib/python3.11/site-packages/hugchat/message.py", line 194, in wait_until_done
    self.__next__()
  File "/home/folder/lib/python3.11/site-packages/hugchat/message.py", line 149, in __next__
    raise self.error
  File "/home/folder/lib/python3.11/site-packages/hugchat/message.py", line 141, in __next__
    return self.__next__()
           ^^^^^^^^^^^^^^^
  File "/home/folder/lib/python3.11/site-packages/hugchat/message.py", line 149, in __next__
    raise self.error
  File "/home/folder/lib/python3.11/site-packages/hugchat/message.py", line 141, in __next__
    return self.__next__()
           ^^^^^^^^^^^^^^^
  File "/home/folder/lib/python3.11/site-packages/hugchat/message.py", line 149, in __next__
    raise self.error
  File "/home/folder/lib/python3.11/site-packages/hugchat/message.py", line 141, in __next__
    return self.__next__()
           ^^^^^^^^^^^^^^^
  File "/home/folder/lib/python3.11/site-packages/hugchat/message.py", line 149, in __next__
    raise self.error
  File "/home/folder/lib/python3.11/site-packages/hugchat/message.py", line 141, in __next__
    return self.__next__()
           ^^^^^^^^^^^^^^^
  File "/home/folder/lib/python3.11/site-packages/hugchat/message.py", line 94, in __next__
    raise self.error
hugchat.exceptions.ChatError: Failed to parse webpage
>>> ^D
Traceback (most recent call last):
  File "/home/folder/lib/python3.11/site-packages/hugchat/hugchat.py", line 780, in _stream_query
    yield obj
GeneratorExit
DEBUG:root:{'Content-Type': 'text/event-stream', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Date': 'Wed, 10 Apr 2024 14:42:07 GMT', 'set-cookie': 'hf-chat=e79c423b-c83e-4de7-a6e5-9eb4e875e82f; Path=/; Expires=Wed, 24 Apr 2024 14:42:07 GMT; HttpOnly; Secure; SameSite=None', 'x-proxied-host': 'http://10.29.19.50', 'x-proxied-path': '/chat/conversation/6616a49674912884dc720453', 'link': '<https://huggingface.co/spaces/huggingchat/chat-ui>;rel="canonical"', 'x-request-id': '2a_IgQ', 'access-control-allow-origin': 'https://huggingface.co', 'access-control-allow-credentials': 'true', 'vary': 'origin, access-control-request-method, access-control-request-headers', 'X-Cache': 'Miss from cloudfront', 'Via': '1.1 461f986b60f99dda319d2b87307b2082.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'TXL50-P6', 'X-Amz-Cf-Id': '4WUZ4zrquw8BELevnyLWOGUj6I9K2-orxE3ZB0iT7NPMAB2hYQbpZQ=='}
Exception ignored in: <generator object ChatBot._stream_query at 0x7f5a73433870>
Traceback (most recent call last):
  File "/home/folder/lib/python3.11/site-packages/hugchat/hugchat.py", line 790, in _stream_query
hugchat.exceptions.ChatError: Failed to parse response: {"type":"webSearch","messageType":"error","message":"Failed to parse webpage","args":["webpage doesn't have any parseable element","https://www.reddit.com/r/Jokes/comments/1bfzou7/a_group_of_boeing_employees_are_sitting_on_a/"]}

@reflectored
Copy link
Contributor

@Soulter if nobody works on this I can give it a try.

@cakemooner
Copy link

@reflectored Please look into. I have the same issue as you do.

@Soulter
Copy link
Owner

Soulter commented Apr 11, 2024

@Soulter if nobody works on this I can give it a try.

hi, I've been a little bit busy recently so I didn't pay much attention to this issue timely, I'd appreciate it if you can work on this

@cakemooner
Copy link

When Web Search tries multiple sites and encounters one or more "Failed to parse webpage" errors, it should ignore the error and carry on to try next site. However currently the error is caught and raised. That's why it crashes out.

@reflectored
Copy link
Contributor

@cakemooner @Soulter Fixed it, did some refactoring as well #193.

@Soulter
Copy link
Owner

Soulter commented Apr 12, 2024

I published a new version v0.4.2 that fixed the bug. Thanks @reflectored

@Soulter Soulter closed this as completed Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bug!
Projects
None yet
Development

No branches or pull requests

4 participants