Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ZixinYang committed Sep 14, 2023
1 parent 1ff7ca2 commit 93a8759
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions libs/langchain/langchain/chat_models/fireworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
def _convert_delta_to_message_chunk(
_dict: Mapping[str, Any], default_class: type[BaseMessageChunk]
) -> BaseMessageChunk:
"""Convert a delta response to a message chunk."""
role = _dict.role
content = _dict.content or ""
additional_kwargs = {}
Expand All @@ -52,6 +53,7 @@ def _convert_delta_to_message_chunk(


def convert_dict_to_message(_dict: Mapping[str, Any]) -> BaseMessage:
"""Convert a dict response to a message."""
role = _dict.role
content = _dict.content or ""
if role == "user":
Expand All @@ -78,7 +80,7 @@ class ChatFireworks(BaseChatModel):

@root_validator()
def validate_environment(cls, values: Dict) -> Dict:
"""Validate that api key and python package exists in environment."""
"""Validate that api key in environment."""
fireworks_api_key = get_from_dict_or_env(
values, "fireworks_api_key", "FIREWORKS_API_KEY"
)
Expand Down Expand Up @@ -234,7 +236,7 @@ async def acompletion_with_retry_streaming(
run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,
**kwargs: Any,
) -> Any:
"""Use tenacity to retry the async completion call."""
"""Use tenacity to retry the completion call for streaming."""
retry_decorator = _create_retry_decorator(llm, run_manager=run_manager)

@retry_decorator
Expand All @@ -252,6 +254,7 @@ def _create_retry_decorator(
Union[AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun]
] = None,
) -> Callable[[Any], Any]:
"""Define retry mechanism."""
errors = [
fireworks.client.error.RateLimitError,
fireworks.client.error.ServiceUnavailableError,
Expand Down
7 changes: 5 additions & 2 deletions libs/langchain/langchain/llms/fireworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Fireworks(LLM):

@root_validator()
def validate_environment(cls, values: Dict) -> Dict:
"""Validate that api key and python package exists in environment."""
"""Validate that api key in environment."""
fireworks_api_key = get_from_dict_or_env(
values, "fireworks_api_key", "FIREWORKS_API_KEY"
)
Expand All @@ -55,6 +55,7 @@ def _call(
run_manager: Optional[CallbackManagerForLLMRun] = None,
**kwargs: Any,
) -> str:
"""Run the LLM on the given prompt and input."""
params = {
"model": self.model,
"prompt": prompt,
Expand All @@ -71,6 +72,7 @@ async def _acall(
run_manager: Optional[CallbackManagerForLLMRun] = None,
**kwargs: Any,
) -> str:
"""Run the LLM on the given prompt and input."""
params = {
"model": self.model,
"prompt": prompt,
Expand Down Expand Up @@ -190,7 +192,7 @@ async def acompletion_with_retry_streaming(
run_manager: Optional[CallbackManagerForLLMRun] = None,
**kwargs: Any,
) -> Any:
"""Use tenacity to retry the completion call."""
"""Use tenacity to retry the completion call for streaming."""
retry_decorator = _create_retry_decorator(llm, run_manager=run_manager)

@retry_decorator
Expand All @@ -208,6 +210,7 @@ def _create_retry_decorator(
Union[AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun]
] = None,
) -> Callable[[Any], Any]:
"""Define retry mechanism."""
errors = [
fireworks.client.error.RateLimitError,
fireworks.client.error.ServiceUnavailableError,
Expand Down

0 comments on commit 93a8759

Please sign in to comment.