From cbcbaa044d0414a984502502f6f41037516f5ca3 Mon Sep 17 00:00:00 2001 From: ybyang Date: Wed, 20 Mar 2024 23:30:30 +0800 Subject: [PATCH] feat: support 3.8 remove langsmith depend --- README.md | 3 ++ pyproject.toml | 5 +-- sparkai/core/callbacks/manager.py | 67 +------------------------------ sparkai/core/tracers/__init__.py | 2 - sparkai/core/tracers/schemas.py | 39 ------------------ 5 files changed, 7 insertions(+), 109 deletions(-) diff --git a/README.md b/README.md index 0796fa1..bcddd4b 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,9 @@ - [ ] 支持 HTTP SPARK API - [ ] 支持大模型多模态等能力 - [ ] Golang版本[SDK](https://github.com/iflytek/spark-ai-go/)进行中 +- [ ] 对接 [liteLLM](https://github.com/BerriAI/litellm) + + ## 安装 如果你不需要源码,只需要通过 `pip `快速安装 diff --git a/pyproject.toml b/pyproject.toml index fc0148b..b0fdd86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "spark-ai-python" -version = "0.3.2" +version = "0.3.3" description = "a sdk for iflytek's spark LLM." authors = ["whybeyoung ","mingduan "] license = "MIT" @@ -10,7 +10,7 @@ packages = [ ] [tool.poetry.dependencies] -python = ">=3.10" +python = ">=3.8" aiohttp = ">3.3" fastapi = {extras = ["all"], version = "^0.110.0"} requests = "*" @@ -21,7 +21,6 @@ nest_asyncio = "*" uvicorn = ">=0.26.0" packaging = "*" tenacity = "*" -langsmith = "*" jsonpatch = "*" [tool.pytest.ini_options] diff --git a/sparkai/core/callbacks/manager.py b/sparkai/core/callbacks/manager.py index 24da9c2..933efe9 100644 --- a/sparkai/core/callbacks/manager.py +++ b/sparkai/core/callbacks/manager.py @@ -1155,13 +1155,6 @@ def _configure( Returns: T: The configured callback manager. """ - from sparkai.core.tracers.context import ( - _configure_hooks, - _get_tracer_project, - _tracing_v2_is_enabled, - tracing_callback_var, - tracing_v2_callback_var, - ) run_tree = None parent_run_id = None if run_tree is None else getattr(run_tree, "id") @@ -1198,18 +1191,8 @@ def _configure( callback_manager.add_metadata(inheritable_metadata or {}) callback_manager.add_metadata(local_metadata or {}, False) - tracer = tracing_callback_var.get() - tracing_enabled_ = ( - env_var_is_set("LANGCHAIN_TRACING") - or tracer is not None - or env_var_is_set("LANGCHAIN_HANDLER") - ) - - tracer_v2 = tracing_v2_callback_var.get() - tracing_v2_enabled_ = _tracing_v2_is_enabled() - tracer_project = _get_tracer_project() debug = _get_debug() - if verbose or debug or tracing_enabled_ or tracing_v2_enabled_: + if verbose or debug : from sparkai.core.tracers.langchain import LangChainTracer from sparkai.core.tracers.langchain_v1 import LangChainTracerV1 from sparkai.core.tracers.stdout import ConsoleCallbackHandler @@ -1227,51 +1210,5 @@ def _configure( for handler in callback_manager.handlers ): callback_manager.add_handler(ConsoleCallbackHandler(), True) - if tracing_enabled_ and not any( - isinstance(handler, LangChainTracerV1) - for handler in callback_manager.handlers - ): - if tracer: - callback_manager.add_handler(tracer, True) - else: - handler = LangChainTracerV1() - handler.load_session(tracer_project) - callback_manager.add_handler(handler, True) - if tracing_v2_enabled_ and not any( - isinstance(handler, LangChainTracer) - for handler in callback_manager.handlers - ): - if tracer_v2: - callback_manager.add_handler(tracer_v2, True) - else: - try: - handler = LangChainTracer(project_name=tracer_project) - callback_manager.add_handler(handler, True) - except Exception as e: - logger.warning( - "Unable to load requested LangChainTracer." - " To disable this warning," - " unset the LANGCHAIN_TRACING_V2 environment variables.", - e, - ) - for var, inheritable, handler_class, env_var in _configure_hooks: - create_one = ( - env_var is not None - and env_var_is_set(env_var) - and handler_class is not None - ) - if var.get() is not None or create_one: - var_handler = var.get() or cast(Type[BaseCallbackHandler], handler_class)() - if handler_class is None: - if not any( - handler is var_handler # direct pointer comparison - for handler in callback_manager.handlers - ): - callback_manager.add_handler(var_handler, inheritable) - else: - if not any( - isinstance(handler, handler_class) - for handler in callback_manager.handlers - ): - callback_manager.add_handler(var_handler, inheritable) + return callback_manager diff --git a/sparkai/core/tracers/__init__.py b/sparkai/core/tracers/__init__.py index 393efbe..2de147d 100644 --- a/sparkai/core/tracers/__init__.py +++ b/sparkai/core/tracers/__init__.py @@ -13,7 +13,6 @@ "EvaluatorCallbackHandler", "LangChainTracer", "ConsoleCallbackHandler", - "Run", "RunLog", "RunLogPatch", "LogStreamCallbackHandler", @@ -27,5 +26,4 @@ RunLog, RunLogPatch, ) -from sparkai.core.tracers.schemas import Run from sparkai.core.tracers.stdout import ConsoleCallbackHandler diff --git a/sparkai/core/tracers/schemas.py b/sparkai/core/tracers/schemas.py index cec6c78..d8fd9cd 100644 --- a/sparkai/core/tracers/schemas.py +++ b/sparkai/core/tracers/schemas.py @@ -6,23 +6,12 @@ from typing import Any, Dict, List, Optional, Type from uuid import UUID -from langsmith.schemas import RunBase as BaseRunV2 -from langsmith.schemas import RunTypeEnum as RunTypeEnumDep from sparkai.core._api import deprecated from sparkai.core.outputs import LLMResult from sparkai.core.pydantic_v1 import BaseModel, Field, root_validator -@deprecated("0.1.0", alternative="Use string instead.", removal="0.2.0") -def RunTypeEnum() -> Type[RunTypeEnumDep]: - """RunTypeEnum.""" - warnings.warn( - "RunTypeEnum is deprecated. Please directly use a string instead" - " (e.g. 'llm', 'chain', 'tool').", - DeprecationWarning, - ) - return RunTypeEnumDep @deprecated("0.1.0", removal="0.2.0") @@ -110,40 +99,12 @@ class ToolRun(BaseRun): # Begin V2 API Schemas -class Run(BaseRunV2): - """Run schema for the V2 API in the Tracer.""" - execution_order: int - child_execution_order: int - child_runs: List[Run] = Field(default_factory=list) - tags: Optional[List[str]] = Field(default_factory=list) - events: List[Dict[str, Any]] = Field(default_factory=list) - trace_id: Optional[UUID] = None - dotted_order: Optional[str] = None - - @root_validator(pre=True) - def assign_name(cls, values: dict) -> dict: - """Assign name to the run.""" - if values.get("name") is None: - if "name" in values["serialized"]: - values["name"] = values["serialized"]["name"] - elif "id" in values["serialized"]: - values["name"] = values["serialized"]["id"][-1] - if values.get("events") is None: - values["events"] = [] - return values - - -ChainRun.update_forward_refs() -ToolRun.update_forward_refs() -Run.update_forward_refs() __all__ = [ "BaseRun", "ChainRun", "LLMRun", - "Run", - "RunTypeEnum", "ToolRun", "TracerSession", "TracerSessionBase",