Я пытаюсь импортировать модуль KServe, но оператор импорта выдает ошибку:
ImportError: cannot import name 'RootModel' from 'pydantic' (/opt/conda/lib/python3.10/site-packages/pydantic/__init__.cpython-310-x86_64-linux-gnu.so)`.
Я использую образец из документации KServe. Проблема сохраняется после удаления и переустановки библиотеки. Эта проблема связана с конфликтом версий? Стоит ли мне использовать другую версию?
Это мой код:
from kubernetes import client
from kserve import KServeClient
from kserve import constants
from kserve import utils
Выдает следующую ошибку:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[14], line 2
1 from kubernetes import client
----> 2 from kserve import KServeClient
3 from kserve import constants
4 from kserve import utils
File /opt/conda/lib/python3.10/site-packages/kserve/__init__.py:18
15 from __future__ import absolute_import
17 from .model import Model
---> 18 from .model_server import ModelServer
19 from .inference_client import InferenceServerClient
20 from .protocol.infer_type import InferRequest, InferInput, InferResponse, InferOutput
File /opt/conda/lib/python3.10/site-packages/kserve/model_server.py:33
31 from .model import BaseKServeModel
32 from .model_repository import ModelRepository
---> 33 from .protocol.dataplane import DataPlane
34 from .protocol.grpc.server import GRPCServer
35 from .protocol.model_repository_extension import ModelRepositoryExtension
File /opt/conda/lib/python3.10/site-packages/kserve/protocol/dataplane.py:33
31 from ..utils.utils import create_response_cloudevent, is_structured_cloudevent
32 from .infer_type import InferRequest, InferResponse
---> 33 from .rest.openai import OpenAIModel
35 JSON_HEADERS = [
36 "application/json",
37 "application/cloudevents+json",
38 "application/ld+json",
39 ]
41 # RayServeHandle used to be the return type of serve.run.
42 # RayServeSyncHandle has been the return type of serve.run since Ray 2.5.
43 # DeploymentHandle will be the new return type (still under feature flag in Ray 2.7).
44 # ref https://github.com/ray-project/ray/pull/37817
45 # On Ray 2.10, it now returns DeploymentHandle:
46 # https://docs.ray.io/en/latest/serve/api ... nt-handles
File /opt/conda/lib/python3.10/site-packages/kserve/protocol/rest/openai/__init__.py:15
1 # Copyright 2023 The KServe Authors.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
(...)
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
---> 15 from .openai_model import (
16 ChatPrompt,
17 CompletionRequest,
18 ChatCompletionRequest,
19 OpenAIModel,
20 )
22 from .openai_proxy_model import OpenAIProxyModel
23 from .openai_chat_adapter_model import OpenAIChatAdapterModel
File /opt/conda/lib/python3.10/site-packages/kserve/protocol/rest/openai/openai_model.py:21
17 import inspect
19 from pydantic import BaseModel
---> 21 from kserve.protocol.rest.openai.types import (
22 ChatCompletion,
23 ChatCompletionChunk,
24 Completion,
25 CreateChatCompletionRequest,
26 CreateCompletionRequest,
27 )
29 from ....model import BaseKServeModel
32 class ChatPrompt(BaseModel):
File /opt/conda/lib/python3.10/site-packages/kserve/protocol/rest/openai/types/__init__.py:17
1 # Copyright 2023 The KServe Authors.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
(...)
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from typing import Union
---> 17 from kserve.protocol.rest.openai.types.openapi import (
18 ChatCompletionRequestAssistantMessage,
19 ChatCompletionRequestFunctionMessage,
20 ChatCompletionRequestSystemMessage,
21 ChatCompletionRequestToolMessage,
22 ChatCompletionRequestUserMessage,
23 ChatCompletionResponseMessage,
24 )
25 from kserve.protocol.rest.openai.types.openapi import (
26 ChatCompletionStreamResponseDelta as ChoiceDelta,
27 )
28 from kserve.protocol.rest.openai.types.openapi import ChatCompletionTokenLogprob
File /opt/conda/lib/python3.10/site-packages/kserve/protocol/rest/openai/types/openapi.py:23
19 from __future__ import annotations
21 from typing import Any, Dict, List, Optional, Union
---> 23 from pydantic import (
24 AnyUrl,
25 BaseModel,
26 ConfigDict,
27 Field,
28 PositiveFloat,
29 RootModel,
30 confloat,
31 conint,
32 constr,
33 )
34 from typing_extensions import Literal
37 class Error(BaseModel):
ImportError: cannot import name 'RootModel' from 'pydantic' (/opt/conda/lib/python3.10/site-packages/pydantic/__init__.cpython-310-x86_64-linux-gnu.so)
Мои версии pydantic и KServe приведены ниже:
Name: pydantic
Version: 1.10.18
Summary: Data validation and settings management using python type hints
Home-page: https://github.com/pydantic/pydantic
Author: Samuel Colvin
Author-email: s@muelcolvin.com
License: MIT
Location: /opt/conda/lib/python3.10/site-packages
Requires: typing-extensions
Required-by: dataproc_jupyter_plugin, fastapi, google-cloud-aiplatform, kserve, ydata-profiling
---
Name: kserve
Version: 0.13.1
Summary: KServe Python SDK
Home-page: https://github.com/kserve/kserve/tree/m ... hon/kserve
Author: The KServe Authors
Author-email: dsun20@bloomberg.net
License: Apache-2.0
Location: /opt/conda/lib/python3.10/site-packages
Requires: cloudevents, fastapi, grpcio, httpx, kubernetes, numpy, orjson, pandas, prometheus-client, protobuf, psutil, pydantic, python-dateutil, pyyaml, ray, six, tabulate, timing-asgi, uvicorn
Required-by:
Подробнее здесь: https://stackoverflow.com/questions/790 ... ve-library