Abraxas-365 / Abraxas-365/langchain-rust
chain.stream should return None instead of Error when stream ends
- Langage dominant
- Rust
- Étoiles
- 1.3k
- Forks
- 177
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
Currently I need to write a lot of boilerplate code when the streaming has ended. this also means I need to add async_openai as dependeny.
```rust
let mut stream = chain.stream(input_variables).await?;
while let Some(result) = stream.next().await {
match &result {
Ok(data) => data.to_stdout()?,
Err(ChainError::LLMError(LLMError::OpenAIError(
OpenAIError::StreamError(e),
))) => {
if e == "Stream ended" {
break;
} else {
error!("OpenAI Error: {:?}", e);
break;
}
}
Err(e) => panic!("Errorx: {:?}", e),
}
}
```
This could be simplified to use `Result>`.
```rust
let mut stream = chain.stream(input_variables).await?;
while let Some(result) = stream.next().await {
match &result {
Ok(Some(data)) => data.to_stdout()?,
None => break,
Err(e) => panic!("Errorx: {:?}", e),
}
}
```
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.