pub struct Generation<'a> { /* private fields */ }
Implementations§
Source§impl<'a> Generation<'a>
impl<'a> Generation<'a>
pub fn new(client: &'a Client) -> Self
Sourcepub async fn call(&self, request: GenerationParam) -> Result<GenerationOutput>
pub async fn call(&self, request: GenerationParam) -> Result<GenerationOutput>
Sourcepub async fn call_stream(
&self,
request: GenerationParam,
) -> Result<GenerationOutputStream>
pub async fn call_stream( &self, request: GenerationParam, ) -> Result<GenerationOutputStream>
异步调用生成流函数
此函数用于处理文本生成的流式请求。流式请求意味着响应会随着时间的推移逐步返回, 而不是一次性返回所有内容。这对于需要实时处理生成内容的场景特别有用。
§参数
request
: 一个可变的GenerationParam
类型对象,包含了生成文本所需的参数。
§返回
返回一个 Result
类型,包含一个 GenerationOutputStream
对象,用于接收生成的文本流。
如果 request
中的 stream
字段为 Some(false)
,则返回一个 DashScopeError::InvalidArgument
错误,
提示用户应使用 Generation::call
函数而不是 call_stream
。
§错误处理
如果 request
参数中的 stream
属性为 Some(false)
,表示用户不希望使用流式处理,
函数将返回一个错误,提示用户应使用非流式处理的 call
方法。
§注意
该函数自动将 request
的 stream
属性设置为 Some(true)
,确保总是以流式处理方式执行生成任务。
Auto Trait Implementations§
impl<'a> Freeze for Generation<'a>
impl<'a> !RefUnwindSafe for Generation<'a>
impl<'a> Send for Generation<'a>
impl<'a> Sync for Generation<'a>
impl<'a> Unpin for Generation<'a>
impl<'a> !UnwindSafe for Generation<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more