Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gpt4-o-mini by default and filter out </output> tags #266

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading