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

fix: model name validation when using custom model #214

Merged
merged 1 commit into from
Oct 5, 2023
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
1 change: 0 additions & 1 deletion pkg/extractors/intent_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func (ee *IntentExtractor) processMessage(
}

// Put the intent into the message metadata
log.Debugf("IntentExtractor: intentResponse: %+v", intentResponse)
err = appState.MemoryStore.PutMessageMetadata(
ctx,
appState,
Expand Down
3 changes: 2 additions & 1 deletion pkg/extractors/summarizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/getzep/zep/pkg/models"
)

const MaxTokensFallback = 2048
const SummaryMaxOutputTokens = 1024

// Force compiler to validate that Extractor implements the MemoryStore interface.
Expand Down Expand Up @@ -146,7 +147,7 @@ func summarize(
}
maxTokens, ok := llms.MaxLLMTokensMap[modelName]
if !ok {
return &models.Summary{}, fmt.Errorf("model name not found in MaxLLMTokensMap")
maxTokens = MaxTokensFallback
}

if promptTokens == 0 {
Expand Down
9 changes: 9 additions & 0 deletions pkg/llms/llm_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func NewLLMClient(ctx context.Context, cfg *config.Config) (models.ZepLLM, error
}
return NewOpenAILLM(ctx, cfg)
}
// if custom OpenAI Endpoint is set, do not validate model name
if cfg.LLM.OpenAIEndpoint != "" {
return NewOpenAILLM(ctx, cfg)
}
// Otherwise, validate model name
if _, ok := ValidOpenAILLMs[cfg.LLM.Model]; !ok {
return nil, fmt.Errorf(
"invalid llm model \"%s\" for %s",
Expand Down Expand Up @@ -113,6 +118,10 @@ var MaxLLMTokensMap = map[string]int{

func GetLLMModelName(cfg *config.Config) (string, error) {
llmModel := cfg.LLM.Model
// only validate model name if OpenAI endpoint is not set
if cfg.LLM.OpenAIEndpoint != "" {
return llmModel, nil
}
if llmModel == "" || !ValidLLMMap[llmModel] {
return "", NewLLMError(InvalidLLMModelError, nil)
}
Expand Down
Loading