Giter Site home page Giter Site logo

hugging-chat-api's Introduction

hugging-chat-api

English | 简体中文

HuggingChat Python API

PyPi Support_Platform Downloads

Leave a star :)

When you use this project, it means that you have agreed to the following two requirements of the HuggingChat:

  1. 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.
  2. Your conversations will be shared with model authors.

Server resources are precious, it is not recommended to request this API in a high frequency.

(Hugging Face's CTO🤗 just liked the suggestion)

Authentication (Required Now)

Get Cookies

from hugchat.login import Login

# login
sign = Login(email, passwd)
cookies = sign.login()
sign.saveCookies()

# load cookies from usercookies/<email>.json
sign = login(email, None)
cookies = sign.loadCookies() # This will detect if the JSON file exists, return cookies if it does and raise an Exception if it's not.

Usage

Basic mode

pip install hugchat
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 usercookies/<email>.json
sign.saveCookies()

# Create a ChatBot
chatbot = hugchat.ChatBot(cookies=cookies.get_dict())  # or cookie_path="usercookies/<email>.json"
print(chatbot.chat("HI"))

# Create a new conversation
id = chatbot.new_conversation()
chatbot.change_conversation(id)

# Get conversation list
conversation_list = chatbot.get_conversation_list()

The chat() function receives these parameters:

  • text: Required[str].
  • temperature: Optional[float]. Default is 0.9
  • top_p: Optional[float]. Default is 0.95
  • repetition_penalty: Optional[float]. Default is 1.2
  • top_k: Optional[int]. Default is 50
  • truncate: Optional[int]. Default is 1024
  • watermark: Optional[bool]. Default is False
  • max_new_tokens: Optional[int]. Default is 1024
  • stop: Optional[list]. Default is ["</s>"]
  • return_full_text: Optional[bool]. Default is False
  • stream: Optional[bool]. Default is True
  • use_cache: Optional[bool]. Default is False
  • is_retry: Optional[bool]. Default is False
  • retry_count: Optional[int]. Number of retries for requesting huggingchat. Default is 5

CLI mode

version 0.0.5.2 or 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 passed.
  • /exit : Closes CLI environment.

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.

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.