Ollama Python Playground
August 5, 2024 ยท View on GitHub
This project is designed to be opened in GitHub Codespaces as an easy way for anyone to try out SLMs (small language models) entirely in the browser.
-
Open the Codespace in the browser using the
Codebutton at the top of the repository. -
Once the Codespace is loaded, it should have ollama pre-installed as well as the OpenAI Python SDK.
-
Ask Ollama to run the SLM of your choice. For example, to run the phi3 model:
ollama run phi3:miniThat will take a few minutes to download the model into the Codespace.
-
Once you see "success" in the output, you can send a message to that model from the prompt.
>>> Write a haiku about hungry hippos -
After several seconds, you should see a response stream in from the model.
-
To learn about different techniques used with language models, open the Python notebook
ollama.ipynband run each cell . If you used a model other than 'phi3:mini', change theMODEL_NAMEin the first cell. -
To have a conversation with a model from Python, open the Python file
chat_history.pyand run it. You can change theMODEL_NAMEat the top of the file as needed, and you can also modify the system message or add few-shot examples if desired.
Additional resources
For more information about working with the Phi-3 model, check out the Phi-3 Cookbook.
To learn more about generative AI generally, check out Generative AI for beginners.
For example code that works with OpenAI models as well, try python-openai-demos.