use openai_organization as argument (#2566)

Added support for passing the openai_organization as an argument, as it
was only supported by the environment variable but openai_api_key was
supported by both environment variables and arguments.

`ChatOpenAI(temperature=0, model_name="gpt-4", openai_api_key="sk-****",
openai_organization="org-****")`
This commit is contained in:
Shishin Mo 2023-04-08 14:02:02 +09:00 committed by GitHub
parent 544cc7f395
commit f7f118e021
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 5 additions and 0 deletions

View File

@ -31,6 +31,7 @@ class OpenAIModerationChain(Chain):
input_key: str = "input" #: :meta private: input_key: str = "input" #: :meta private:
output_key: str = "output" #: :meta private: output_key: str = "output" #: :meta private:
openai_api_key: Optional[str] = None openai_api_key: Optional[str] = None
openai_organization: Optional[str] = None
@root_validator() @root_validator()
def validate_environment(cls, values: Dict) -> Dict: def validate_environment(cls, values: Dict) -> Dict:

View File

@ -44,6 +44,7 @@ class AzureChatOpenAI(ChatOpenAI):
openai_api_base: str = "" openai_api_base: str = ""
openai_api_version: str = "" openai_api_version: str = ""
openai_api_key: str = "" openai_api_key: str = ""
openai_organization: str = ""
@root_validator() @root_validator()
def validate_environment(cls, values: Dict) -> Dict: def validate_environment(cls, values: Dict) -> Dict:

View File

@ -115,6 +115,7 @@ class ChatOpenAI(BaseChatModel):
model_kwargs: Dict[str, Any] = Field(default_factory=dict) model_kwargs: Dict[str, Any] = Field(default_factory=dict)
"""Holds any model parameters valid for `create` call not explicitly specified.""" """Holds any model parameters valid for `create` call not explicitly specified."""
openai_api_key: Optional[str] = None openai_api_key: Optional[str] = None
openai_organization: Optional[str] = None
request_timeout: int = 60 request_timeout: int = 60
"""Timeout in seconds for the OpenAPI request.""" """Timeout in seconds for the OpenAPI request."""
max_retries: int = 6 max_retries: int = 6

View File

@ -98,6 +98,7 @@ class OpenAIEmbeddings(BaseModel, Embeddings):
query_model_name: str = "text-embedding-ada-002" query_model_name: str = "text-embedding-ada-002"
embedding_ctx_length: int = 8191 embedding_ctx_length: int = 8191
openai_api_key: Optional[str] = None openai_api_key: Optional[str] = None
openai_organization: Optional[str] = None
chunk_size: int = 1000 chunk_size: int = 1000
"""Maximum number of texts to embed in each batch""" """Maximum number of texts to embed in each batch"""
max_retries: int = 6 max_retries: int = 6

View File

@ -151,6 +151,7 @@ class BaseOpenAI(BaseLLM):
model_kwargs: Dict[str, Any] = Field(default_factory=dict) model_kwargs: Dict[str, Any] = Field(default_factory=dict)
"""Holds any model parameters valid for `create` call not explicitly specified.""" """Holds any model parameters valid for `create` call not explicitly specified."""
openai_api_key: Optional[str] = None openai_api_key: Optional[str] = None
openai_organization: Optional[str] = None
batch_size: int = 20 batch_size: int = 20
"""Batch size to use when passing multiple documents to generate.""" """Batch size to use when passing multiple documents to generate."""
request_timeout: Optional[Union[float, Tuple[float, float]]] = None request_timeout: Optional[Union[float, Tuple[float, float]]] = None