Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
yaksh0nti authored Jun 19, 2024
2 parents 96699f0 + 710197e commit 55abc04
Show file tree
Hide file tree
Showing 37 changed files with 50 additions and 3,751 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, Union

import sqlalchemy as sa
from sqlalchemy.engine import RowMapping
from sqlalchemy.sql.expression import Select

from langchain_community.docstore.document import Document
from langchain_community.document_loaders.base import BaseLoader
Expand All @@ -19,7 +20,7 @@ class SQLDatabaseLoader(BaseLoader):

def __init__(
self,
query: Union[str, sa.Select],
query: Union[str, Select],
db: SQLDatabase,
*,
parameters: Optional[Dict[str, Any]] = None,
Expand Down Expand Up @@ -106,7 +107,7 @@ def lazy_load(self) -> Iterator[Document]:

@staticmethod
def page_content_default_mapper(
row: sa.RowMapping, column_names: Optional[List[str]] = None
row: RowMapping, column_names: Optional[List[str]] = None
) -> str:
"""
A reasonable default function to convert a record into a "page content" string.
Expand All @@ -121,7 +122,7 @@ def page_content_default_mapper(

@staticmethod
def metadata_default_mapper(
row: sa.RowMapping, column_names: Optional[List[str]] = None
row: RowMapping, column_names: Optional[List[str]] = None
) -> Dict[str, Any]:
"""
A reasonable default function to convert a record into a "metadata" dictionary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Keys can be listed based on the updated at field.
* Keys can be deleted.
"""

import contextlib
import decimal
import uuid
Expand All @@ -29,9 +30,7 @@
)

from sqlalchemy import (
URL,
Column,
Engine,
Float,
Index,
String,
Expand All @@ -42,15 +41,21 @@
select,
text,
)
from sqlalchemy.engine import URL, Engine
from sqlalchemy.ext.asyncio import (
AsyncEngine,
AsyncSession,
async_sessionmaker,
create_async_engine,
)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session, sessionmaker

try:
from sqlalchemy.ext.asyncio import async_sessionmaker
except ImportError:
# dummy for sqlalchemy < 2
async_sessionmaker = type("async_sessionmaker", (type,), {}) # type: ignore

from langchain_community.indexes.base import RecordManager

Base = declarative_base()
Expand Down
8 changes: 7 additions & 1 deletion libs/community/langchain_community/vectorstores/pgvector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import numpy as np
import sqlalchemy
from langchain_core._api import deprecated, warn_deprecated
from sqlalchemy import SQLColumnExpression, delete, func
from sqlalchemy import delete, func
from sqlalchemy.dialects.postgresql import JSON, JSONB, UUID
from sqlalchemy.orm import Session, relationship

Expand All @@ -29,6 +29,12 @@
except ImportError:
from sqlalchemy.ext.declarative import declarative_base

try:
from sqlalchemy import SQLColumnExpression
except ImportError:
# for sqlalchemy < 2
SQLColumnExpression = Any # type: ignore

from langchain_core.documents import Document
from langchain_core.embeddings import Embeddings
from langchain_core.runnables.config import run_in_executor
Expand Down
15 changes: 11 additions & 4 deletions libs/community/tests/unit_tests/chat_message_histories/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@
import pytest
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage
from sqlalchemy import Column, Integer, Text
from sqlalchemy.orm import DeclarativeBase

try:
from sqlalchemy.orm import DeclarativeBase

class Base(DeclarativeBase):
pass
except ImportError:
# for sqlalchemy < 2
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base() # type:ignore

from langchain_community.chat_message_histories import SQLChatMessageHistory
from langchain_community.chat_message_histories.sql import DefaultMessageConverter
Expand Down Expand Up @@ -198,9 +208,6 @@ async def test_async_clear_messages(


def test_model_no_session_id_field_error(con_str: str) -> None:
class Base(DeclarativeBase):
pass

class Model(Base):
__tablename__ = "test_table"
id = Column(Integer, primary_key=True)
Expand Down
13 changes: 9 additions & 4 deletions libs/community/tests/unit_tests/test_sql_database.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# flake8: noqa: E501
"""Test SQL database wrapper."""

import pytest
import sqlalchemy as sa
from packaging import version
from sqlalchemy import (
Column,
Integer,
MetaData,
Result,
String,
Table,
Text,
insert,
select,
)
from sqlalchemy.engine import Engine, Result

from langchain_community.utilities.sql_database import SQLDatabase, truncate_word

is_sqlalchemy_v1 = version.parse(sa.__version__).major == 1

metadata_obj = MetaData()

user = Table(
Expand All @@ -35,18 +39,18 @@


@pytest.fixture
def engine() -> sa.Engine:
def engine() -> Engine:
return sa.create_engine("sqlite:///:memory:")


@pytest.fixture
def db(engine: sa.Engine) -> SQLDatabase:
def db(engine: Engine) -> SQLDatabase:
metadata_obj.create_all(engine)
return SQLDatabase(engine)


@pytest.fixture
def db_lazy_reflection(engine: sa.Engine) -> SQLDatabase:
def db_lazy_reflection(engine: Engine) -> SQLDatabase:
metadata_obj.create_all(engine)
return SQLDatabase(engine, lazy_table_reflection=True)

Expand Down Expand Up @@ -230,6 +234,7 @@ def test_sql_database_run_update(db: SQLDatabase) -> None:
assert output == expected_output


@pytest.mark.skipif(is_sqlalchemy_v1, reason="Requires SQLAlchemy 2 or newer")
def test_sql_database_schema_translate_map() -> None:
"""Verify using statement-specific execution options."""

Expand Down
11 changes: 8 additions & 3 deletions libs/langchain/langchain/indexes/_sql_record_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
* Keys can be listed based on the updated at field.
* Keys can be deleted.
"""

import contextlib
import decimal
import uuid
from typing import Any, AsyncGenerator, Dict, Generator, List, Optional, Sequence, Union

from langchain_core.indexing import RecordManager
from sqlalchemy import (
URL,
Column,
Engine,
Float,
Index,
String,
Expand All @@ -33,15 +32,21 @@
select,
text,
)
from sqlalchemy.engine import URL, Engine
from sqlalchemy.ext.asyncio import (
AsyncEngine,
AsyncSession,
async_sessionmaker,
create_async_engine,
)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Query, Session, sessionmaker

try:
from sqlalchemy.ext.asyncio import async_sessionmaker
except ImportError:
# dummy for sqlalchemy < 2
async_sessionmaker = type("async_sessionmaker", (type,), {}) # type: ignore

Base = declarative_base()


Expand Down
21 changes: 0 additions & 21 deletions libs/partners/upstage/LICENSE

This file was deleted.

57 changes: 0 additions & 57 deletions libs/partners/upstage/Makefile

This file was deleted.

26 changes: 2 additions & 24 deletions libs/partners/upstage/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
# langchain-upstage
This package has moved!

This package contains the LangChain integrations for [Upstage](https://upstage.ai) through their [APIs](https://developers.upstage.ai/docs/getting-started/models).

## Installation and Setup

- Install the LangChain partner package
```bash
pip install -U langchain-upstage
```

- Get an Upstage api key from [Upstage Console](https://console.upstage.ai/home) and set it as an environment variable (`UPSTAGE_API_KEY`)

## Chat Models

This package contains the `ChatUpstage` class, which is the recommended way to interface with Upstage models.

See a [usage example](https://python.langchain.com/docs/integrations/chat/upstage)

## Embeddings

See a [usage example](https://python.langchain.com/docs/integrations/text_embedding/upstage)

Use `solar-embedding-1-large` model for embeddings. Do not add suffixes such as `-query` or `-passage` to the model name.
`UpstageEmbeddings` will automatically add the suffixes based on the method called.
https://github.com/langchain-ai/langchain-upstage/tree/main/libs/upstage
17 changes: 0 additions & 17 deletions libs/partners/upstage/langchain_upstage/__init__.py

This file was deleted.

Loading

0 comments on commit 55abc04

Please sign in to comment.