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

Add base_url #87

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 14 additions & 7 deletions libs/cohere/langchain_cohere/rerank.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class CohereRerank(BaseDocumentCompressor):
COHERE_API_KEY."""
user_agent: str = "langchain:partner"
"""Identifier for the application making the request."""
base_url: Optional[str] = None
"""Override the default Cohere API URL."""

class Config:
"""Configuration for this pydantic object."""
Expand All @@ -34,13 +36,18 @@ class Config:
@root_validator()
def validate_environment(cls, values: Dict) -> Dict:
"""Validate that api key and python package exists in environment."""
if not values.get("client"):
cohere_api_key = get_from_dict_or_env(
values, "cohere_api_key", "COHERE_API_KEY"
)
client_name = values["user_agent"]
values["client"] = cohere.Client(cohere_api_key, client_name=client_name)
return values
cohere_api_key = get_from_dict_or_env(
values, "cohere_api_key", "COHERE_API_KEY"
)
request_timeout = values.get("request_timeout")

client_name = values["user_agent"]
values["client"] = cohere.Client(
cohere_api_key,
timeout=request_timeout,
client_name=client_name,
base_url=values["base_url"],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want to do values.get() because base_url is optional.

)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you want to return values here? could be wrong


@root_validator()
def validate_model_specified(cls, values: Dict) -> Dict:
Expand Down
Loading