Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ai.load_session() doesn't load messages #83

Open
pyrotank41 opened this issue Sep 12, 2023 · 1 comment
Open

ai.load_session() doesn't load messages #83

pyrotank41 opened this issue Sep 12, 2023 · 1 comment

Comments

@pyrotank41
Copy link

pyrotank41 commented Sep 12, 2023

while loading a saved session, and I noticed the load_session() function never loads the messages from the saved session. Was that intended? or am i missing something?

to work around it i am using using the following code instead of using ai.load_session()

with open("chat_session.json", "rb") as f:
                sess_dict = orjson.loads(f.read())
ai.new_session(**sess_dict, api_key=OPENAI_API_KEY)

list_dict = sess_dict['messages']
chat_messages = [ChatMessage.model_validate(item) for item in list_dict]

ai.default_session.messages = chat_messages

i can create a pull request if the maintainers of this repository find this to be a bug

@CyberDefend3r
Copy link

It does load the messages from a saved session file. This is the main reason I use the library, it makes few-shot prompting super simple. I have saved session files with fake user and assistant messages so that it knows how to respond to future prompts.

I did try but I can't seem to replicate your issue. All the messages load for me when using the load_session() method and I verified by dumping the messages using the get_session() method. Is it possible that the session file you are loading doesn't have any messages or maybe not formatted correctly?

Here is the code I used to test:

# create an instance of AIChat class
ai = AIChat(api_key=_key_, console=False, model="gpt-4-turbo", params={"temperature": 0.78, "max_tokens": 2048})

# Load a saved session JSON file
ai.load_session(api_key=_key_, input_path="./ai_context/defender_generic.json")

# Dump the messages in that session as a list of ChatMessage objects
ai.get_session(id="defender").messages

EXAMPLE:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants