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

list index out of range error using DeepSeek #23

Open
ThomasCosyn opened this issue Jan 31, 2025 · 0 comments
Open

list index out of range error using DeepSeek #23

ThomasCosyn opened this issue Jan 31, 2025 · 0 comments

Comments

@ThomasCosyn
Copy link

ThomasCosyn commented Jan 31, 2025

Hello,

I tried to integrate a DeepSeek model deployed on Azure with AzureAIChatCompletionsModel, but I get the error

File site-packages\langchain_azure_ai\chat_models\inference.py", line 500, in _stream  
choice = chunk.choices[0]  
IndexError : list index out of range

I guess the API sometimes sends a response with a choices empty list. We could check the size of the list before getting the first item ?

        self,
        messages: List[BaseMessage],
        stop: Optional[List[str]] = None,
        run_manager: Optional[CallbackManagerForLLMRun] = None,
        **kwargs: Any,
    ) -> Iterator[ChatGenerationChunk]:
        inference_messages = to_inference_message(messages)
        default_chunk_class = AIMessageChunk
        response = self._client.complete(
            messages=inference_messages,
            stream=True,
            stop=stop or self.stop,
            **self._identifying_params,
            **kwargs,
        )
        for chunk in response:
            if len(chunk.choices) > 0:
                choice = chunk.choices[0]
                chunk = _convert_delta_to_message_chunk(choice.delta, default_chunk_class)
                finish_reason = choice.finish_reason
                generation_info = (
                    dict(finish_reason=finish_reason) if finish_reason is not None else None
                )
                default_chunk_class = chunk.__class__  # type: ignore[assignment]
                cg_chunk = ChatGenerationChunk(
                    message=chunk, generation_info=generation_info
                )
                if run_manager:
                    run_manager.on_llm_new_token(cg_chunk.text, chunk=cg_chunk)
                yield cg_chunk```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant