Skip to content

Commit

Permalink
feat: model intent
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmcguire1 committed Dec 15, 2023
1 parent ae0e585 commit 2546130
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
18 changes: 11 additions & 7 deletions internal/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,28 @@ func (h *Handler) randomFact(ctx context.Context) (string, error) {

func (h *Handler) DispatchIntents(ctx context.Context, req alexa.Request) (res alexa.Response, err error) {
switch req.Body.Intent.Name {
case alexa.AutoCompleteIntent:
prompt := req.Body.Intent.Slots["prompt"].Value
h.Logger.With("prompt", prompt).Info("found phrase to autocomplete")
case alexa.ModelIntent:
model := req.Body.Intent.Slots["chatModel"].Value
h.Logger.With("model", model).Info("found model to use")

switch strings.ToLower(prompt) {
case "use gemini":
switch strings.ToLower(model) {
case "gemini":
h.Model = chatmodels.CHAT_MODEL_GEMINI
res = alexa.NewResponse("Autocomplete", "ok", false)
return
case "use gpt":
case "gpt":
h.Model = chatmodels.CHAT_MODEL_GPT
res = alexa.NewResponse("Autocomplete", "ok", false)
return
case "what model", "what model is in use":
default:
res = alexa.NewResponse("Autocomplete", fmt.Sprintf("I am using the model %s", h.Model.String()), false)
return
}

case alexa.AutoCompleteIntent:
prompt := req.Body.Intent.Slots["prompt"].Value
h.Logger.With("prompt", prompt).Info("found phrase to autocomplete")

err = h.RequestsQueue.PushMessage(ctx, &chatmodels.Request{Prompt: prompt, Model: h.Model})
if err != nil {
break
Expand Down
37 changes: 37 additions & 0 deletions internal/api/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,43 @@ func TestHelpIntent(t *testing.T) {
assert.False(t, resp.Body.ShouldEndSession)
}

func TestModelIntent(t *testing.T) {
mockChatGptService := &chatmodels.MockClient{}
h := &Handler{
ChatGptService: mockChatGptService,
Logger: logger,
Model: chatmodels.CHAT_MODEL_GPT,
}

req := alexa.Request{
Version: "",
Session: alexa.Session{},
Body: alexa.ReqBody{
Intent: alexa.Intent{
Name: alexa.ModelIntent,
Slots: map[string]alexa.Slot{
"chatModel": {
Name: "chatModel",
Value: "gpt",
Resolutions: alexa.Resolutions{},
},
},
},
Type: alexa.IntentRequestType,
},
Context: alexa.Context{},
}

resp, err := h.Invoke(context.Background(), req)
assert.NoError(t, err)
assert.EqualValues(
t,
resp.Body.OutputSpeech.Text,
"ok",
)
assert.False(t, resp.Body.ShouldEndSession)
}

func TestUnsupportedIntent(t *testing.T) {
mockChatGptService := &chatmodels.MockClient{}
h := &Handler{
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/alexa/intents.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ const (
FallbackIntent = "AMAZON.FallbackIntent"
AutoCompleteIntent = "AutoCompleteIntent"
RandomFactIntent = "RandomFactIntent"
ModelIntent = "Model"
LastResponseIntent = "LastResponseIntent"
)

0 comments on commit 2546130

Please sign in to comment.