Skip to content

Commit

Permalink
Use gpt4-o-mini by default and filter out </output> tags (#266)
Browse files Browse the repository at this point in the history
* Use gpt4-o-mini by default to lower costs.
* gpt4-o-mini is more than an order of magnitude cheaper than gpt4-o

  * .15 / million input tokens vs $5 / million input tokens
  * .6 / million output tokens vs $15 / million output tokens

* In the case where OAI can't determine an apporpriate command it often
just outputs the output tag </output>. This is sometimes included in a
code block so our postprocessing doesn't remove it and turn it into an
empty response

* Fix the post-processing to remove this.

Fix #264
  • Loading branch information
jlewi authored Sep 30, 2024
1 parent f22b0ba commit 238e04f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
17 changes: 14 additions & 3 deletions app/pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,14 +556,25 @@ func postProcessBlocks(blocks []*v1alpha1.Block) ([]*v1alpha1.Block, error) {
// Post process the blocks
results := make([]*v1alpha1.Block, 0, len(blocks))
for _, block := range blocks {
if block.GetKind() == v1alpha1.BlockKind_CODE {
results = append(results, block)
return results, nil
if block.GetKind() != v1alpha1.BlockKind_CODE {
continue
}
// The model sometimes returns just the "</output>" tag but inside a coude block.
// We want to ignore such blocks.
if isOutputTag(block.Contents) {
continue
}
results = append(results, block)
return results, nil
}
return results, nil
}

func isOutputTag(contents string) bool {
trimmed := strings.TrimSpace(contents)
return trimmed == "</output>"
}

// streamState is a structure to keep track of the state for a stream and deal with concurrency
// It provides thread safe access to shared state.
type streamState struct {
Expand Down
35 changes: 35 additions & 0 deletions app/pkg/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"testing"
"time"

"github.com/google/go-cmp/cmp"

"github.com/sashabaranov/go-openai"

parserv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/parser/v1"
Expand Down Expand Up @@ -340,3 +342,36 @@ func Test_ShouldTrigger(t *testing.T) {
})
}
}

func Test_PostProcessBlocks(t *testing.T) {
type testCase struct {
name string
blocks []*v1alpha1.Block
expected []*v1alpha1.Block
}

cases := []testCase{
{
name: "output-tag-in-codeblocks",
blocks: []*v1alpha1.Block{
{
Kind: v1alpha1.BlockKind_CODE,
Contents: "</output>",
},
},
expected: []*v1alpha1.Block{},
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
actual, err := postProcessBlocks(c.blocks)
if err != nil {
t.Fatalf("Error post processing blocks; %v", err)
}
if d := cmp.Diff(c.expected, actual); d != "" {
t.Errorf("Unexpected diff:\n%s", d)
}
})
}
}
2 changes: 1 addition & 1 deletion app/pkg/config/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package config

import "github.com/sashabaranov/go-openai"

const DefaultModel = openai.GPT4o
const DefaultModel = openai.GPT4oMini

0 comments on commit 238e04f

Please sign in to comment.