mirror of
https://github.com/hwchase17/langchain.git
synced 2025-05-29 19:18:53 +00:00
parent
8ad3b255dc
commit
ff43cd6701
@ -53,7 +53,6 @@ from langchain.utils import (
|
|||||||
from langchain.utils.openai import is_openai_v1
|
from langchain.utils.openai import is_openai_v1
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import httpx
|
|
||||||
import tiktoken
|
import tiktoken
|
||||||
|
|
||||||
|
|
||||||
@ -201,10 +200,11 @@ class ChatOpenAI(BaseChatModel):
|
|||||||
"""Automatically inferred from env var `OPENAI_ORG_ID` if not provided."""
|
"""Automatically inferred from env var `OPENAI_ORG_ID` if not provided."""
|
||||||
# to support explicit proxy for OpenAI
|
# to support explicit proxy for OpenAI
|
||||||
openai_proxy: Optional[str] = None
|
openai_proxy: Optional[str] = None
|
||||||
request_timeout: Union[float, Tuple[float, float], httpx.Timeout, None] = Field(
|
request_timeout: Union[float, Tuple[float, float], Any, None] = Field(
|
||||||
default=None, alias="timeout"
|
default=None, alias="timeout"
|
||||||
)
|
)
|
||||||
"""Timeout for requests to OpenAI completion API. Default is 600 seconds."""
|
"""Timeout for requests to OpenAI completion API. Can be float, httpx.Timeout or
|
||||||
|
None."""
|
||||||
max_retries: int = 2
|
max_retries: int = 2
|
||||||
"""Maximum number of retries to make when generating."""
|
"""Maximum number of retries to make when generating."""
|
||||||
streaming: bool = False
|
streaming: bool = False
|
||||||
@ -227,7 +227,8 @@ class ChatOpenAI(BaseChatModel):
|
|||||||
default_query: Union[Mapping[str, object], None] = None
|
default_query: Union[Mapping[str, object], None] = None
|
||||||
# Configure a custom httpx client. See the
|
# Configure a custom httpx client. See the
|
||||||
# [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
|
# [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
|
||||||
http_client: Union[httpx.Client, None] = None
|
http_client: Union[Any, None] = None
|
||||||
|
"""Optional httpx.Client."""
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
"""Configuration for this pydantic object."""
|
"""Configuration for this pydantic object."""
|
||||||
|
@ -5,7 +5,6 @@ import os
|
|||||||
import warnings
|
import warnings
|
||||||
from importlib.metadata import version
|
from importlib.metadata import version
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
Dict,
|
Dict,
|
||||||
@ -35,9 +34,6 @@ from langchain.pydantic_v1 import BaseModel, Extra, Field, root_validator
|
|||||||
from langchain.schema.embeddings import Embeddings
|
from langchain.schema.embeddings import Embeddings
|
||||||
from langchain.utils import get_from_dict_or_env, get_pydantic_field_names
|
from langchain.utils import get_from_dict_or_env, get_pydantic_field_names
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
import httpx
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -207,10 +203,11 @@ class OpenAIEmbeddings(BaseModel, Embeddings):
|
|||||||
"""Maximum number of texts to embed in each batch"""
|
"""Maximum number of texts to embed in each batch"""
|
||||||
max_retries: int = 2
|
max_retries: int = 2
|
||||||
"""Maximum number of retries to make when generating."""
|
"""Maximum number of retries to make when generating."""
|
||||||
request_timeout: Optional[Union[float, Tuple[float, float], httpx.Timeout]] = Field(
|
request_timeout: Optional[Union[float, Tuple[float, float], Any]] = Field(
|
||||||
default=None, alias="timeout"
|
default=None, alias="timeout"
|
||||||
)
|
)
|
||||||
"""Timeout in seconds for the OpenAPI request."""
|
"""Timeout for requests to OpenAI completion API. Can be float, httpx.Timeout or
|
||||||
|
None."""
|
||||||
headers: Any = None
|
headers: Any = None
|
||||||
tiktoken_model_name: Optional[str] = None
|
tiktoken_model_name: Optional[str] = None
|
||||||
"""The model name to pass to tiktoken when using this class.
|
"""The model name to pass to tiktoken when using this class.
|
||||||
@ -233,7 +230,8 @@ class OpenAIEmbeddings(BaseModel, Embeddings):
|
|||||||
default_query: Union[Mapping[str, object], None] = None
|
default_query: Union[Mapping[str, object], None] = None
|
||||||
# Configure a custom httpx client. See the
|
# Configure a custom httpx client. See the
|
||||||
# [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
|
# [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
|
||||||
http_client: Union[httpx.Client, None] = None
|
http_client: Union[Any, None] = None
|
||||||
|
"""Optional httpx.Client."""
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
"""Configuration for this pydantic object."""
|
"""Configuration for this pydantic object."""
|
||||||
|
@ -25,7 +25,19 @@ from tests.unit_tests.callbacks.fake_callback_handler import FakeCallbackHandler
|
|||||||
@pytest.mark.scheduled
|
@pytest.mark.scheduled
|
||||||
def test_chat_openai() -> None:
|
def test_chat_openai() -> None:
|
||||||
"""Test ChatOpenAI wrapper."""
|
"""Test ChatOpenAI wrapper."""
|
||||||
chat = ChatOpenAI(max_tokens=10)
|
chat = ChatOpenAI(
|
||||||
|
temperature=0.7,
|
||||||
|
base_url=None,
|
||||||
|
organization=None,
|
||||||
|
openai_proxy=None,
|
||||||
|
timeout=10.0,
|
||||||
|
max_retries=3,
|
||||||
|
http_client=None,
|
||||||
|
n=1,
|
||||||
|
max_tokens=10,
|
||||||
|
default_headers=None,
|
||||||
|
default_query=None,
|
||||||
|
)
|
||||||
message = HumanMessage(content="Hello")
|
message = HumanMessage(content="Hello")
|
||||||
response = chat([message])
|
response = chat([message])
|
||||||
assert isinstance(response, BaseMessage)
|
assert isinstance(response, BaseMessage)
|
||||||
|
Loading…
Reference in New Issue
Block a user