forked from danielmiessler/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding flag for pinning seed in openai and compatible APIs
- Loading branch information
1 parent
f4044cd
commit a619c91
Showing
6 changed files
with
149 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package openai | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/danielmiessler/fabric/common" | ||
"github.com/sashabaranov/go-openai" | ||
goopenai "github.com/sashabaranov/go-openai" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBuildChatCompletionRequestPinSeed(t *testing.T) { | ||
|
||
var msgs []*common.Message | ||
|
||
for i := 0; i < 2; i++ { | ||
msgs = append(msgs, &common.Message{ | ||
Role: "User", | ||
Content: "My msg", | ||
}) | ||
} | ||
|
||
opts := &common.ChatOptions{ | ||
Temperature: 0.8, | ||
TopP: 0.9, | ||
PresencePenalty: 0.1, | ||
FrequencyPenalty: 0.2, | ||
Raw: false, | ||
Seed: 1, | ||
} | ||
|
||
var expectedMessages []openai.ChatCompletionMessage | ||
|
||
for i := 0; i < 2; i++ { | ||
expectedMessages = append(expectedMessages, | ||
openai.ChatCompletionMessage{ | ||
Role: msgs[i].Role, | ||
Content: msgs[i].Content, | ||
}, | ||
) | ||
} | ||
|
||
var expectedRequest = goopenai.ChatCompletionRequest{ | ||
Model: opts.Model, | ||
Temperature: float32(opts.Temperature), | ||
TopP: float32(opts.TopP), | ||
PresencePenalty: float32(opts.PresencePenalty), | ||
FrequencyPenalty: float32(opts.FrequencyPenalty), | ||
Messages: expectedMessages, | ||
Seed: &opts.Seed, | ||
} | ||
|
||
var client = NewClient() | ||
request := client.buildChatCompletionRequest(msgs, opts) | ||
assert.Equal(t, expectedRequest, request) | ||
} | ||
|
||
func TestBuildChatCompletionRequestNilSeed(t *testing.T) { | ||
|
||
var msgs []*common.Message | ||
|
||
for i := 0; i < 2; i++ { | ||
msgs = append(msgs, &common.Message{ | ||
Role: "User", | ||
Content: "My msg", | ||
}) | ||
} | ||
|
||
opts := &common.ChatOptions{ | ||
Temperature: 0.8, | ||
TopP: 0.9, | ||
PresencePenalty: 0.1, | ||
FrequencyPenalty: 0.2, | ||
Raw: false, | ||
Seed: 0, | ||
} | ||
|
||
var expectedMessages []openai.ChatCompletionMessage | ||
|
||
for i := 0; i < 2; i++ { | ||
expectedMessages = append(expectedMessages, | ||
openai.ChatCompletionMessage{ | ||
Role: msgs[i].Role, | ||
Content: msgs[i].Content, | ||
}, | ||
) | ||
} | ||
|
||
var expectedRequest = goopenai.ChatCompletionRequest{ | ||
Model: opts.Model, | ||
Temperature: float32(opts.Temperature), | ||
TopP: float32(opts.TopP), | ||
PresencePenalty: float32(opts.PresencePenalty), | ||
FrequencyPenalty: float32(opts.FrequencyPenalty), | ||
Messages: expectedMessages, | ||
Seed: nil, | ||
} | ||
|
||
var client = NewClient() | ||
request := client.buildChatCompletionRequest(msgs, opts) | ||
assert.Equal(t, expectedRequest, request) | ||
} |