Skip to content

Commit

Permalink
openai only; fix ineffectual assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
danielchalef committed Nov 12, 2023
1 parent d6955ca commit 63e30a8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
28 changes: 9 additions & 19 deletions pkg/search/perpetual.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func (m *MultiQuestionSummaryRetriever) Run(ctx context.Context) ([]models.Summa
ctx, cancel := context.WithTimeout(ctx, PerpetualMemoryTimeOut)
defer cancel()

if m.Service != "openai" {
return nil, errors.New("PerpetualMemory only supports OpenAI at this time")
}

questions, err := m.generateQuestions(ctx)
if err != nil {
return nil, fmt.Errorf("failed to generate questions: %w", err)
Expand All @@ -64,7 +68,7 @@ func (m *MultiQuestionSummaryRetriever) search(
ctx context.Context,
questions []string,
) ([]models.Summary, error) {
pool := pool.NewWithResults[[]models.MemorySearchResult]().WithContext(ctx).
searchPool := pool.NewWithResults[[]models.MemorySearchResult]().WithContext(ctx).
WithCancelOnError().
WithFirstError()

Expand Down Expand Up @@ -93,11 +97,11 @@ func (m *MultiQuestionSummaryRetriever) search(

for _, question := range questions {
question := question
pool.Go(func(ctx context.Context) ([]models.MemorySearchResult, error) {
searchPool.Go(func(ctx context.Context) ([]models.MemorySearchResult, error) {
return searchQuestion(question)
})
}
results, err := pool.Wait()
results, err := searchPool.Wait()
if err != nil {
return nil, fmt.Errorf("failed to search summaries: %w", err)
}
Expand Down Expand Up @@ -137,14 +141,7 @@ func (m *MultiQuestionSummaryRetriever) generateQuestions(ctx context.Context) (
}
m.History = m.generateHistoryString()

switch m.Service {
case "openai":
return m.generateQuestionsOpenAI(ctx)
//case "anthropic":
// return m.generateQuestionsAnthropic()
}

return nil, errors.New("unsupported service")
return m.generateQuestionsOpenAI(ctx)
}

func (m *MultiQuestionSummaryRetriever) generateQuestionsOpenAI(
Expand Down Expand Up @@ -203,14 +200,7 @@ func (m *MultiQuestionSummaryRetriever) reduce(
return models.Summary{}, errors.New("no summaries provided")
}

switch m.Service {
case "openai":
return m.reduceOpenAI(ctx, summaries)
//case "anthropic":
// return m.reduceAnthropic(summaries)
}

return models.Summary{}, errors.New("unsupported service")
return m.reduceOpenAI(ctx, summaries)
}

func (m *MultiQuestionSummaryRetriever) reduceOpenAI(
Expand Down
1 change: 0 additions & 1 deletion pkg/server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
)

const ReadHeaderTimeout = 5 * time.Second
const OtelTracerNamer = "chi-server"
const RouterName = "router"

var log = internal.GetLogger()
Expand Down
2 changes: 1 addition & 1 deletion pkg/store/postgres/get_memory_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func getPerpetualMemory(
config.SessionID,
appState.Config.Memory.MessageWindow,
nil,
config.LastNMessages,
lastNMessages,
)
if err != nil {
return nil, fmt.Errorf("failed to get messages: %w", err)
Expand Down

0 comments on commit 63e30a8

Please sign in to comment.