Giter VIP home page Giter VIP logo

hugging-chat-api's Introduction

hugging-chat-api

English | 简体中文

Unofficial HuggingChat Python API, extensible for chatbots etc.

PyPi Support_Platform DownloadsPW Status Downloads

Note

Some recent versions may no longer be fully backward compatible to some extent, a good idea is to review this README or issues promptly after any problem arise. Custom parameters(temprature, max_token, etc) is no longer supported

Recently new updates:

  • Assistant(Image Generator, etc)
  • Web search
  • Memorize context
  • Supports for changing LLMs

Installation

pip3 install hugchat

Usage

API

The following are all common usages of this repo, You may not necessarily use all of them, You can add or delete some as needed :)

from hugchat import hugchat
from hugchat.login import Login

# Log in to huggingface and grant authorization to huggingchat
EMAIL = "your email"
PASSWD = "your password"
cookie_path_dir = "./cookies/" # NOTE: trailing slash (/) is required to avoid errors
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())  # or cookie_path="usercookies/<email>.json"

# Non stream response
query_result = chatbot.chat("Hi!")
print(query_result) # or query_result.text or query_result["text"]

# Stream response
for resp in chatbot.query(
    "Hello",
    stream=True
):
    print(resp)

# Web search (new feature)
query_result = chatbot.query("Hi!", web_search=True)
print(query_result)
for source in query_result.web_search_sources:
    print(source.link)
    print(source.title)
    print(source.hostname)

# Create a new conversation
chatbot.new_conversation(switch_to = True) # switch to the new conversation

# Get conversations on the server that are not from the current session (all your conversations in huggingchat)
conversation_list = chatbot.get_remote_conversations(replace_conversation_list=True)
# Get conversation list(local)
conversation_list = chatbot.get_conversation_list()

# Get the available models (not hardcore)
models = chatbot.get_available_llm_models()

# Switch model with given index
chatbot.switch_llm(0) # Switch to the first model
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

# [DANGER] Delete all the conversations for the logged in user
chatbot.delete_all_conversations()

The query() function receives these parameters:

  • text: Required[str].
  • retry_count: Optional[int]. Number of retries for requesting huggingchat. Default is 5
  • web_search : Optional[bool]. Whether to use online search.

CLI

version 0.0.5.2 or newer

Simply run the following command in your terminal to start the CLI mode

python -m hugchat.cli

CLI params:

  • -u <your huggingface email> : Provide account email to login.
  • -p : Force request password to login, ignores saved cookies.
  • -s : Enable streaming mode output in CLI.
  • -c : Continue previous conversation in 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.

  • /delete-all : Deletes all the conversations for the logged in user.

  • /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.

  • /stream <on|off>: streaming the response.

  • /web <on|off>: web search.

  • /web-hint <on|off>: display web search hint.

  • 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

Star History Chart

hugging-chat-api's People

Contributors

soulter avatar whitelisted1 avatar rockchinq avatar zekaroni avatar ogios avatar akhil3417 avatar daniensi avatar fshabashev avatar xsa-dev avatar exy02 avatar ibndias avatar hansfzlorenzana avatar failurepoint avatar sjrl avatar muzammilpervaiz avatar louiscklaw avatar sumandora avatar everypizza1 avatar anzarwani avatar reflectored avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.