From d0f19d1f6b3f3dbb0db8794ab8d5c74bd68d5bc6 Mon Sep 17 00:00:00 2001 From: royzhao Date: Fri, 25 Oct 2024 13:26:06 +0800 Subject: [PATCH] fix(knext): add remote client addr (#376) --- python/knext/knext/builder/client.py | 6 ++++-- python/knext/knext/common/rest/configuration.py | 2 +- python/knext/knext/graph_algo/client.py | 6 ++++-- python/knext/knext/project/client.py | 8 +++++--- python/knext/knext/reasoner/client.py | 6 ++++-- python/knext/knext/search/client.py | 6 ++++-- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/python/knext/knext/builder/client.py b/python/knext/knext/builder/client.py index ca84717e..8666ae53 100644 --- a/python/knext/knext/builder/client.py +++ b/python/knext/knext/builder/client.py @@ -13,15 +13,17 @@ from knext.builder import rest from knext.builder.rest.models.writer_graph_request import WriterGraphRequest from knext.common.base.client import Client +from knext.common.rest import ApiClient, Configuration class BuilderClient(Client): """ """ - _rest_client = rest.BuilderApi() - def __init__(self, host_addr: str = None, project_id: int = None): super().__init__(host_addr, project_id) + self._rest_client: rest.BuilderApi = rest.BuilderApi( + api_client=ApiClient(configuration=Configuration(host=host_addr)) + ) def write_graph(self, sub_graph: dict, operation: str, lead_to_builder: bool): request = WriterGraphRequest( diff --git a/python/knext/knext/common/rest/configuration.py b/python/knext/knext/common/rest/configuration.py index 38b46956..4cf7a243 100644 --- a/python/knext/knext/common/rest/configuration.py +++ b/python/knext/knext/common/rest/configuration.py @@ -79,7 +79,7 @@ class Configuration(object): from knext.common import env self.host = ( - os.environ.get("KAG_PROJECT_HOST_ADDR") or host or env.LOCAL_SCHEMA_URL + host or os.environ.get("KAG_PROJECT_HOST_ADDR") or env.LOCAL_SCHEMA_URL ) """Default Base url """ diff --git a/python/knext/knext/graph_algo/client.py b/python/knext/knext/graph_algo/client.py index e4e04aa6..07fb5e7f 100644 --- a/python/knext/knext/graph_algo/client.py +++ b/python/knext/knext/graph_algo/client.py @@ -12,6 +12,7 @@ from typing import List, Dict from knext.common.base.client import Client +from knext.common.rest import ApiClient, Configuration from knext.graph_algo import ( GetPageRankScoresRequest, GetPageRankScoresRequestStartNodes, @@ -23,10 +24,11 @@ from knext.graph_algo import rest class GraphAlgoClient(Client): """ """ - _rest_client = rest.GraphApi() - def __init__(self, host_addr: str = None, project_id: int = None): super().__init__(host_addr, project_id) + self._rest_client: rest.GraphApi = rest.GraphApi( + api_client=ApiClient(configuration=Configuration(host=host_addr)) + ) def calculate_pagerank_scores(self, target_vertex_type, start_nodes: List[Dict]): """ diff --git a/python/knext/knext/project/client.py b/python/knext/knext/project/client.py index bfe5f5c6..525f6811 100644 --- a/python/knext/knext/project/client.py +++ b/python/knext/knext/project/client.py @@ -12,16 +12,18 @@ import json from knext.common.base.client import Client +from knext.common.rest import Configuration, ApiClient from knext.project import rest class ProjectClient(Client): """ """ - _rest_client = rest.ProjectApi() - def __init__(self, host_addr: str = None, project_id: int = None): super().__init__(host_addr, project_id) + self._rest_client: rest.ProjectApi = rest.ProjectApi( + api_client=ApiClient(configuration=Configuration(host=host_addr)) + ) def get_config(self, project_id: str): project = self.get(id=int(project_id)) @@ -36,7 +38,7 @@ class ProjectClient(Client): for project in projects: condition = True for k, v in conditions.items(): - condition = condition and getattr(project, k) == v + condition = condition and str(getattr(project, k)) == str(v) if condition: return project return None diff --git a/python/knext/knext/reasoner/client.py b/python/knext/knext/reasoner/client.py index 72d53133..a9cbbf23 100644 --- a/python/knext/knext/reasoner/client.py +++ b/python/knext/knext/reasoner/client.py @@ -13,6 +13,7 @@ import os import knext.common.cache from knext.common.base.client import Client +from knext.common.rest import ApiClient, Configuration from knext.project.client import ProjectClient from knext.reasoner import ReasonTask from knext.reasoner import rest @@ -26,10 +27,11 @@ reason_cache = knext.common.cache.SchemaCache() class ReasonerClient(Client): """SPG Reasoner Client.""" - _rest_client = rest.ReasonerApi() - def __init__(self, host_addr: str = None, project_id: int = None, namespace=None): super().__init__(host_addr, project_id) + self._rest_client: rest.ReasonerApi = rest.ReasonerApi( + api_client=ApiClient(configuration=Configuration(host=host_addr)) + ) self._namespace = namespace or os.environ.get("KAG_PROJECT_NAMESPACE") self._session = None # load schema cache diff --git a/python/knext/knext/search/client.py b/python/knext/knext/search/client.py index 63adce6c..6c5c08f0 100644 --- a/python/knext/knext/search/client.py +++ b/python/knext/knext/search/client.py @@ -10,6 +10,7 @@ # or implied. from knext.common.base.client import Client +from knext.common.rest import Configuration, ApiClient from knext.search import rest, TextSearchRequest, VectorSearchRequest, IdxRecord @@ -21,10 +22,11 @@ def idx_record_to_dict(record: IdxRecord): class SearchClient(Client): """ """ - _rest_client = rest.SearchApi() - def __init__(self, host_addr: str = None, project_id: int = None): super().__init__(host_addr, project_id) + self._rest_client: rest.SearchApi = rest.SearchApi( + api_client=ApiClient(configuration=Configuration(host=host_addr)) + ) def search_text(self, query_string, label_constraints=None, topk=10): req = TextSearchRequest(self._project_id, query_string, label_constraints, topk)