* * Add feature flag for sdk_v1 * Add sdk1 to unstract common ns * Update backend deps * Fix dev essentials container names * Update sample compose override * * Fix imports in llm * Refactor provider args validation * [feat] add embedding, vectordb adapters in sdk1 [feat] add file storage, tool, util, platform, prompt modules in sdk1 [feat] integrate sdk1 in backend under feature flag * feat: integrate sdk1 in platform service * [feat] integrate sdk1 with filesystem core package * refactor: conditionally import sdk1 in platform svc * refactor: conditionally import sdk1 in backend * feat: integrate sdk1 with unstract core tool registry pkg * feat: integrate sdk1 with tools feat: add x2txt adapter to sdk1 feat: add adapter and tools helpers to sdk1 * feat: integrate sdk1 with prompt service feat: add llm no-op adapter in sdk1 feat: add utils in sdk1 * Regenerated uv.lock for backend since it had issues * fix: cleanup unnecessary conditionals * Removed import which caused issues in prompt_studio_helper.py * fix: embedding init feat: unified embedding interface powered by litellm * fix: correct platform helper imports * Fixed variations of feature flag differing between sdk pypi and local sdk * Fixed inconsistent version of "aiohttp" in backend's uv.lock * fix: resolve circular imports by restructuring SDK modules - Move audit.py and usage_handler.py from utils/ to parent directory - Remove re-exports from utils/__init__.py to eliminate circular dependencies - Update imports across codebase to be explicit: * Direct imports from utils.common for Utils and log_elapsed * Direct import from audit module for Audit class * Direct import from utils.tool for ToolUtils - Fix imports in backend services, prompt-service, and tools Files moved: - unstract/sdk1/utils/audit.py → unstract/sdk1/audit.py - unstract/sdk1/utils/usage_handler.py → unstract/sdk1/usage_handler.py * Refactor SDK1 adapters: migrate to versioned directories - Rename embedding/ to embedding1/ for all adapter types - Rename llm/ to llm1/ directory structure - Add new base1.py classes for adapter foundations - Update backend adapter processor to support new structure - Update import paths and references in embedding.py and llm.py * deps: add requirements feat: bump litellm version chore: generate uv lock * * Remove v0 embedding and llm adapters * Add v1 embedding and llm adapters * Add unified litellm powered embedding and llm interfaces * Fix internal v1 imports * Remove debug logs * feat: add missing modules * fix: module imports * fix: handle adapter metadata * feat: add support for adapter instance id * fix: kw arguments for embedding entrypoint * fix: module invocation * feat: add embedding compat layer fix: tool binding for adapter instance id fix: context window size integration fix: callabck manager for embedding compat * fix: embedding compat layer async apis * fix: missing imports * fix: callback manager for embedding compat * feat: remove llmwhisperer v1 adapter feat: remove deprecated code feat: add metrics capture to llm adapters feat: add llm usage reporting feat: add llm response post processing fix: handling platform kwargs fix: minor integration issues * fix: type hints * feat: make platform api key optional if no tool * fix: cleanup llmwhisperer v1 imports * fix: minor integration issues * fix: minor integration issues * fix: minor integration issues * fix: minor integration issues * style: improve readability * style: improve readability fix: minor integration issues * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fixed Azure openai LLM connector not working. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * feat: integrate unstract-sdk1 as a dependency into prompt service - Add unstract-sdk1as a dependency to prompt-service pyproject.toml - Update prompt Dockerfile to include sdk1 package in build * Fixed extra params passed to bedrock llm adapter and added support for thinking * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * feat(sdk1): upgrade litellm to v1.76.0 for consistency in params for LLMs - Update litellm dependency from v1.74.7 to v1.76.0 in pyproject.toml - Add new uv.lock file for sdk1 package dependency management - Update backend and prompt-service uv.lock files for dependency consistency * - Add litellm.drop_params=True to filter unsupported model parameters - Fixed vertex AI llms connector not working - Modified params to include thinking capabilities for bedrock llm. - Update OpenAI adapter configuration schema (Previously it was the schema for OpenAI embedding). * refactor(sdk1): separate LLM and embedding parameter classes - Split BaseParameters into BaseChatCompletionParameters and BaseEmbeddingParameters - Rename OpenAIParameters to OpenAILLMParameters for clarity - Add OpenAIEmbeddingParameters for embedding-specific configurations - Update all embedding adapters to use new parameter classes(*provider*EmbeddingParameters) - Remove batch_embed_size from bedrock.json configuration file since bedrock doesn't support it. - Improve embedding.py with better parameter handling and litellm.drop_params - Add fallback for platform API key when tool is not available - Fix default parameter handling in EmbeddingCompat class * Added unstract-sdk1 as a dependency to platform-service * Fixed cost mot being displayed for prompt runs in prompt-studio * Fixed issues with create profile manager not working properly in prompt-studio * fix(sdk1): resolve compatibility issues with single_pass_extraction plugin - Fix LLM response structure compatibility by returning LLMResponseCompat objects - Merge usage_kwargs into platform_kwargs for proper audit/usage tracking - Add adapter_instance_id to platform_kwargs similar to original SDK - Update test_connection method to use LLMResponseCompat.text attribute - Ensure usage data (run_id, llm_usage_reason, adapter_instance_id) is properly passed to audit system This resolves TypeError and AttributeError issues when using SDK1 with plugins that expect unstract-sdk compatible response structures and usage tracking. * - Added feature flag imports for some file which imported sdk0(llama-index) - Added get_model_name method in sdk1 llm.py - moved model_name sanitization from cost_calculation.py to audit.py(sdk1) * Revert unnecessary empty line Signed-off-by: Hari John Kuriakose <hari@zipstack.com> * added reasoning capabilities and fixed issue with validating model name * - Removed .gitignore .pre-commit-config.yaml - Removed commented out code in pyproject.toml in sdk1 folder * Revert "- Removed .gitignore .pre-commit-config.yaml" This reverts commit 8a2ed67ef8f4e7134fb7eb735b0dac40be67ebf1. * - Removed .gitignore .pre-commit-config.yaml - Removed commented code in pyproject.toml in sdk1 * Reverted rabbitmq hostname to `unstract-rabbit` in dev-essentials.yaml * Imported LLMWhispererv1 into sdkv1 * Removed commented out supabase deps in pyproject.toml * Added support for sdk1 in tools * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Generate lock files for the latest unstract-sdk v0.77.3 * Addressed pre-commits issues with typing annotation and long lines of code * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fixed ruff fails in pre-commit check * Fixed pre-commit ruff failures in sdk1 directory and modified ruff rules in pyproject.toml * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fixed sonar cloud reliability issues. --------- Signed-off-by: Hari John Kuriakose <hari@zipstack.com> Co-authored-by: pk-zipstack <praveen@zipstack.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
108 lines
2.8 KiB
Python
108 lines
2.8 KiB
Python
from rest_framework.exceptions import APIException
|
|
|
|
from adapter_processor_v2.constants import AdapterKeys
|
|
from unstract.flags.feature_flag import check_feature_flag_status
|
|
|
|
if check_feature_flag_status("sdk1"):
|
|
from unstract.sdk1.exceptions import SdkError
|
|
else:
|
|
from unstract.sdk.exceptions import SdkError
|
|
|
|
|
|
class IdIsMandatory(APIException):
|
|
status_code = 400
|
|
default_detail = "ID is Mandatory."
|
|
|
|
|
|
class InValidType(APIException):
|
|
status_code = 400
|
|
default_detail = "Type is not Valid."
|
|
|
|
|
|
class InValidAdapterId(APIException):
|
|
status_code = 400
|
|
default_detail = "Adapter ID is not Valid."
|
|
|
|
|
|
class InternalServiceError(APIException):
|
|
status_code = 500
|
|
default_detail = "Internal Service error"
|
|
|
|
|
|
class CannotDeleteDefaultAdapter(APIException):
|
|
status_code = 500
|
|
default_detail = (
|
|
"This is configured as default and cannot be deleted. "
|
|
"Please configure a different default before you try again!"
|
|
)
|
|
|
|
|
|
class DuplicateAdapterNameError(APIException):
|
|
status_code = 400
|
|
default_detail: str = AdapterKeys.ADAPTER_NAME_EXISTS
|
|
|
|
def __init__(
|
|
self,
|
|
name: str | None = None,
|
|
detail: str | None = None,
|
|
code: str | None = None,
|
|
) -> None:
|
|
if name:
|
|
detail = self.default_detail.replace("this name", f"name '{name}'")
|
|
super().__init__(detail, code)
|
|
|
|
|
|
class TestAdapterError(APIException):
|
|
status_code = 500
|
|
default_detail = "Error while testing adapter"
|
|
|
|
def __init__(
|
|
self,
|
|
sdk_err: SdkError,
|
|
detail: str | None = None,
|
|
code: str | None = None,
|
|
adapter_name: str | None = None,
|
|
):
|
|
if sdk_err.status_code:
|
|
self.status_code = sdk_err.status_code
|
|
if detail is None:
|
|
adapter_name = f"'{adapter_name}'" if adapter_name else "adapter"
|
|
detail = f"Error testing {adapter_name}. {str(sdk_err)}"
|
|
super().__init__(detail, code)
|
|
|
|
|
|
class TestAdapterInputError(APIException):
|
|
status_code = 400
|
|
default_detail = "Error while testing adapter, please check the configuration."
|
|
|
|
|
|
class DeleteAdapterInUseError(APIException):
|
|
status_code = 409
|
|
|
|
def __init__(
|
|
self,
|
|
detail: str | None = None,
|
|
code: str | None = None,
|
|
adapter_name: str = "adapter",
|
|
):
|
|
if detail is None:
|
|
if adapter_name != "adapter":
|
|
adapter_name = f"'{adapter_name}'"
|
|
detail = (
|
|
f"Cannot delete {adapter_name}. "
|
|
"It is used in a workflow or a prompt studio project"
|
|
)
|
|
super().__init__(detail, code)
|
|
|
|
|
|
class AdapterNotFound(APIException):
|
|
status_code = 404
|
|
default_detail = "Adapter not found"
|
|
|
|
def __init__(
|
|
self,
|
|
detail: str | None = None,
|
|
code: str | None = None,
|
|
) -> None:
|
|
super().__init__(detail, code)
|