Git Product home page Git Product logo

Comments (4)

simonw avatar simonw commented on June 20, 2024 1

The session should be reset at the end of the with block. Try this:

from gpt4all import GPT4All
model = GPT4All("Phi-3-mini-4k-instruct.Q4_0.gguf")

with model.chat_session():
    print(model.generate("2 fun names for a pelican"))
    print(model.generate("2 more"))

with model.chat_session():
    print("-- should have reset --")
    print(model.generate("2 more"))

I get this:

  1. "Pelico the Plunge" - A playful take on their diving behavior, suggesting they enjoy taking plunges into water to catch fish!

  2. "Scoop Squad Pelicans" – Highlights how these birds skillfully scoop up prey with their large pouched bills while also being a fun and memorable name for an avian-themed team or group activity.


  1. "Neck Divers of the Bayou" – This title captures both the unique neck dive behavior pelicans are known for, as well as their habitat in bayous where they can often be spotted fishing and diving with ease.

  2. "The Scaly Surfers of the Sea" - A whimsical name that plays on the idea of pelicans riding ocean waves to catch food while also incorporating a nod to their scaly appearance, which is distinctive among birds.

-- should have reset --

It seems like your request was cut off. However, I'll assume you want to know what "2 more" could mean in a common context and provide an answer for that scenario: [...]

from gpt4all.

simonw avatar simonw commented on June 20, 2024 1

You might be able to achieve the same effect by calling __enter__() and __exit__() at the right moments instead of using with:

Try something like this:

from gpt4all import GPT4All

model = GPT4All("Phi-3-mini-4k-instruct.Q4_0.gguf")

# First chat session
session = model.chat_session()
session.__enter__()
try:
    print(model.generate("2 fun names for a pelican"))
    print(model.generate("2 more"))
finally:
    session.__exit__(None, None, None)

# Second chat session
session = model.chat_session()
session.__enter__()
try:
    print("-- should have reset --")
    print(model.generate("2 more"))
finally:
    session.__exit__(None, None, None)

You can keep that session object as self.session or similar.

from gpt4all.

woheller69 avatar woheller69 commented on June 20, 2024 1

Excellent, thanks! That works.

https://github.com/woheller69/gpt4all-TK-CHAT/blob/main/appGUI.py

from gpt4all.

woheller69 avatar woheller69 commented on June 20, 2024

that does not work for me. In my tkinter app mainloop() must at the end of the with statement.
So I would have to restart the app which - with the latest Python bindings - is more time consuming than before #2354.
Therefore I would like to stay within the contextmanager and just clear history.

from gpt4all.

Related Issues (20)

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.