From 8f01a466c675b528e6ff9543340f4a9ea453b044 Mon Sep 17 00:00:00 2001 From: Kieran Sears Date: Sun, 10 Nov 2024 12:29:29 +0000 Subject: [PATCH] urllib to join ollama url domain to endpoint in place of string format --- goldenverba/components/embedding/OllamaEmbedder.py | 5 +++-- goldenverba/components/generation/OllamaGenerator.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/goldenverba/components/embedding/OllamaEmbedder.py b/goldenverba/components/embedding/OllamaEmbedder.py index c26699d7a..b1625c4ed 100644 --- a/goldenverba/components/embedding/OllamaEmbedder.py +++ b/goldenverba/components/embedding/OllamaEmbedder.py @@ -2,6 +2,7 @@ import requests from wasabi import msg import aiohttp +from urllib.parse import urljoin from goldenverba.components.interfaces import Embedding from goldenverba.components.types import InputConfig @@ -33,7 +34,7 @@ async def vectorize(self, config: dict, content: list[str]) -> list[float]: data = {"model": model, "input": content} async with aiohttp.ClientSession() as session: - async with session.post(self.url + "/api/embed", json=data) as response: + async with session.post(urljoin(self.url, "/api/embed"), json=data) as response: response.raise_for_status() data = await response.json() embeddings = data.get("embeddings", []) @@ -42,7 +43,7 @@ async def vectorize(self, config: dict, content: list[str]) -> list[float]: def get_models(url: str): try: - response = requests.get(url + "/api/tags") + response = requests.get(urljoin(url, "/api/tags")) models = [model.get("name") for model in response.json().get("models")] if len(models) > 0: return models diff --git a/goldenverba/components/generation/OllamaGenerator.py b/goldenverba/components/generation/OllamaGenerator.py index 7d48747ec..3d7185619 100644 --- a/goldenverba/components/generation/OllamaGenerator.py +++ b/goldenverba/components/generation/OllamaGenerator.py @@ -1,6 +1,7 @@ import os import json import aiohttp +from urllib.parse import urljoin from typing import List, Dict, AsyncGenerator from goldenverba.components.interfaces import Generator @@ -35,7 +36,6 @@ async def generate_stream( conversation: List[Dict] = [], ) -> AsyncGenerator[Dict, None]: model = config.get("Model").value - url = f"{self.url}/api/chat" system_message = config.get("System Message").value if not self.url: @@ -47,7 +47,7 @@ async def generate_stream( try: async with aiohttp.ClientSession() as session: - async with session.post(url, json=data) as response: + async with session.post(urljoin(self.url, "/api/chat"), json=data) as response: async for line in response.content: if line.strip(): yield self._process_response(line)