A huggingchat python api.
Project description
hugging-chat-api
English | 简体中文
Unofficial HuggingChat Python API, extensible for chatbots etc.
Note
Recently new updates:
- Memorize context
- Change LLMs supported. See more at https://github.com/Soulter/hugging-chat-api/issues/56 (v0.0.9)
Installation
pip install hugchat
or
pip3 install hugchat
Usage
API
from hugchat import hugchat
from hugchat.login import Login
# Log in to huggingface and grant authorization to huggingchat
sign = Login(email, passwd)
cookies = sign.login()
# Save cookies to the local directory
cookie_path_dir = "./cookies_snapshot"
sign.saveCookiesToDir(cookie_path_dir)
# Load cookies when you restart your program:
# sign = login(email, None)
# cookies = sign.loadCookiesFromDir(cookie_path_dir) # This will detect if the JSON file exists, return cookies if it does and raise an Exception if it's not.
# Create a ChatBot
chatbot = hugchat.ChatBot(cookies=cookies.get_dict()) # or cookie_path="usercookies/<email>.json"
print(chatbot.query("Hi!")['text']) # non stream response
for resp in chatbot.query(
"Hello",
stream=True
):
print(resp) # stream response
# Create a new conversation
id = chatbot.new_conversation()
chatbot.change_conversation(id)
# Get conversation list
conversation_list = chatbot.get_conversation_list()
# Switch model (default: meta-llama/Llama-2-70b-chat-hf. )
chatbot.switch_llm(0) # Switch to `OpenAssistant/oasst-sft-6-llama-30b-xor`
chatbot.switch_llm(1) # Switch to `meta-llama/Llama-2-70b-chat-hf`
The query() function receives these parameters:
text: Required[str].temperature: Optional[float]. Default is 0.9top_p: Optional[float]. Default is 0.95repetition_penalty: Optional[float]. Default is 1.2top_k: Optional[int]. Default is 50truncate: Optional[int]. Default is 1024watermark: Optional[bool]. Default is Falsemax_new_tokens: Optional[int]. Default is 1024stop: Optional[list]. Default is ["</s>"]return_full_text: Optional[bool]. Default is Falsestream: Optional[bool]. Default is Trueuse_cache: Optional[bool]. Default is Falseis_retry: Optional[bool]. Default is Falseretry_count: Optional[int]. Number of retries for requesting huggingchat. Default is 5
CLI
version 0.0.5.2or newer
Simply run the following command in your terminal to start the CLI mode
python -m hugchat.cli
Commands in cli mode:
-
/new: Create and switch to a new conversation. -
/ids: Shows a list of all ID numbers and ID strings in current session. -
/switch <id>: Switches to the ID number or ID string passed. -
/del <id>: Deletes the ID number or ID string passed. Will not delete active session. -
/clear: Clear the terminal. -
/llm: Get available models you can switch to. -
/llm <index>: Switches model to given model index based on/llm. -
/sharewithauthor <on|off>: Changes settings for sharing data with model author. On by default. -
/exit: Closes CLI environment. -
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.
-
Server resources are precious, it is not recommended to request this API in a high frequency. (
Hugging Face's CTO🤗just liked the suggestion)
Disclaimers
This is not an official Hugging Face product. This is a personal project and is not affiliated with Hugging Face in any way. Don't sue us.
Star History
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hugchat-0.2.9.tar.gz.
File metadata
- Download URL: hugchat-0.2.9.tar.gz
- Upload date:
- Size: 26.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea82cf4900f7e71fbd5a9ea7aadbac238f56e6179ea614da267f1f08c2fbbb82
|
|
| MD5 |
f16a53dede60de7d768a3598b255eba7
|
|
| BLAKE2b-256 |
226f1fbb5fb1b5fd77e04a9068c299a4760eca8db332f30df0e77d76e1945253
|
File details
Details for the file hugchat-0.2.9-py3-none-any.whl.
File metadata
- Download URL: hugchat-0.2.9-py3-none-any.whl
- Upload date:
- Size: 25.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4877a6e7ce1bdb3b3f826ea70dfdc8383b58950735fa32e0883a3b0fa3f36d74
|
|
| MD5 |
f2c10373200b4bb60607cae77d1186cf
|
|
| BLAKE2b-256 |
226d0c6ac5731cc3934791cbd6ac58e96f055cbf66ae10390750ecc7e0d800da
|