hugging-chat-api icon indicating copy to clipboard operation
hugging-chat-api copied to clipboard

how do i make it remember previous messages like chatgpt

Open YoussefBechara opened this issue 1 year ago • 12 comments

helpppppppppp

YoussefBechara avatar Feb 11 '24 21:02 YoussefBechara

I'm sorry, but you didn't provide any information about your issue, and seem to have selected an incorrect label. Can you please provide more information about the problems you are having?

Whitelisted1 avatar Feb 11 '24 21:02 Whitelisted1

Hello, it defaults to remember your previous message. Are you encountered any problem?

Soulter avatar Feb 12 '24 02:02 Soulter

thanks guys i fixed it by putting the same conv id each timr

YoussefBechara avatar Mar 04 '24 18:03 YoussefBechara

@YoussefBechara where do you add that conv ID, and how do you get it in the first place?

I have this function and when ever i call it, it starts a new conversation. I am trying now to control it with chatbot.new_conversation(switch_to=True)... @Soulter any idea how to make it stick to one conversation thread?

from hugchat import hugchat
from hugchat.login import Login
import os
from dotenv import load_dotenv, find_dotenv

# read local .env file
_ = load_dotenv(find_dotenv())

def query_LLM(prompt, new_conversation: bool = False):
    # Log in to huggingface and grant authorization to huggingchat
    huggingchat_user_email = os.environ['huggingchat_user_email']
    huggingchat_user_pwd = os.environ['huggingchat_user_pwd']

    sign = Login(email=huggingchat_user_email, passwd=huggingchat_user_pwd)
    cookies = sign.login()

    # Save cookies to the local directory
    cookie_path_dir = "./cookies_snapshot"
    sign.saveCookiesToDir(cookie_path_dir)

    # Create a ChatBot
    chatbot = hugchat.ChatBot(cookies=cookies.get_dict())  # or cookie_path="usercookies/<email>.json"
    if new_conversation:
        chatbot.new_conversation(switch_to=True)
    # non stream response
    return chatbot.chat(prompt)['text']

also as where are at it, what is the utlity of

 # Save cookies to the local directory
    cookie_path_dir = "./cookies_snapshot"
    sign.saveCookiesToDir(cookie_path_dir)

rezkanas avatar Mar 27 '24 11:03 rezkanas

@rezkanas use these two lines: id = chatbot.new_conversation() print(id) chatbot.change_conversation(id) Here we are making the new conv with id printed then we copy it and change ttje conv to it and yea

YoussefBechara avatar Mar 27 '24 20:03 YoussefBechara

Thank you @YoussefBechara. I update my code and continuing in the same conversation is working now. but a new requirements pops up now. I need to change system prompt for each round of conversation. I have a go at it but I see that it does not work when running the code. @Soulter can I change system prompt during the conversation? or is there one system prompt per conversation?

    @staticmethod
    def query_LLM(system_prompt: str, prompt: str, new_conversation: bool = False):
        # Log in to huggingface and grant authorization to huggingchat
        huggingchat_user_email = os.environ['huggingchat_user_email']
        huggingchat_user_pwd = os.environ['huggingchat_user_pwd']

        sign = Login(email=huggingchat_user_email, passwd=huggingchat_user_pwd)
        cookies = sign.login()

        # Save cookies to the local directory
        cookie_path_dir = "./cookies_snapshot"
        sign.saveCookiesToDir(cookie_path_dir)

        # Create a ChatBot
        if new_conversation:
            global conversation_id, chatbot
            chatbot = hugchat.ChatBot(system_prompt=system_prompt,
                                      cookies=cookies.get_dict())  # or cookie_path="usercookies/<email>.json"

            chatbot.new_conversation(switch_to=True)
            conversation_id = chatbot.new_conversation()
        else:
            #for continuing conversation, change system prompt
            chatbot.system_prompt=system_prompt

        chatbot.change_conversation(conversation_id)

        return chatbot.chat(prompt)['text']

rezkanas avatar Mar 27 '24 22:03 rezkanas

@Soulter, @Whitelisted1 any update about this?

rezkanas avatar Apr 04 '24 11:04 rezkanas

@rezkanas what are system prompts? because it doesnt ask me anything i just send normal promptsto the same conversation again and again

YoussefBechara avatar Apr 05 '24 07:04 YoussefBechara

Something like this worked for me (no system_prompt) :

from hugchat import hugchat
from hugchat.login import Login

def query_LLM(prompt: str, new_conversation: bool = False):
        # Log in to huggingface and grant authorization to huggingchat
        huggingchat_user_email = "your_email"
        huggingchat_user_pwd = "your_password"

        sign = Login(email=huggingchat_user_email, passwd=huggingchat_user_pwd)
        cookies = sign.login()

        # Save cookies to the local directory
        cookie_path_dir = "./cookies"
        cookies = sign.login(cookie_dir_path=cookie_path_dir, save_cookies=True)

        # Create a ChatBot
        if new_conversation:
            global conversation_id, chatbot
            chatbot = hugchat.ChatBot(cookies=cookies.get_dict())  # or cookie_path="usercookies/<email>.json"

            chatbot.new_conversation(switch_to=True)
            conversation_id = chatbot.new_conversation()
        else:
            pass

        chatbot.change_conversation(conversation_id)

        return chatbot.chat(prompt)['text']

rep1 = query_LLM('''Hello.''', True)
print(rep1)

rep2 = query_LLM('''How are you ?''', False)
print(rep2)

HydRen-fr avatar Apr 05 '24 15:04 HydRen-fr

I would like to pass different system prompts at each turn of the conversation along with passing user prompts.

However, I've noticed that when I attempt to change the chatbot.system_prompt, the language model (LLM) doesn't seem to adjust its responses accordingly. Could it be that the system prompt can't be changed mid-conversation? I need confirmation or clarification on this matter. I think changing the system prompt mid-conversation isn't directly supported.

rezkanas avatar Apr 09 '24 11:04 rezkanas

I would like to pass different system prompts at each turn of the conversation along with passing user prompts.

However, I've noticed that when I attempt to change the chatbot.system_prompt, the language model (LLM) doesn't seem to adjust its responses accordingly. Could it be that the system prompt can't be changed mid-conversation? I need confirmation or clarification on this matter. I think changing the system prompt mid-conversation isn't directly supported.

With the current way that HuggingFace manages system prompts you can only use one system prompt per conversation.

Whitelisted1 avatar Apr 10 '24 13:04 Whitelisted1

thank you @Whitelisted1.

rezkanas avatar Apr 10 '24 18:04 rezkanas

This issue was marked as stale because of inactivity.

github-actions[bot] avatar Jun 10 '24 01:06 github-actions[bot]

This issue was closed because of inactivity.

github-actions[bot] avatar Jun 17 '24 01:06 github-actions[bot]