diff --git a/util/ai/ai.go b/util/ai/ai.go index 1b02693592..c7dcfef8f2 100644 --- a/util/ai/ai.go +++ b/util/ai/ai.go @@ -28,7 +28,7 @@ var ( ) type AI interface { - WritingTools(ctx context.Context, params *pb.RpcAIWritingToolsRequest) (result, error) + WritingTools(ctx context.Context, params *pb.RpcAIWritingToolsRequest) (Result, error) app.ComponentRunnable } @@ -54,7 +54,7 @@ type PromptConfig struct { JSONMode bool } -type result struct { +type Result struct { Answer string } @@ -78,7 +78,7 @@ func (ai *AIService) Close(_ context.Context) (err error) { return nil } -func (ai *AIService) WritingTools(ctx context.Context, params *pb.RpcAIWritingToolsRequest) (result, error) { +func (ai *AIService) WritingTools(ctx context.Context, params *pb.RpcAIWritingToolsRequest) (Result, error) { ai.mu.Lock() defer ai.mu.Unlock() @@ -95,7 +95,7 @@ func (ai *AIService) WritingTools(ctx context.Context, params *pb.RpcAIWritingTo if language, exists := detector.DetectLanguageOf(text); !exists { log.Errorf("unsupported language detected: %s", language) - return result{}, fmt.Errorf("%w: %s", ErrUnsupportedLanguage, language) + return Result{}, fmt.Errorf("%w: %s", ErrUnsupportedLanguage, language) } } @@ -117,18 +117,18 @@ func (ai *AIService) WritingTools(ctx context.Context, params *pb.RpcAIWritingTo answer, err := ai.chat(context.Background()) if err != nil { - return result{}, err + return Result{}, err } // extract answer value from json response, except for default mode if params.Mode != 0 { extractedAnswer, err := ai.extractAnswerByMode(answer) if err != nil { - return result{}, err + return Result{}, err } - return result{Answer: extractedAnswer}, nil + return Result{Answer: extractedAnswer}, nil } - return result{Answer: answer}, nil + return Result{Answer: answer}, nil } diff --git a/util/ai/ai_test.go b/util/ai/ai_test.go index d8a82576d2..13177e0e19 100644 --- a/util/ai/ai_test.go +++ b/util/ai/ai_test.go @@ -25,7 +25,7 @@ func TestWritingTools(t *testing.T) { tests := []struct { name string params *pb.RpcAIWritingToolsRequest - validateResult func(t *testing.T, result result, err error) + validateResult func(t *testing.T, result Result, err error) }{ { name: "SupportedLanguage", @@ -39,7 +39,7 @@ func TestWritingTools(t *testing.T) { Temperature: 0.1, Text: "This is a test.", }, - validateResult: func(t *testing.T, result result, err error) { + validateResult: func(t *testing.T, result Result, err error) { assert.NoError(t, err) }, }, @@ -55,7 +55,7 @@ func TestWritingTools(t *testing.T) { Temperature: 0.1, Text: "Съешь ещё этих мягких французских булок, да выпей же чаю. Впрочем, одних слов недостаточно для демонстрации эффекта, но этот текст подходит для большинства задач. Здесь можно написать что угодно, и никто не обратит внимания на содержание.", }, - validateResult: func(t *testing.T, result result, err error) { + validateResult: func(t *testing.T, result Result, err error) { assert.Error(t, err) assert.True(t, errors.Is(err, ErrUnsupportedLanguage)) }, @@ -72,7 +72,7 @@ func TestWritingTools(t *testing.T) { Temperature: 0.1, Text: "Can you use an invalid endpoint?", }, - validateResult: func(t *testing.T, result result, err error) { + validateResult: func(t *testing.T, result Result, err error) { assert.Error(t, err) assert.True(t, errors.Is(err, ErrEndpointNotReachable)) }, @@ -89,7 +89,7 @@ func TestWritingTools(t *testing.T) { Temperature: 0.1, Text: "Can you use an invalid model?", }, - validateResult: func(t *testing.T, result result, err error) { + validateResult: func(t *testing.T, result Result, err error) { assert.Error(t, err) assert.True(t, errors.Is(err, ErrModelNotFound)) }, @@ -106,7 +106,7 @@ func TestWritingTools(t *testing.T) { Temperature: 0.1, Text: "Can you use an invalid token?", }, - validateResult: func(t *testing.T, result result, err error) { + validateResult: func(t *testing.T, result Result, err error) { assert.Error(t, err) assert.True(t, errors.Is(err, ErrAuthRequired)) }, @@ -123,7 +123,7 @@ func TestWritingTools(t *testing.T) { Temperature: 0, Text: "What is the capital of France?", }, - validateResult: func(t *testing.T, result result, err error) { + validateResult: func(t *testing.T, result Result, err error) { assert.NoError(t, err) assert.NotEmpty(t, result.Answer) assert.Contains(t, result.Answer, "Paris") @@ -141,7 +141,7 @@ func TestWritingTools(t *testing.T) { Temperature: 0, Text: "What is the capital of France?", }, - validateResult: func(t *testing.T, result result, err error) { + validateResult: func(t *testing.T, result Result, err error) { assert.NoError(t, err) assert.NotEmpty(t, result.Answer) assert.Contains(t, result.Answer, "Paris") @@ -159,7 +159,7 @@ func TestWritingTools(t *testing.T) { Temperature: 0, Text: "Countries, Capitals\nFrance, Paris\nGermany, Berlin", }, - validateResult: func(t *testing.T, result result, err error) { + validateResult: func(t *testing.T, result Result, err error) { assert.NoError(t, err) assert.NotEmpty(t, result.Answer) assert.Equal(t, "| Country | Capital |\n|----------|---------|\n| France | Paris |\n| Germany | Berlin |\n", result.Answer)