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

混元SDK怎么处理异常捕获? #289

Open
unfish opened this issue Dec 22, 2023 · 0 comments
Open

混元SDK怎么处理异常捕获? #289

unfish opened this issue Dec 22, 2023 · 0 comments

Comments

@unfish
Copy link

unfish commented Dec 22, 2023

代码:
public async IAsyncEnumerable<(ResultType resultType, string result)> SendMessageStream(ApiChatInput input)
{
Credential cred = new Credential {
SecretId = SecretId,
SecretKey = SecretKey
};
HunyuanClient _client = new HunyuanClient(cred, "ap-guangzhou");
var req = new ChatProRequest()
{
Messages = GetMsgBody(input)
};
var resp = await _client.ChatPro(req);
foreach (var sse in resp)
{
var o = JObject.Parse(sse.Data);
yield return (ResultType.Answer, o["Choices"][0]["Delta"]["Content"].Value());
}
}
在IAsyncEnumerable类型的方法内部不允许使用try catch,但如果这个请求过程中出现参数错误之类的它又会直接抛出异常,我如何获取到请求异常后的Message呢?比如地域不支持,或者余额不足之类的。

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