-
-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to
ChatOllama
base class in Ollama provider (#1015)
* Added separate `ollama` provider Created a separate file `ollama.py` as a unique provider. Refactored other code accordingly. Also changed the `Ollama` class to `ChatOllama` so that it can support binding tools to the LLM. Updated the imports to come from `langchain_ollama` instead of `langchain_community` Tested on several Ollama models, both LLMs and embedding models: `mxbai-embed-large`, `nomic-embed-text`, `ima/deepseek-math`, `mathstral`, `qwen2-math`, `snowflake-arctic-embed`, `mistral`, `llama3.1`, `starcoder2:15b-instruct` * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
0884211
commit e6ec9e9
Showing
5 changed files
with
36 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/ollama.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from langchain_ollama import ChatOllama, OllamaEmbeddings | ||
|
||
from ..embedding_providers import BaseEmbeddingsProvider | ||
from ..providers import BaseProvider, EnvAuthStrategy, TextField | ||
|
||
|
||
class OllamaProvider(BaseProvider, ChatOllama): | ||
id = "ollama" | ||
name = "Ollama" | ||
model_id_key = "model" | ||
help = ( | ||
"See [https://www.ollama.com/library](https://www.ollama.com/library) for a list of models. " | ||
"Pass a model's name; for example, `deepseek-coder-v2`." | ||
) | ||
models = ["*"] | ||
registry = True | ||
fields = [ | ||
TextField(key="base_url", label="Base API URL (optional)", format="text"), | ||
] | ||
|
||
|
||
class OllamaEmbeddingsProvider(BaseEmbeddingsProvider, OllamaEmbeddings): | ||
id = "ollama" | ||
name = "Ollama" | ||
# source: https://ollama.com/library | ||
models = [ | ||
"nomic-embed-text", | ||
"mxbai-embed-large", | ||
"all-minilm", | ||
"snowflake-arctic-embed", | ||
] | ||
model_id_key = "model" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters