Skip to content

Commit

Permalink
fix more typing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
abraham-leal committed Dec 16, 2024
1 parent f503c5a commit f6f56bc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions weave/integrations/langchain/langchain_nvidia_ai_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from typing import TYPE_CHECKING, Any, Callable, Optional

if TYPE_CHECKING:
from langchain_core.messages import AIMessageChunk, convert_to_openai_messages
from openai.types.chat import ChatCompletion
pass

import weave
from weave.trace.op import Op, ProcessedInputs
Expand All @@ -16,6 +15,7 @@

# NVIDIA-specific accumulator for parsing the objects of streaming interactions
def nvidia_accumulator(acc: Optional[Any], value: Any) -> Any:
from langchain_core.messages import AIMessageChunk
from langchain_core.outputs import ChatGenerationChunk

if acc is None:
Expand All @@ -31,7 +31,9 @@ def nvidia_accumulator(acc: Optional[Any], value: Any) -> Any:

# Post processor to transform output into OpenAI's ChatCompletion format -- need to handle stream and non-stream outputs
def post_process_to_openai_format(output: Any) -> dict:
from langchain_core.messages import convert_to_openai_messages
from langchain_core.outputs import ChatGenerationChunk, ChatResult
from openai.types.chat import ChatCompletion

if isinstance(output, ChatResult): ## its ChatResult
message = output.llm_output ## List of ChatGeneration
Expand Down Expand Up @@ -112,6 +114,8 @@ def post_process_to_openai_format(output: Any) -> dict:
def process_inputs_to_openai_format_stream(
func: Op, args: tuple, kwargs: dict
) -> ProcessedInputs | None:
from langchain_core.messages import convert_to_openai_messages

original_args = args
original_kwargs = kwargs

Expand Down Expand Up @@ -143,6 +147,8 @@ def process_inputs_to_openai_format_stream(
def process_inputs_to_openai_format(
func: Op, args: tuple, kwargs: dict
) -> ProcessedInputs | None:
from langchain_core.messages import convert_to_openai_messages

original_args = args
original_kwargs = kwargs

Expand Down

0 comments on commit f6f56bc

Please sign in to comment.