Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition to langchain-core ^0.1 #564

Merged
merged 5 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions langserve/api_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
from fastapi import HTTPException
from fastapi.encoders import jsonable_encoder
from fastapi.exceptions import RequestValidationError
from langchain.callbacks.base import AsyncCallbackHandler
from langchain.callbacks.tracers.log_stream import RunLogPatch
from langchain.load.serializable import Serializable
from langchain.schema.runnable import Runnable, RunnableConfig
from langchain.schema.runnable.config import get_config_list, merge_configs
from langchain_core.callbacks.base import AsyncCallbackHandler
from langchain_core.load.serializable import Serializable
from langchain_core.runnables import Runnable, RunnableConfig
from langchain_core.runnables.config import get_config_list, merge_configs
from langchain_core.tracers import RunLogPatch
from langsmith import client as ls_client
from langsmith.utils import tracing_is_enabled
from starlette.requests import Request
Expand Down
9 changes: 6 additions & 3 deletions langserve/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
from typing import Any, Dict, List, Optional, Sequence
from uuid import UUID

from langchain.callbacks.base import AsyncCallbackHandler
from langchain.callbacks.manager import (
from langchain_core.agents import AgentAction, AgentFinish
from langchain_core.callbacks import AsyncCallbackHandler
from langchain_core.callbacks.manager import (
BaseRunManager,
ahandle_event,
handle_event,
)
from langchain.schema import AgentAction, AgentFinish, BaseMessage, Document, LLMResult
from langchain_core.documents import Document
from langchain_core.messages import BaseMessage
from langchain_core.outputs import LLMResult
from typing_extensions import TypedDict


Expand Down
12 changes: 6 additions & 6 deletions langserve/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@

import httpx
from httpx._types import AuthTypes, CertTypes, CookieTypes, HeaderTypes, VerifyTypes
from langchain.callbacks.manager import (
from langchain_core.callbacks import (
AsyncCallbackManagerForChainRun,
CallbackManagerForChainRun,
)
from langchain.callbacks.tracers.log_stream import RunLogPatch
from langchain.load.dump import dumpd
from langchain.schema.runnable import Runnable
from langchain.schema.runnable.config import (
from langchain_core.load.dump import dumpd
from langchain_core.runnables import Runnable
from langchain_core.runnables.config import (
RunnableConfig,
ensure_config,
get_async_callback_manager_for_config,
get_callback_manager_for_config,
)
from langchain.schema.runnable.utils import AddableDict, Input, Output
from langchain_core.runnables.schema import StreamEvent
from langchain_core.runnables.utils import AddableDict, Input, Output
from langchain_core.tracers.log_stream import RunLogPatch
from typing_extensions import Literal

from langserve.callbacks import CallbackEventDict, ahandle_callbacks, handle_callbacks
Expand Down
2 changes: 1 addition & 1 deletion langserve/playground.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Literal, Sequence, Type

from fastapi.responses import Response
from langchain.schema.runnable import Runnable
from langchain_core.runnables import Runnable

from langserve.pydantic_v1 import BaseModel

Expand Down
12 changes: 6 additions & 6 deletions langserve/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
from typing import Any, Dict, List, Union

import orjson
from langchain.prompts.base import StringPromptValue
from langchain.prompts.chat import ChatPromptValueConcrete
from langchain.schema.agent import AgentAction, AgentActionMessageLog, AgentFinish
from langchain.schema.document import Document
from langchain.schema.messages import (
from langchain_core.agents import AgentAction, AgentActionMessageLog, AgentFinish
from langchain_core.documents import Document
from langchain_core.messages import (
AIMessage,
AIMessageChunk,
ChatMessage,
Expand All @@ -32,12 +30,14 @@
SystemMessage,
SystemMessageChunk,
)
from langchain.schema.output import (
from langchain_core.outputs import (
ChatGeneration,
ChatGenerationChunk,
Generation,
LLMResult,
)
from langchain_core.prompt_values import ChatPromptValueConcrete
from langchain_core.prompts.base import StringPromptValue

from langserve.pydantic_v1 import BaseModel, ValidationError
from langserve.validation import CallbackEvent
Expand Down
2 changes: 1 addition & 1 deletion langserve/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Union,
)

from langchain.schema.runnable import Runnable
from langchain_core.runnables import Runnable
from typing_extensions import Annotated

from langserve.api_handler import APIHandler, PerRequestConfigModifier, _is_hosted
Expand Down
10 changes: 3 additions & 7 deletions langserve/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@
from typing import Any, Dict, List, Literal, Optional, Sequence, Union
from uuid import UUID

from langchain.schema import (
BaseMessage,
ChatGeneration,
Document,
Generation,
RunInfo,
)
from langchain_core.documents import Document
from langchain_core.messages import BaseMessage
from langchain_core.outputs import ChatGeneration, Generation, RunInfo
from typing_extensions import Type

from langserve.schema import BatchResponseMetadata, SingletonResponseMetadata
Expand Down
323 changes: 1 addition & 322 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fastapi = {version = ">=0.90.1,<1", optional = true}
sse-starlette = {version = "^1.3.0", optional = true}
httpx-sse = {version = ">=0.3.1", optional = true}
pydantic = ">=1"
langchain = ">=0.0.333"
langchain-core = "^0.1.0"
orjson = ">=2"

[tool.poetry.group.dev.dependencies]
Expand Down
7 changes: 3 additions & 4 deletions tests/unit_tests/test_callbacks.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import uuid

from langchain_core.prompts import ChatPromptTemplate

from langserve.callbacks import AsyncEventAggregatorCallback, replace_uuids
from tests.unit_tests.utils.llms import FakeListLLM


async def test_event_aggregator() -> None:
"""Test that the event aggregator is aggregating events."""

from langchain.llms import FakeListLLM
from langchain.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate.from_template("{question}")
llm = FakeListLLM(responses=["hello", "world"])

Expand Down
8 changes: 2 additions & 6 deletions tests/unit_tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
from typing import Any

import pytest
from langchain.schema.messages import (
HumanMessage,
HumanMessageChunk,
SystemMessage,
)
from langchain.schema.output import ChatGeneration
from langchain_core.messages import HumanMessage, HumanMessageChunk, SystemMessage
from langchain_core.outputs import ChatGeneration

try:
from pydantic.v1 import BaseModel
Expand Down
31 changes: 22 additions & 9 deletions tests/unit_tests/test_server_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,33 @@
from fastapi import APIRouter, Depends, FastAPI, Header, HTTPException, Request
from fastapi.testclient import TestClient
from httpx import AsyncClient
from langchain.callbacks.tracers.log_stream import RunLog, RunLogPatch
from langchain.prompts import PromptTemplate
from langchain.prompts.base import StringPromptValue
from langchain.schema.messages import HumanMessage, SystemMessage
from langchain.schema.runnable import Runnable, RunnableConfig, RunnablePassthrough
from langchain.schema.runnable.base import RunnableLambda
from langchain.schema.runnable.utils import ConfigurableField, Input, Output
from langchain_core.chat_history import BaseChatMessageHistory
from langchain_core.documents import Document
from langchain_core.messages import AIMessage, AIMessageChunk, BaseMessage
from langchain_core.messages import (
AIMessage,
AIMessageChunk,
BaseMessage,
HumanMessage,
SystemMessage,
)
from langchain_core.output_parsers import StrOutputParser
from langchain_core.outputs import ChatGenerationChunk, LLMResult
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_core.prompt_values import StringPromptValue
from langchain_core.prompts import (
ChatPromptTemplate,
MessagesPlaceholder,
PromptTemplate,
)
from langchain_core.runnables import (
ConfigurableField,
Runnable,
RunnableConfig,
RunnableLambda,
RunnablePassthrough,
)
from langchain_core.runnables.history import RunnableWithMessageHistory
from langchain_core.runnables.utils import Input, Output
from langchain_core.tracers import RunLog, RunLogPatch
from langsmith import schemas as ls_schemas
from pytest import MonkeyPatch
from pytest_mock import MockerFixture
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import pytest
from fastapi import Request
from langchain.prompts import PromptTemplate
from langchain.schema.runnable.utils import ConfigurableField
from langchain_core.prompts import PromptTemplate
from langchain_core.runnables import ConfigurableField

from langserve.api_handler import _unpack_request_config

Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/utils/tracer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Dict, List
from uuid import UUID

from langchain.callbacks.tracers.base import BaseTracer
from langchain_core.tracers import BaseTracer
from langsmith.schemas import Run


Expand Down
Loading