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

SetMemory() not available for ollama. #7

Open
MukulManni opened this issue Aug 17, 2024 · 2 comments
Open

SetMemory() not available for ollama. #7

MukulManni opened this issue Aug 17, 2024 · 2 comments

Comments

@MukulManni
Copy link

I tried to use gollm.SetMemory(4000) with ollama. But it gave, no encoding for model llama3-un error. (llama3-un is the name of model)

Code:

llm, err := gollm.NewLLM(
		gollm.SetProvider("ollama"),
		gollm.SetModel("llama3-un"),
		gollm.SetDebugLevel(gollm.LogLevelWarn),
		gollm.SetMemory(400),
	)

Output:

2024/08/17 14:08:18 ERROR: Failed to create LLM with memory [error failed to get encoding for model: no encoding for model llama3-un]
2024/08/17 14:08:18 Failed to create LLM: failed to create LLM with memory: failed to get encoding for model: no encoding for model llama3-un
exit status 1

I searched the docs and found that some kind of encoding is being used to make memory and the encodings are only available for openai models.

Can there be a way to use memory in ollama models.

@MukulManni
Copy link
Author

I think to add memory in a models, we have to know it's prompt, which is different for different models.
So to use memory in open source models, we have to provide the prompts on which the model was trained.
In gollm if we somehow add an option to provide prompt, then we can maybe add memory in open source models like in ollama,
or otherwise simply write code with prompts to use memory in the model.

@teilomillet
Copy link
Owner

Thank you MukulManni,

The error likely comes from the internal/memory.go, for the NewMemory function.

I suspect it's is because we use github.com/pkoukk/tiktoken-go under the hood and it's a tokenizer for openai models, then logically not recognizing llama3.1.

I guess we could default to a gpt-4o models in the case of an error, this would still be better than nothing, except if you can find a tokenizer for llama3.1 models.

The change looks like :

func NewMemory(maxTokens int, model string, logger Logger) (*Memory, error) {
encoding, err := tiktoken.EncodingForModel(model)
if err != nil {
logger.Warn("Failed to get encoding for model, defaulting to gpt-4o", "model", model, "error", err)
encoding, err = tiktoken.EncodingForModel("gpt-4o")
if err != nil {
return nil, fmt.Errorf("failed to get default encoding: %v", err)
}
}

return &Memory{
	messages:  []Message{},
	maxTokens: maxTokens,
	encoding:  encoding,
	logger:    logger,
}, nil

}


I just pushed the change, can you confirm it's working on your side as well ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants