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

如何捕获错误信息 #15

Open
dxxjing opened this issue Feb 11, 2025 · 0 comments
Open

如何捕获错误信息 #15

dxxjing opened this issue Feb 11, 2025 · 0 comments

Comments

@dxxjing
Copy link

dxxjing commented Feb 11, 2025

userId := "123"
	botId = strings.TrimSpace(botId)
	autoSaveHistory := false
	stream := true
	chatReq := coze.CreateChatsReq{
		ConversationID: "",
		BotID:          botId,
		UserID:         userId,
		Messages: []*coze.Message{
			coze.BuildUserQuestionText(prompt, nil),
		},
		Stream:          &stream,
		CustomVariables: nil,
		AutoSaveHistory: &autoSaveHistory,
		MetaData:        nil,
	}
var result string
resp, err := uc.components.ChineseCoze.Chat.Stream(ctx, &chatReq)
if err != nil {
		return "", err
	}
defer resp.Close()
	var tokenCount int
	for {
		event, err := resp.Recv()
		if errors.Is(err, io.EOF) { // finished
			break
		}
		if err != nil { 
			return "", err
		}
		if event.Event == coze.ChatEventConversationChatCompleted {
			tokenCount = event.Chat.Usage.TokenCount
		} else if event.Event == coze.ChatEventConversationMessageCompleted {
			if event.Message.Type == coze.MessageTypeAnswer {
				result = event.Message.Content
			}
		}
	}
fmt.Println(result)

最后打印result 如下:
[702112104] System Internal Error:Our system encountered an unexpected internal error. This is usually a temporary issue and should be resolved quickly.Please:Wait for a moment and try your operation again.If the problem persists, try refreshing the page or logging in again.Our technical team has received an alert and is actively working on resolving the issue.We apologize for any inconvenience. If the issue continues, please contact customer support.

判断err 仍然捕获不到这个错误信息,请问这个错误如何正常处理?

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