Skip to content

"Get context window" detection fails; fallback to 4096 #319

@ML-CSI

Description

@ML-CSI

When chatting with my transcription I get an error message like this:

"Transcript alone exceeds model context limit (5601 tokens > 4096). Please use a model with larger context window."

disclaimer: I'm new to Scriberr, Github and also writing issues; English is not my main language; doing my best anyway ;)
Please ask if infos are missing :) I'm willing to help as best as possible!

this issue is in a way related to #287 (but not the same!)

I tried all of them with OpenAI as provider in settings

  • a) my local OpenWebUI instance's API
  • b) OpenRouter
  • c) groq
  • d) Google AI Studio

...in all the cases I got the same error message above
This indicates that the context window is not detected properly from those platforms.

I checked the code of Scriberr for the error message and found this:
(Scriberr-main\internal\api\chat_handlers.go)

// Get context window
	contextWindow, err := svc.GetContextWindow(c.Request.Context(), session.Model)
	if err != nil {
		fmt.Printf("Failed to get context window for model %s: %v. Using default 4096.\n", session.Model, err)
		contextWindow = 4096
	}

It defaults back to 4096 (maybe because of the old default value of Ollama?)
This explains my problems as later in the code it looks like this (same file as mentioned above)

	// Final check - if still over limit after trimming all possible messages, return error
	if currentTokenCount > contextWindow {
		c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("Transcript alone exceeds model context limit (%d tokens > %d). Please use a model with larger context window.", currentTokenCount, contextWindow)})
		return
	}

This equals my error message.

So what could be a solution? Defaulting for a higher context window? 4096 isnt a reasonable setting for running a LLM anyway ;)
Another solutIution? dont know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Projects

    Status

    Planned

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions