Skip to content

Commit

Permalink
feat: support 3.8
Browse files Browse the repository at this point in the history
remove langsmith depend
  • Loading branch information
whybeyoung committed Mar 20, 2024
1 parent 06275e9 commit cbcbaa0
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 109 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
- [ ] 支持 HTTP SPARK API
- [ ] 支持大模型多模态等能力
- [ ] Golang版本[SDK](https://github.com/iflytek/spark-ai-go/)进行中
- [ ] 对接 [liteLLM](https://github.com/BerriAI/litellm)


## 安装

如果你不需要源码,只需要通过 `pip `快速安装
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <ybyang7@iflytek.com>","mingduan <mingduan@iflytek.com>"]
license = "MIT"
Expand All @@ -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 = "*"
Expand All @@ -21,7 +21,6 @@ nest_asyncio = "*"
uvicorn = ">=0.26.0"
packaging = "*"
tenacity = "*"
langsmith = "*"
jsonpatch = "*"

[tool.pytest.ini_options]
Expand Down
67 changes: 2 additions & 65 deletions sparkai/core/callbacks/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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
2 changes: 0 additions & 2 deletions sparkai/core/tracers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"EvaluatorCallbackHandler",
"LangChainTracer",
"ConsoleCallbackHandler",
"Run",
"RunLog",
"RunLogPatch",
"LogStreamCallbackHandler",
Expand All @@ -27,5 +26,4 @@
RunLog,
RunLogPatch,
)
from sparkai.core.tracers.schemas import Run
from sparkai.core.tracers.stdout import ConsoleCallbackHandler
39 changes: 0 additions & 39 deletions sparkai/core/tracers/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit cbcbaa0

Please sign in to comment.