Your first chat bot with python!

Python
AI
Author

David Munoz Tord

Published

June 27, 2023

By David Munoz Tord

Goal: Learn about language models and familiarize yourself with some of the basic functions of the {languagemodels} to create your own chat bot.

{languagemodels} is a python module designed to be as simple as possible for learners and educators exploring how large language models intersect with modern software development. The interfaces to this package are all simple functions using standard types. The complexity of large language models is hidden from view while providing free local inference using light-weight, open models. All included models are free for educational use, no API keys are required, and all inference is performed locally by default.

Read more about it

You can morph between plot like this:

import languagemodels as lm
lm.do("What color is the sky?")


To easy, let’s try something a bit harder

lm.do("If I have 7 apples then eat 5, how many apples do I have?")

Aouch…

Indeed the model performance is quite low because the models used by this package are 1000x smaller than the largest models in use today. They are useful as learning tools, but if you are expecting ChatGPT or similar performance, you will be very disappointed…

The base model should work on any system with 512MB of memory, but this memory limit can be increased. Setting this value higher will require more memory and generate results more slowly, but the results should be superior. Let’s try:

lm.set_max_ram('4gb')
lm.do("If I have 7 apples then eat 5, how many apples do I have?")

Yeah, here we go little (4gb) buddy!


Now that we got the basics, let’s play with it!

lm.chat('''
     System: Respond as a helpful assistant.

     User: What is relativity?

     Assistant:
     ''')


lm.complete("She hid in her room until")


lm.get_wiki("Physics")