mirror of
https://github.com/kardolus/chatgpt-cli.git
synced 2024-09-08 23:15:00 +03:00
Add thread based context management
This commit is contained in:
@@ -39,6 +39,7 @@ func New(caller http.Caller, cs config.ConfigStore, hs history.HistoryStore) (*C
|
||||
}
|
||||
|
||||
caller.SetAPIKey(configuration.APIKey)
|
||||
hs.SetThread(configuration.Thread)
|
||||
|
||||
return &Client{
|
||||
Config: configuration,
|
||||
|
||||
@@ -23,11 +23,12 @@ import (
|
||||
|
||||
const (
|
||||
defaultMaxTokens = 4096
|
||||
defaultURL = "https://api.openai.com"
|
||||
defaultURL = "https://default.openai.com"
|
||||
defaultName = "default-name"
|
||||
defaultModel = "gpt-3.5-turbo"
|
||||
defaultCompletionsPath = "/v1/chat/completions"
|
||||
defaultModelsPath = "/v1/models"
|
||||
defaultCompletionsPath = "/default/completions"
|
||||
defaultModelsPath = "/default/models"
|
||||
defaultThread = "default-thread"
|
||||
envApiKey = "api-key"
|
||||
)
|
||||
|
||||
@@ -230,6 +231,7 @@ func testClient(t *testing.T, when spec.G, it spec.S) {
|
||||
})
|
||||
it("ignores history when configured to do so", func() {
|
||||
mockCaller.EXPECT().SetAPIKey(envApiKey).Times(1)
|
||||
mockHistoryStore.EXPECT().SetThread(defaultThread).Times(1)
|
||||
mockConfigStore.EXPECT().Read().Return(types.Config{OmitHistory: true}, nil).Times(1)
|
||||
|
||||
subject, err := client.New(mockCaller, mockConfigStore, mockHistoryStore)
|
||||
@@ -484,6 +486,7 @@ func newClientFactory(mc *MockCaller, mcs *MockConfigStore, mhs *MockHistoryStor
|
||||
URL: defaultURL,
|
||||
CompletionsPath: defaultCompletionsPath,
|
||||
ModelsPath: defaultModelsPath,
|
||||
Thread: defaultThread,
|
||||
}).Times(1)
|
||||
|
||||
return &clientFactory{
|
||||
@@ -495,6 +498,7 @@ func newClientFactory(mc *MockCaller, mcs *MockConfigStore, mhs *MockHistoryStor
|
||||
|
||||
func (f *clientFactory) buildClientWithoutConfig() *client.Client {
|
||||
f.mockCaller.EXPECT().SetAPIKey(envApiKey).Times(1)
|
||||
f.mockHistoryStore.EXPECT().SetThread(defaultThread).Times(1)
|
||||
f.mockConfigStore.EXPECT().Read().Return(types.Config{}, nil).Times(1)
|
||||
|
||||
c, err := client.New(f.mockCaller, f.mockConfigStore, f.mockHistoryStore)
|
||||
@@ -505,6 +509,7 @@ func (f *clientFactory) buildClientWithoutConfig() *client.Client {
|
||||
|
||||
func (f *clientFactory) buildClientWithConfig(config types.Config) *client.Client {
|
||||
f.mockCaller.EXPECT().SetAPIKey(envApiKey).Times(1)
|
||||
f.mockHistoryStore.EXPECT().SetThread(defaultThread).Times(1)
|
||||
f.mockConfigStore.EXPECT().Read().Return(config, nil).Times(1)
|
||||
|
||||
c, err := client.New(f.mockCaller, f.mockConfigStore, f.mockHistoryStore)
|
||||
|
||||
@@ -63,6 +63,18 @@ func (mr *MockHistoryStoreMockRecorder) Read() *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockHistoryStore)(nil).Read))
|
||||
}
|
||||
|
||||
// SetThread mocks base method.
|
||||
func (m *MockHistoryStore) SetThread(arg0 string) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "SetThread", arg0)
|
||||
}
|
||||
|
||||
// SetThread indicates an expected call of SetThread.
|
||||
func (mr *MockHistoryStoreMockRecorder) SetThread(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetThread", reflect.TypeOf((*MockHistoryStore)(nil).SetThread), arg0)
|
||||
}
|
||||
|
||||
// Write mocks base method.
|
||||
func (m *MockHistoryStore) Write(arg0 []types.Message) error {
|
||||
m.ctrl.T.Helper()
|
||||
|
||||
Reference in New Issue
Block a user