From 3eaed9f310892736961ccfaf5e6ad8dc752c9755 Mon Sep 17 00:00:00 2001 From: Son Nguyen Date: Wed, 22 Nov 2023 14:55:56 +0700 Subject: [PATCH] Fix some typo and coding convention --- server/ai/anthropic/client.go | 8 ++++---- server/ai/asksage/asksage.go | 2 +- server/ai/asksage/client.go | 4 ++-- server/ai/conversation.go | 10 +++++----- server/ai/interfaces.go | 2 +- server/ai/openai/openai.go | 4 ++-- server/api_test.go | 32 ++++++++++++++++---------------- server/built_in_tools.go | 6 +++--- server/plugin_test.go | 12 ++++++------ server/service.go | 14 +++++++------- 10 files changed, 47 insertions(+), 47 deletions(-) diff --git a/server/ai/anthropic/client.go b/server/ai/anthropic/client.go index 3aeac802..b5bf4878 100644 --- a/server/ai/anthropic/client.go +++ b/server/ai/anthropic/client.go @@ -74,10 +74,10 @@ func (c *Client) CompletionNoStream(prompt string) (string, error) { if resp.StatusCode != http.StatusOK { body, err := ioutil.ReadAll(resp.Body) if err != nil { - return "", errors.Wrap(err, "unable to read responce body on error: "+resp.Status) + return "", errors.Wrap(err, "unable to read response body on error: "+resp.Status) } - return "", errors.New("non 200 responce from anthropic: " + resp.Status + "\nBody:\n" + string(body)) + return "", errors.New("non 200 response from anthropic: " + resp.Status + "\nBody:\n" + string(body)) } completionResponse := CompletionResponse{} @@ -126,11 +126,11 @@ func (c *Client) Completion(prompt string) (*ai.TextStreamResult, error) { if resp.StatusCode != http.StatusOK { body, err := ioutil.ReadAll(resp.Body) if err != nil { - errChan <- errors.Wrap(err, "unable to read responce body on error: "+resp.Status) + errChan <- errors.Wrap(err, "unable to read response body on error: "+resp.Status) return } - errChan <- errors.New("non 200 responce from anthropic: " + resp.Status + "\nBody:\n" + string(body)) + errChan <- errors.New("non 200 response from anthropic: " + resp.Status + "\nBody:\n" + string(body)) return } diff --git a/server/ai/asksage/asksage.go b/server/ai/asksage/asksage.go index f98f304f..acae48f8 100644 --- a/server/ai/asksage/asksage.go +++ b/server/ai/asksage/asksage.go @@ -85,7 +85,7 @@ func (s *AskSage) ChatCompletionNoStream(conversation ai.BotConversation, opts . return response.Message, nil } -// TODO: Implment actual token counting. For now just estimated based off OpenAI estimations +// TODO: Implement actual token counting. For now just estimated based off OpenAI estimations func (a *AskSage) CountTokens(text string) int { charCount := float64(len(text)) / 4.0 wordCount := float64(len(strings.Fields(text))) / 0.75 diff --git a/server/ai/asksage/client.go b/server/ai/asksage/client.go index d1b5efa5..fc978b82 100644 --- a/server/ai/asksage/client.go +++ b/server/ai/asksage/client.go @@ -167,10 +167,10 @@ func (c *Client) do(method, path string, body interface{}, result interface{}) e if resp.StatusCode != http.StatusOK { body, err := ioutil.ReadAll(resp.Body) if err != nil { - return errors.Wrap(err, "unable to read responce body on error: "+resp.Status) + return errors.Wrap(err, "unable to read response body on error: "+resp.Status) } - return errors.New("non 200 responce from asksage: " + resp.Status + "\nBody:\n" + string(body)) + return errors.New("non 200 response from asksage: " + resp.Status + "\nBody:\n" + string(body)) } // Decode response body into specified struct diff --git a/server/ai/conversation.go b/server/ai/conversation.go index 51148f6f..6143440a 100644 --- a/server/ai/conversation.go +++ b/server/ai/conversation.go @@ -33,12 +33,12 @@ type ConversationContext struct { PromptParameters map[string]string } -func NewConversationContext(reqeustingUser *model.User, channel *model.Channel, post *model.Post) ConversationContext { - // Get current time and date formated nicely with the user's locale +func NewConversationContext(requestingUser *model.User, channel *model.Channel, post *model.Post) ConversationContext { + // Get current time and date formatted nicely with the user's locale now := time.Now() nowString := now.Format(time.RFC1123) - if reqeustingUser != nil { - tz := reqeustingUser.GetPreferredTimezone() + if requestingUser != nil { + tz := requestingUser.GetPreferredTimezone() loc, err := time.LoadLocation(tz) if err != nil || loc == nil { loc = time.UTC @@ -47,7 +47,7 @@ func NewConversationContext(reqeustingUser *model.User, channel *model.Channel, } return ConversationContext{ Time: nowString, - RequestingUser: reqeustingUser, + RequestingUser: requestingUser, Channel: channel, Post: post, } diff --git a/server/ai/interfaces.go b/server/ai/interfaces.go index 2f24caae..8d223fba 100644 --- a/server/ai/interfaces.go +++ b/server/ai/interfaces.go @@ -20,7 +20,7 @@ func WithModel(model string) LanguageModelOption { } } -func WithmaxTokens(maxTokens int) LanguageModelOption { +func WithMaxTokens(maxTokens int) LanguageModelOption { return func(cfg *LLMConfig) { cfg.MaxTokens = maxTokens } diff --git a/server/ai/openai/openai.go b/server/ai/openai/openai.go index 1843d6eb..9041bc42 100644 --- a/server/ai/openai/openai.go +++ b/server/ai/openai/openai.go @@ -220,7 +220,7 @@ func (s *OpenAI) createConfig(opts []ai.LanguageModelOption) ai.LLMConfig { return cfg } -func (s *OpenAI) completionReqeustFromConfig(cfg ai.LLMConfig) openaiClient.ChatCompletionRequest { +func (s *OpenAI) completionRequestFromConfig(cfg ai.LLMConfig) openaiClient.ChatCompletionRequest { return openaiClient.ChatCompletionRequest{ Model: cfg.Model, MaxTokens: cfg.MaxTokens, @@ -232,7 +232,7 @@ func (s *OpenAI) completionReqeustFromConfig(cfg ai.LLMConfig) openaiClient.Chat } func (s *OpenAI) ChatCompletion(conversation ai.BotConversation, opts ...ai.LanguageModelOption) (*ai.TextStreamResult, error) { - request := s.completionReqeustFromConfig(s.createConfig(opts)) + request := s.completionRequestFromConfig(s.createConfig(opts)) request = modifyCompletionRequestWithConversation(request, conversation) request.Stream = true return s.streamResult(request, conversation) diff --git a/server/api_test.go b/server/api_test.go index 6cc2688a..ea5bfa1d 100644 --- a/server/api_test.go +++ b/server/api_test.go @@ -31,7 +31,7 @@ func TestPostRouter(t *testing.T) { request *http.Request expectedStatus int config Config - envSetup func(e *TestEnviroment) + envSetup func(e *TestEnvironment) }{ "test no permission to channel": { request: httptest.NewRequest("POST", url, nil), @@ -39,7 +39,7 @@ func TestPostRouter(t *testing.T) { config: Config{ EnableUseRestrictions: false, }, - envSetup: func(e *TestEnviroment) { + envSetup: func(e *TestEnvironment) { e.mockAPI.On("GetChannel", "channelid").Return(&model.Channel{ Id: "channelid", Type: model.ChannelTypeOpen, @@ -55,7 +55,7 @@ func TestPostRouter(t *testing.T) { EnableUseRestrictions: true, OnlyUsersOnTeam: "someotherteam", }, - envSetup: func(e *TestEnviroment) { + envSetup: func(e *TestEnvironment) { e.mockAPI.On("GetChannel", "channelid").Return(&model.Channel{ Id: "channelid", Type: model.ChannelTypeOpen, @@ -72,7 +72,7 @@ func TestPostRouter(t *testing.T) { EnableUseRestrictions: true, AllowedTeamIDs: "someteam", }, - envSetup: func(e *TestEnviroment) { + envSetup: func(e *TestEnvironment) { e.mockAPI.On("GetChannel", "channelid").Return(&model.Channel{ Id: "channelid", Type: model.ChannelTypeOpen, @@ -88,7 +88,7 @@ func TestPostRouter(t *testing.T) { EnableUseRestrictions: true, AllowPrivateChannels: false, }, - envSetup: func(e *TestEnviroment) { + envSetup: func(e *TestEnvironment) { e.mockAPI.On("HasPermissionToChannel", "userid", "channelid", model.PermissionReadChannel).Return(true) e.mockAPI.On("GetChannel", "channelid").Return(&model.Channel{ Id: "channelid", @@ -104,7 +104,7 @@ func TestPostRouter(t *testing.T) { EnableUseRestrictions: true, AllowPrivateChannels: false, }, - envSetup: func(e *TestEnviroment) { + envSetup: func(e *TestEnvironment) { e.mockAPI.On("HasPermissionToChannel", "userid", "channelid", model.PermissionReadChannel).Return(true) e.mockAPI.On("GetChannel", "channelid").Return(&model.Channel{ Id: "channelid", @@ -153,7 +153,7 @@ func TestTextRouter(t *testing.T) { request *http.Request expectedStatus int config Config - envSetup func(e *TestEnviroment) + envSetup func(e *TestEnvironment) }{ "test user not allowed": { request: httptest.NewRequest("POST", url, nil), @@ -162,7 +162,7 @@ func TestTextRouter(t *testing.T) { EnableUseRestrictions: true, OnlyUsersOnTeam: "someotherteam", }, - envSetup: func(e *TestEnviroment) { + envSetup: func(e *TestEnvironment) { e.mockAPI.On("HasPermissionToTeam", "userid", "someotherteam", model.PermissionViewTeam).Return(false) }, }, @@ -201,7 +201,7 @@ func TestAdminRouter(t *testing.T) { request *http.Request expectedStatus int config Config - envSetup func(e *TestEnviroment) + envSetup func(e *TestEnvironment) }{ "only admins": { request: httptest.NewRequest("GET", url, nil), @@ -209,7 +209,7 @@ func TestAdminRouter(t *testing.T) { config: Config{ EnableUseRestrictions: false, }, - envSetup: func(e *TestEnviroment) { + envSetup: func(e *TestEnvironment) { e.mockAPI.On("HasPermissionTo", "userid", model.PermissionManageSystem).Return(false) }, }, @@ -248,7 +248,7 @@ func TestChannelRouter(t *testing.T) { request *http.Request expectedStatus int config Config - envSetup func(e *TestEnviroment) + envSetup func(e *TestEnvironment) }{ "test no permission to channel": { request: httptest.NewRequest("POST", url, nil), @@ -256,7 +256,7 @@ func TestChannelRouter(t *testing.T) { config: Config{ EnableUseRestrictions: false, }, - envSetup: func(e *TestEnviroment) { + envSetup: func(e *TestEnvironment) { e.mockAPI.On("GetChannel", "channelid").Return(&model.Channel{ Id: "channelid", Type: model.ChannelTypeOpen, @@ -272,7 +272,7 @@ func TestChannelRouter(t *testing.T) { EnableUseRestrictions: true, OnlyUsersOnTeam: "someotherteam", }, - envSetup: func(e *TestEnviroment) { + envSetup: func(e *TestEnvironment) { e.mockAPI.On("GetChannel", "channelid").Return(&model.Channel{ Id: "channelid", Type: model.ChannelTypeOpen, @@ -289,7 +289,7 @@ func TestChannelRouter(t *testing.T) { EnableUseRestrictions: true, AllowedTeamIDs: "someteam", }, - envSetup: func(e *TestEnviroment) { + envSetup: func(e *TestEnvironment) { e.mockAPI.On("GetChannel", "channelid").Return(&model.Channel{ Id: "channelid", Type: model.ChannelTypeOpen, @@ -305,7 +305,7 @@ func TestChannelRouter(t *testing.T) { EnableUseRestrictions: true, AllowPrivateChannels: false, }, - envSetup: func(e *TestEnviroment) { + envSetup: func(e *TestEnvironment) { e.mockAPI.On("HasPermissionToChannel", "userid", "channelid", model.PermissionReadChannel).Return(true) e.mockAPI.On("GetChannel", "channelid").Return(&model.Channel{ Id: "channelid", @@ -321,7 +321,7 @@ func TestChannelRouter(t *testing.T) { EnableUseRestrictions: true, AllowPrivateChannels: false, }, - envSetup: func(e *TestEnviroment) { + envSetup: func(e *TestEnvironment) { e.mockAPI.On("HasPermissionToChannel", "userid", "channelid", model.PermissionReadChannel).Return(true) e.mockAPI.On("GetChannel", "channelid").Return(&model.Channel{ Id: "channelid", diff --git a/server/built_in_tools.go b/server/built_in_tools.go index f3bdb42b..bd449725 100644 --- a/server/built_in_tools.go +++ b/server/built_in_tools.go @@ -13,7 +13,7 @@ import ( ) type LookupMattermostUserArgs struct { - Username string `jsonschema_description:"The username of the user to lookup witout a leading '@'. Example: 'firstname.lastname'"` + Username string `jsonschema_description:"The username of the user to lookup without a leading '@'. Example: 'firstname.lastname'"` } func (p *Plugin) toolResolveLookupMattermostUser(context ai.ConversationContext, argsGetter ai.ToolArgumentGetter) (string, error) { @@ -149,7 +149,7 @@ func (p *Plugin) getBuiltInTools() []ai.Tool { builtInTools := []ai.Tool{ { Name: "LookupMattermostUser", - Description: "Lookup a Mattermost user by their username. Avalable information includes: username, full name, email, nickname, position, locale, timezone, last activity, and status.", + Description: "Lookup a Mattermost user by their username. Available information includes: username, full name, email, nickname, position, locale, timezone, last activity, and status.", Schema: LookupMattermostUserArgs{}, Resolver: p.toolResolveLookupMattermostUser, }, @@ -168,7 +168,7 @@ func (p *Plugin) getBuiltInTools() []ai.Tool { } else if status != nil && status.State == model.PluginStateRunning { builtInTools = append(builtInTools, ai.Tool{ Name: "GetGithubIssue", - Description: "Retrive a single GitHub issue by owner, repo, and issue number.", + Description: "Retrieve a single GitHub issue by owner, repo, and issue number.", Schema: GetGithubIssueArgs{}, Resolver: p.toolGetGithubIssue, }) diff --git a/server/plugin_test.go b/server/plugin_test.go index f11be1bb..aac0ff45 100644 --- a/server/plugin_test.go +++ b/server/plugin_test.go @@ -10,12 +10,12 @@ import ( "github.com/stretchr/testify/require" ) -type TestEnviroment struct { +type TestEnvironment struct { plugin *Plugin mockAPI *plugintest.API } -func SetupTestEnvironment(t *testing.T) *TestEnviroment { +func SetupTestEnvironment(t *testing.T) *TestEnvironment { p := Plugin{} p.botid = "botid" @@ -26,7 +26,7 @@ func SetupTestEnvironment(t *testing.T) *TestEnviroment { p.ffmpegPath = "" - e := &TestEnviroment{ + e := &TestEnvironment{ plugin: &p, } e.ResetMocks(t) @@ -34,13 +34,13 @@ func SetupTestEnvironment(t *testing.T) *TestEnviroment { return e } -func (e *TestEnviroment) ResetMocks(t *testing.T) { +func (e *TestEnvironment) ResetMocks(t *testing.T) { e.mockAPI = &plugintest.API{} e.plugin.SetAPI(e.mockAPI) e.plugin.pluginAPI = pluginapi.NewClient(e.plugin.API, e.plugin.Driver) } -func (e *TestEnviroment) Cleanup(t *testing.T) { +func (e *TestEnvironment) Cleanup(t *testing.T) { t.Helper() e.mockAPI.AssertExpectations(t) } @@ -267,7 +267,7 @@ func TestHandleAudioCallsRecording(t *testing.T) { require.ErrorIs(t, err, ErrUsageRestriction) }) - t.Run("don't respond if somone is trying to spoof the calls bot", func(t *testing.T) { + t.Run("don't respond if someone is trying to spoof the calls bot", func(t *testing.T) { e.ResetMocks(t) e.plugin.setConfiguration(makeConfig(Config{ EnableAutomaticCallsSummary: true, diff --git a/server/service.go b/server/service.go index e0d54cbb..fca432aa 100644 --- a/server/service.go +++ b/server/service.go @@ -53,7 +53,7 @@ func (p *Plugin) continueConversation(context ai.ConversationContext) error { return err } - // Special handing for threads started by the bot in responce to a summarization request. + // Special handing for threads started by the bot in response to a summarization request. var result *ai.TextStreamResult originalThreadID, ok := threadData.Posts[0].GetProp(ThreadIDProp).(string) if ok && originalThreadID != "" { @@ -169,12 +169,12 @@ func (p *Plugin) selectEmoji(postToReact *model.Post, context ai.ConversationCon return err } - emojiName, err := p.getLLM().ChatCompletionNoStream(prompt, ai.WithmaxTokens(25)) + emojiName, err := p.getLLM().ChatCompletionNoStream(prompt, ai.WithMaxTokens(25)) if err != nil { return err } - // Do some emoji post processing to hopfully make this an actual emoji. + // Do some emoji post processing to hopefully make this an actual emoji. emojiName = strings.Trim(strings.TrimSpace(emojiName), ":") if _, found := model.GetSystemEmojiId(emojiName); !found { @@ -207,7 +207,7 @@ func (p *Plugin) spellcheckMessage(message string) (*string, error) { return nil, err } - result, err := p.getLLM().ChatCompletionNoStream(prompt, ai.WithmaxTokens(128)) + result, err := p.getLLM().ChatCompletionNoStream(prompt, ai.WithMaxTokens(128)) if err != nil { return nil, err } @@ -225,7 +225,7 @@ func (p *Plugin) changeTone(tone, message string) (*string, error) { return nil, err } - result, err := p.getLLM().ChatCompletionNoStream(prompt, ai.WithmaxTokens(128)) + result, err := p.getLLM().ChatCompletionNoStream(prompt, ai.WithMaxTokens(128)) if err != nil { return nil, err } @@ -242,7 +242,7 @@ func (p *Plugin) simplifyText(message string) (*string, error) { return nil, err } - result, err := p.getLLM().ChatCompletionNoStream(prompt, ai.WithmaxTokens(128)) + result, err := p.getLLM().ChatCompletionNoStream(prompt, ai.WithMaxTokens(128)) if err != nil { return nil, err } @@ -260,7 +260,7 @@ func (p *Plugin) aiChangeText(ask, message string) (*string, error) { return nil, err } - result, err := p.getLLM().ChatCompletionNoStream(prompt, ai.WithmaxTokens(128)) + result, err := p.getLLM().ChatCompletionNoStream(prompt, ai.WithMaxTokens(128)) if err != nil { return nil, err }