This commit is contained in:
@@ -34,17 +34,11 @@ func (s *SensitiveWordUtil) InitDetector() error {
|
||||
detector, err := swd.New()
|
||||
if err != nil {
|
||||
s.initErr = err
|
||||
// 只有在global.GVA_LOG不为nil时才记录日志
|
||||
if global.GVA_LOG != nil {
|
||||
global.GVA_LOG.Error("Failed to initialize sensitive word detector", zap.Error(err))
|
||||
}
|
||||
global.GVA_LOG.Error("Failed to initialize sensitive word detector", zap.Error(err))
|
||||
return
|
||||
}
|
||||
s.detector = detector
|
||||
// 只有在global.GVA_LOG不为nil时才记录日志
|
||||
if global.GVA_LOG != nil {
|
||||
global.GVA_LOG.Info("Sensitive word detector initialized successfully")
|
||||
}
|
||||
global.GVA_LOG.Info("Sensitive word detector initialized successfully")
|
||||
})
|
||||
return s.initErr
|
||||
}
|
||||
|
||||
@@ -98,18 +98,14 @@ func (v *VolcengineLLMUtil) InitClient() error {
|
||||
// 验证配置
|
||||
if config.ApiKey == "" {
|
||||
v.initErr = fmt.Errorf("volcengine api key is empty")
|
||||
if global.GVA_LOG != nil {
|
||||
global.GVA_LOG.Error("Volcengine configuration error", zap.Error(v.initErr))
|
||||
}
|
||||
global.GVA_LOG.Error("Volcengine configuration error", zap.Error(v.initErr))
|
||||
return
|
||||
}
|
||||
|
||||
// 创建ARK Runtime客户端,使用API Key
|
||||
v.client = arkruntime.NewClientWithApiKey(config.ApiKey)
|
||||
|
||||
if global.GVA_LOG != nil {
|
||||
global.GVA_LOG.Info("Volcengine LLM client initialized successfully")
|
||||
}
|
||||
global.GVA_LOG.Info("Volcengine LLM client initialized successfully")
|
||||
})
|
||||
return v.initErr
|
||||
}
|
||||
@@ -165,9 +161,7 @@ func (v *VolcengineLLMUtil) ChatCompletion(req LLMRequest) (*LLMResponse, error)
|
||||
// 调用API
|
||||
resp, err := v.client.CreateChatCompletion(context.Background(), chatReq)
|
||||
if err != nil {
|
||||
if global.GVA_LOG != nil {
|
||||
global.GVA_LOG.Error("Chat completion failed", zap.Error(err), zap.String("requestID", req.RequestID))
|
||||
}
|
||||
global.GVA_LOG.Error("Chat completion failed", zap.Error(err), zap.String("requestID", req.RequestID))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -199,9 +193,7 @@ func (v *VolcengineLLMUtil) ChatCompletion(req LLMRequest) (*LLMResponse, error)
|
||||
Usage: usage,
|
||||
}
|
||||
|
||||
if global.GVA_LOG != nil {
|
||||
global.GVA_LOG.Info("Chat completion successful", zap.String("requestID", req.RequestID))
|
||||
}
|
||||
global.GVA_LOG.Info("Chat completion successful", zap.String("requestID", req.RequestID))
|
||||
return chatResp, nil
|
||||
}
|
||||
|
||||
@@ -264,16 +256,12 @@ func (v *VolcengineLLMUtil) StreamChatCompletion(req LLMRequest, eventChan chan<
|
||||
// 调用流式API
|
||||
stream_resp, err := v.client.CreateChatCompletionStream(ctx, chatReq)
|
||||
if err != nil {
|
||||
if global.GVA_LOG != nil {
|
||||
global.GVA_LOG.Error("Stream chat completion failed", zap.Error(err), zap.String("requestID", req.RequestID))
|
||||
}
|
||||
global.GVA_LOG.Error("Stream chat completion failed", zap.Error(err), zap.String("requestID", req.RequestID))
|
||||
return err
|
||||
}
|
||||
defer stream_resp.Close()
|
||||
|
||||
if global.GVA_LOG != nil {
|
||||
global.GVA_LOG.Info("Stream chat completion started", zap.String("requestID", req.RequestID))
|
||||
}
|
||||
global.GVA_LOG.Info("Stream chat completion started", zap.String("requestID", req.RequestID))
|
||||
|
||||
// 处理流式响应
|
||||
for {
|
||||
@@ -293,14 +281,10 @@ func (v *VolcengineLLMUtil) StreamChatCompletion(req LLMRequest, eventChan chan<
|
||||
Object: "chat.completion.chunk",
|
||||
},
|
||||
}
|
||||
if global.GVA_LOG != nil {
|
||||
global.GVA_LOG.Info("Stream chat completion finished", zap.String("requestID", req.RequestID))
|
||||
}
|
||||
global.GVA_LOG.Info("Stream chat completion finished", zap.String("requestID", req.RequestID))
|
||||
return nil
|
||||
}
|
||||
if global.GVA_LOG != nil {
|
||||
global.GVA_LOG.Error("Stream receive error", zap.Error(err), zap.String("requestID", req.RequestID))
|
||||
}
|
||||
global.GVA_LOG.Error("Stream receive error", zap.Error(err), zap.String("requestID", req.RequestID))
|
||||
eventChan <- LLMStreamEvent{
|
||||
Event: "error",
|
||||
Data: LLMResponse{
|
||||
@@ -359,9 +343,7 @@ func (v *VolcengineLLMUtil) StopGeneration(requestID string) error {
|
||||
if cancelFunc, ok := cancel.(context.CancelFunc); ok {
|
||||
cancelFunc()
|
||||
v.activeSessions.Delete(requestID)
|
||||
if global.GVA_LOG != nil {
|
||||
global.GVA_LOG.Info("Generation stopped", zap.String("requestID", requestID))
|
||||
}
|
||||
global.GVA_LOG.Info("Generation stopped", zap.String("requestID", requestID))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user