fix(ollama): resolve model list loading issue and add Pytest for component testing (#3575)
* Commit to solve Model not loading issue The issue was that the url of the models: api/tags was not parsed correctly. It was having a // hence used urlencode to parse it properly. Th e correct apporach works only if the base_url is correct,i.e a valid ollama URL: for DS LF this must be a public ollama Server URL. * updated the component Ollama Component changed the get model to take in base url and the function will make the expected url for the model names. This makes the function better, than providing the model url as paramter. Added Pytest, 7 tests, 1 test excluded for future implememtstion: test_build_model_failure Make lint and Make format had touched multiple files * removed unwanted print statements removed unwanted print statements. make format, formatted a lot of .tsx files also * removed skipped tests * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
3222153938
commit
46a9789028
13 changed files with 3122 additions and 1371 deletions
|
|
@ -1,4 +1,5 @@
|
|||
from typing import Any
|
||||
from urllib.parse import urljoin
|
||||
|
||||
import httpx
|
||||
from langchain_community.chat_models import ChatOllama
|
||||
|
|
@ -41,8 +42,7 @@ class ChatOllamaComponent(LCModelComponent):
|
|||
base_url_value = self.variables(base_url_value)
|
||||
elif not base_url_value:
|
||||
base_url_value = "http://localhost:11434"
|
||||
build_config["model_name"]["options"] = self.get_model(base_url_value + "/api/tags")
|
||||
|
||||
build_config["model_name"]["options"] = self.get_model(base_url_value)
|
||||
if field_name == "keep_alive_flag":
|
||||
if field_value == "Keep":
|
||||
build_config["keep_alive"]["value"] = "-1"
|
||||
|
|
@ -55,8 +55,9 @@ class ChatOllamaComponent(LCModelComponent):
|
|||
|
||||
return build_config
|
||||
|
||||
def get_model(self, url: str) -> list[str]:
|
||||
def get_model(self, base_url_value: str) -> list[str]:
|
||||
try:
|
||||
url = urljoin(base_url_value, "/api/tags")
|
||||
with httpx.Client() as client:
|
||||
response = client.get(url)
|
||||
response.raise_for_status()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue