Skip to content

Commit

Permalink
⏺️ migrate to langchain_core abstractions
Browse files Browse the repository at this point in the history
  • Loading branch information
shroominic committed Dec 15, 2023
1 parent cdd6692 commit 4848be8
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 43 deletions.
10 changes: 4 additions & 6 deletions src/funcchain/_llms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
from pathlib import Path
from typing import Any, Dict, Iterator, List, Optional, Union

from langchain.callbacks.manager import CallbackManagerForLLMRun
from langchain.chat_models.base import BaseChatModel
from langchain.schema import ChatResult
from langchain.schema.messages import AIMessage, AIMessageChunk, BaseMessage, ChatMessage, HumanMessage, SystemMessage
from langchain.schema.output import ChatGeneration, ChatGenerationChunk
from langchain_core.language_models import BaseLanguageModel
from langchain_core.callbacks.manager import CallbackManagerForLLMRun
from langchain_core.language_models import BaseChatModel, BaseLanguageModel
from langchain_core.messages import AIMessage, AIMessageChunk, BaseMessage, ChatMessage, HumanMessage, SystemMessage
from langchain_core.outputs import ChatGeneration, ChatGenerationChunk, ChatResult
from langchain_core.pydantic_v1 import Field, root_validator
from langchain_core.utils import get_pydantic_field_names
from langchain_core.utils.utils import build_extra_kwargs
Expand Down
10 changes: 5 additions & 5 deletions src/funcchain/chain/creation.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from types import UnionType
from typing import TypeVar, Union

from langchain.chat_models.base import BaseChatModel
from langchain.prompts import ChatPromptTemplate
from langchain.schema import AIMessage, BaseMessage, BaseOutputParser, HumanMessage
from langchain.schema.chat_history import BaseChatMessageHistory
from langchain.schema.runnable import RunnableSequence, RunnableSerializable, RunnableWithFallbacks
from langchain_core.chat_models.base import BaseChatModel
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.schema import AIMessage, BaseMessage, BaseOutputParser, HumanMessage
from langchain_core.schema.chat_history import BaseChatMessageHistory
from langchain_core.schema.runnable import RunnableSequence, RunnableSerializable, RunnableWithFallbacks
from PIL import Image
from pydantic import BaseModel

Expand Down
5 changes: 3 additions & 2 deletions src/funcchain/chain/interface.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import TypeVar

from langchain.memory import ChatMessageHistory
from langchain.schema import BaseMessage, BaseOutputParser
from langchain.schema.chat_history import BaseChatMessageHistory
from langchain_core.chat_history import BaseChatMessageHistory
from langchain_core.messages import BaseMessage
from langchain_core.output_parsers import BaseOutputParser

from ..settings import SettingsOverride, get_settings
from .invoke import ainvoke, invoke
Expand Down
7 changes: 4 additions & 3 deletions src/funcchain/chain/invoke.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import TypeVar

from langchain.callbacks.base import Callbacks
from langchain.schema import BaseMessage, BaseOutputParser
from langchain.schema.chat_history import BaseChatMessageHistory
from langchain_core.callbacks.base import Callbacks
from langchain_core.chat_history import BaseChatMessageHistory
from langchain_core.messages import BaseMessage
from langchain_core.output_parsers import BaseOutputParser

from ..settings import FuncchainSettings
from ..utils.decorators import get_parent_frame, log_openai_callback, retry_parse
Expand Down
10 changes: 5 additions & 5 deletions src/funcchain/chain/prompt.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from string import Formatter
from typing import Any, Optional, Type

from langchain.prompts import ChatPromptTemplate
from langchain.prompts.chat import BaseStringMessagePromptTemplate, MessagePromptTemplateT
from langchain.prompts.prompt import PromptTemplate
from langchain.schema import BaseMessage, HumanMessage, SystemMessage
from langchain.schema.chat_history import BaseChatMessageHistory
from langchain_core.chat_history import BaseChatMessageHistory
from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.prompts.chat import BaseStringMessagePromptTemplate, MessagePromptTemplateT
from langchain_core.prompts.prompt import PromptTemplate
from PIL import Image
from pydantic import BaseModel

Expand Down
4 changes: 2 additions & 2 deletions src/funcchain/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any

from langchain.schema.messages import BaseMessage
from langchain.schema.output_parser import OutputParserException
from langchain_core.exceptions import OutputParserException
from langchain_core.messages import BaseMessage


class ParsingRetryException(OutputParserException):
Expand Down
6 changes: 4 additions & 2 deletions src/funcchain/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import re
from typing import Callable, Optional, Type, TypeVar

from langchain.schema import AIMessage, ChatGeneration, Generation, OutputParserException
from langchain.schema.output_parser import BaseGenerationOutputParser, BaseOutputParser
from langchain_core.exceptions import OutputParserException
from langchain_core.messages import AIMessage
from langchain_core.output_parsers import BaseGenerationOutputParser, BaseOutputParser
from langchain_core.outputs import ChatGeneration, Generation
from pydantic import BaseModel, ValidationError

from .exceptions import ParsingRetryException
Expand Down
6 changes: 3 additions & 3 deletions src/funcchain/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from typing import Optional, TypedDict

from langchain.cache import InMemoryCache
from langchain.chat_models.base import BaseChatModel
from langchain.globals import set_llm_cache
from langchain.schema.runnable import RunnableWithFallbacks
from langchain_core.globals import set_llm_cache
from langchain_core.language_models import BaseChatModel
from langchain_core.runnables import RunnableWithFallbacks
from pydantic import Field
from pydantic_settings import BaseSettings

Expand Down
8 changes: 4 additions & 4 deletions src/funcchain/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from typing import Any, AsyncGenerator, Awaitable, Callable, Coroutine, Generator
from uuid import UUID

from langchain.callbacks.base import AsyncCallbackHandler
from langchain.schema.messages import BaseMessage
from langchain.schema.output import ChatGenerationChunk, GenerationChunk, LLMResult
from langchain_core.callbacks.base import AsyncCallbackHandler
from langchain_core.messages import BaseMessage
from langchain_core.outputs import ChatGenerationChunk, GenerationChunk, LLMResult


class AsyncStreamHandler(AsyncCallbackHandler):
"""Async callback handler that can be used to handle callbacks from langchain."""
"""Async callback handler that can be used to handle callbacks from langchain_core."""

def __init__(
self, fn: Callable[[str], Awaitable[None] | None], default_kwargs: dict
Expand Down
4 changes: 2 additions & 2 deletions src/funcchain/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import Optional

from langchain.output_parsers.format_instructions import PYDANTIC_FORMAT_INSTRUCTIONS
from langchain.schema import OutputParserException
from langchain.schema.output_parser import BaseOutputParser
from langchain_core.exceptions import OutputParserException
from langchain_core.output_parsers import BaseOutputParser
from pydantic import BaseModel, Field
from typing_extensions import Self

Expand Down
6 changes: 3 additions & 3 deletions src/funcchain/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

from langchain.callbacks import get_openai_callback
from langchain.callbacks.openai_info import OpenAICallbackHandler
from langchain.schema import AIMessage
from langchain.schema.chat_history import BaseChatMessageHistory
from langchain.schema.output_parser import OutputParserException
from langchain_core.chat_history import BaseChatMessageHistory
from langchain_core.exceptions import OutputParserException
from langchain_core.messages import AIMessage
from rich import print

from ..exceptions import ParsingRetryException
Expand Down
2 changes: 1 addition & 1 deletion src/funcchain/utils/function_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from inspect import FrameInfo, currentframe, getouterframes
from typing import Union

from langchain.schema import BaseOutputParser, StrOutputParser
from langchain_core.output_parsers import BaseOutputParser, StrOutputParser

from ..parser import BoolOutputParser, ParserBaseModel, PydanticOutputParser

Expand Down
7 changes: 3 additions & 4 deletions src/funcchain/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

from docstring_parser import parse
from langchain.chat_models import ChatOpenAI
from langchain.chat_models.base import BaseChatModel
from langchain.schema.language_model import BaseLanguageModel
from langchain.schema.messages import HumanMessage, SystemMessage
from langchain.schema.runnable import Runnable, RunnableWithFallbacks
from langchain_core.language_models import BaseChatModel, BaseLanguageModel
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_core.runnables import Runnable, RunnableWithFallbacks
from pydantic import BaseModel
from tiktoken import encoding_for_model

Expand Down
2 changes: 1 addition & 1 deletion src/funcchain/utils/model_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Any

from langchain.chat_models import AzureChatOpenAI, ChatAnthropic, ChatGooglePalm, ChatOpenAI
from langchain.chat_models.base import BaseChatModel
from langchain_core.language_models import BaseChatModel

from .._llms import ChatLlamaCpp
from ..settings import FuncchainSettings
Expand Down

0 comments on commit 4848be8

Please sign in to comment.