[Python] How to get a list of models available in Ollama using Langchain

Discussão em 'Python' iniciado por Stack, Março 1, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to run a Python script that gets and prints a list of the models that are available to a running instance of Ollama. My code, based on code provided at https://medium.com/@garysvenson09/h...in-ollama-for-langchain-tutorial-786cb14298a8, is provided below:

    from langchain import Ollama

    ollama_client = Ollama()
    model_list = ollama_client.list_models()
    for model in model_list: print(f"Model Name: {model.name}, Version: {model.version}, Description: {model.description}")


    The problem is that when I run the script, I get the following error:

    Traceback (most recent call last):
    File "C:\Research\Project 39\langtest1\Test1\firsttest.py", line 2, in <module>
    from langchain import Ollama
    ImportError: cannot import name 'Ollama' from 'langchain' (C:\Research\Project 39\langtest1\Test1\venv\Lib\site-packages\langchain\__init__.py)
    Process finished with exit code 1


    Obviously, the code I am using is flawed.

    How to get a list of available models from Ollama?

    Continue reading...

Compartilhe esta Página