{"id":13456479,"url":"https://github.com/Soulter/hugging-chat-api","last_synced_at":"2025-03-24T10:32:41.805Z","repository":{"id":157012890,"uuid":"633251831","full_name":"Soulter/hugging-chat-api","owner":"Soulter","description":"HuggingChat Python API🤗","archived":false,"fork":false,"pushed_at":"2025-01-22T06:40:20.000Z","size":414,"stargazers_count":915,"open_issues_count":18,"forks_count":130,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-20T06:07:38.702Z","etag":null,"topics":["ai","bot","chatbot","hugchat","huggingchat"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Soulter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-27T05:27:02.000Z","updated_at":"2025-03-19T03:30:23.000Z","dependencies_parsed_at":"2023-12-28T03:04:17.892Z","dependency_job_id":"6b80b113-0ca4-4203-997c-d27503fbd64b","html_url":"https://github.com/Soulter/hugging-chat-api","commit_stats":{"total_commits":331,"total_committers":26,"mean_commits":12.73076923076923,"dds":0.5619335347432024,"last_synced_commit":"9d4b86388bf3e65d285f23147c89efe56cbc2c99"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soulter%2Fhugging-chat-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soulter%2Fhugging-chat-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soulter%2Fhugging-chat-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soulter%2Fhugging-chat-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Soulter","download_url":"https://codeload.github.com/Soulter/hugging-chat-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245252495,"owners_count":20585077,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","bot","chatbot","hugchat","huggingchat"],"created_at":"2024-07-31T08:01:22.778Z","updated_at":"2025-03-24T10:32:41.799Z","avatar_url":"https://github.com/Soulter.png","language":"Python","funding_links":["https://www.buymeacoffee.com/soulter"],"categories":["Python"],"sub_categories":[],"readme":"# hugging-chat-api\n\nEnglish | [简体中文](README_cn.md)\n \nUnofficial HuggingChat Python API, extensible for chatbots etc. It supports:\n\n- Basic Chat\n- Assistant(Image Generator, [etc.](https://huggingface.co/chat/assistants))\n- Web search\n- Memorize context\n- [Switch LLMs](https://huggingface.co/chat/models)\n- ...\n\n[![PyPi](https://img.shields.io/pypi/v/hugchat.svg?logo=pypi\u0026logoColor=white)](https://pypi.python.org/pypi/hugchat)\n[![Support_Platform](https://img.shields.io/badge/3.6+-%234ea94b.svg?logo=python\u0026logoColor=white)](https://pypi.python.org/pypi/hugchat)\n[![DownloadsPW](https://img.shields.io/pypi/dw/hugchat?logo=download\u0026logoColor=white)](https://pypi.python.org/pypi/hugchat)\n[![Downloads](https://static.pepy.tech/badge/hugchat?logo=download\u0026logoColor=white)](https://www.pepy.tech/projects/hugchat)\n\n\u003e **Note**\n\u003e\n\u003e For the personal reasons, the update of this repo will become slow, and we will ensure that the most basic features can be used normally. Welcome Any PR!\n\n## Installation\n```bash\npip3 install hugchat\n```\n\n## Usage\n\n### API\n\n#### Minimal Example\n\n```py\nfrom hugchat import hugchat\nfrom hugchat.login import Login\n\n# Log in to huggingface and grant authorization to huggingchat\n# DO NOT EXPOSE YOUR EMAIL AND PASSWORD IN CODES, USE ENVIRONMENT VARIABLES OR CONFIG FILES\nEMAIL = \"your email\"\nPASSWD = \"your password\"\ncookie_path_dir = \"./cookies/\" # NOTE: trailing slash (/) is required to avoid errors\nsign = Login(EMAIL, PASSWD)\ncookies = sign.login(cookie_dir_path=cookie_path_dir, save_cookies=True)\n\nchatbot = hugchat.ChatBot(cookies=cookies.get_dict())\n\nprint(chatbot.chat(\"Hi!\").wait_until_done())\n```\n\n\nThe following are all common usages of this repo, You may not necessarily use all of them, You can add or delete some as needed :)\n\n\n```py\nfrom hugchat import hugchat\nfrom hugchat.login import Login\n\n# Log in to huggingface and grant authorization to huggingchat\nEMAIL = \"your email\"\nPASSWD = \"your password\"\ncookie_path_dir = \"./cookies/\" # NOTE: trailing slash (/) is required to avoid errors\nsign = Login(EMAIL, PASSWD)\ncookies = sign.login(cookie_dir_path=cookie_path_dir, save_cookies=True)\n\n# Create your ChatBot\nchatbot = hugchat.ChatBot(cookies=cookies.get_dict())  # or cookie_path=\"usercookies/\u003cemail\u003e.json\"\n\nmessage_result = chatbot.chat(\"Hi!\") # note: message_result is a generator, the method will return immediately.\n\n# Option 1: Non stream\nmessage_str: str = message_result.wait_until_done()\n# get files(such as images)\nfile_list = message_result.get_files_created() # must call wait_until_done() first!\n\n# Option 2: Stream response\nfor resp in chatbot.chat(\n    \"Hello\",\n    stream=True\n):\n    print(resp)\n\n# Web search\nquery_result = chatbot.chat(\"How many models stored in huggingface?\", web_search=True).wait_until_done()\nprint(query_result)\n# You can get the web search results from the query result\nfor source in query_result.get_search_sources():\n    print(source.link, source.title)\n\n# Create a new conversation\nchatbot.new_conversation(switch_to = True) # switch to the new conversation\n\n# Get conversations on the server that are not from the current session (all your conversations in huggingchat)\nconversation_list = chatbot.get_remote_conversations(replace_conversation_list=True)\n# Get conversation list(local)\nconversation_list = chatbot.get_conversation_list()\n\n# Get the available models\nmodels = chatbot.get_available_llm_models()\n# Switch model with given index\nchatbot.switch_llm(0) # Switch to the first model\nchatbot.switch_llm(1) # Switch to the second model\n\n# Get information about the current conversation\ninfo = chatbot.get_conversation_info()\nprint(info.id, info.title, info.model, info.system_prompt, info.history)\n\n# Assistant\nASSISTANT_ID = \"66017fca58d60bd7d5c5c26c\" # get the assistant id from https://huggingface.co/chat/assistants\nchatbot.new_conversation(assistant=ASSISTANT_ID, switch_to=True) # create a new conversation with assistant\n\n# [DANGER] Delete all the conversations for the logged in user\nchatbot.delete_all_conversations()\n```\n\n### CLI\n\nSimply run the following command in your terminal to start the CLI mode\n\n```bash\npython -m hugchat.cli\n```\n\nCLI params:\n\n- `-u \u003cyour huggingface email\u003e` : Provide account email to login.\n- `-p` : Force request password to login, ignores saved cookies.\n- `-s` : Enable streaming mode output in CLI.\n- `-c` : Continue previous conversation in CLI \".\n\nCommands in cli mode:\n\n- `/new` : Create and switch to a new conversation.\n- `/ids` : Shows a list of all ID numbers and ID strings in *current session*.\n- `/switch` : Shows a list of all conversations' info in *current session*. Then you can choose one to switch to.\n- `/switch all` : Shows a list of all conversations' info in *your account*. Then you can choose one to switch to. (not recommended if your account has a lot of conversations)\n- `/del \u003cindex\u003e` : Deletes the conversation linked with the index passed. Will not delete active session.\n- `/delete-all` : Deletes all the conversations for the logged in user.\n- `/clear` : Clear the terminal.\n- `/llm` : Get available models you can switch to.\n- `/llm \u003cindex\u003e` : Switches model to given model index based on `/llm`.\n- `/share` : Toggles settings for sharing data with model author. On by default.\n- `/exit` : Closes CLI environment.\n- `/stream` : Toggles streaming the response.\n- `/web` : Toggles web search.\n- `/web-hint` : Toggles display web search hint.\n\n- AI is an area of active research with known problems such as biased generation and misinformation. Do not use this application for high-stakes decisions or advice.\n- Server resources are precious, it is not recommended to request this API in a high frequency.\n\n## Donations\n❤\n\n\u003ca href=\"https://www.buymeacoffee.com/soulter\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/default-orange.png\" alt=\"Buy Me A Coffee\" height=\"28\" width=\"119\"\u003e\u003c/a\u003e\n\n## Disclaimers\n\nThis is not an official [Hugging Face](https://huggingface.co/) product. This is a **personal project** and is not affiliated with [Hugging Face](https://huggingface.co/) in any way. Don't sue us.\n\n## Star History\n\n[![Star History Chart](https://api.star-history.com/svg?repos=Soulter/hugging-chat-api\u0026type=Date)](https://star-history.com/#Soulter/hugging-chat-api\u0026Date)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSoulter%2Fhugging-chat-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSoulter%2Fhugging-chat-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSoulter%2Fhugging-chat-api/lists"}