Ollama Modelfile with Adapter

Contents

Ollama Modelfile with Adapter#

Now that we’ve finetuned a model and created an adapter, we’ll add it to the model to be able to use it.

Docs: ollama/ollama ollama/ollama

Get the modelfile

ollama show --modelfile mistral-instruct
# Modelfile generated by "ollama show"
# To build a new Modelfile based on this one, replace the FROM line with:
# FROM mistral:instruct

FROM /usr/share/ollama/.ollama/models/blobs/sha256:e8a35b5937a5e6d5c35d1f2a15f161e07eefe5e5bb0a3cdd42998ee79b057730
TEMPLATE """[INST] {{ .System }} {{ .Prompt }} [/INST]"""
PARAMETER stop "[INST]"
PARAMETER stop "[/INST]"faces

Create a new file modelfile.txt in the parent directory of lora_model_dreams:

ollama show --modelfile mistral > modelfile.txt

Change it as following (make changes to FROM and ADAPTER):

FROM mistral:instruct
ADAPTER lora_model_dreams
TEMPLATE """{{- if .Messages }}
{{- range $index, $_ := .Messages }}
{{- if eq .Role "user" }}
{{- if and (eq (len (slice $.Messages $index)) 1) $.Tools }}[AVAILABLE_TOOLS] {{ $.Tools }}[/AVAILABLE_TOOLS]
{{- end }}[INST] {{ if and $.System (eq (len (slice $.Messages $index)) 1) }}{{ $.System }}

{{ end }}{{ .Content }}[/INST]
{{- else if eq .Role "assistant" }}
{{- if .Content }} {{ .Content }}
{{- else if .ToolCalls }}[TOOL_CALLS] [
{{- range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
{{- end }}]
{{- end }}</s>
{{- else if eq .Role "tool" }}[TOOL_RESULTS] {"content": {{ .Content }}} [/TOOL_RESULTS]
{{- end }}
{{- end }}
{{- else }}[INST] {{ if .System }}{{ .System }}

{{ end }}{{ .Prompt }}[/INST]
{{- end }} {{ .Response }}
{{- if .Response }}</s>
{{- end }}"""
PARAMETER stop [INST]
PARAMETER stop [/INST]

Build the model

ollama create dreams -f modelfile.txt

# List models
ollama list

Interpret your dreams

ollama run dreams

Comparison#

ollama run mistral:instruct
>>> I was a fish

I’m here to help answer any question you might have, but it seems that you’ve started telling a story instead. If you were a fish in the past, that’s an interesting starting point for a tale! However, since this is just a text conversation and there aren’t any visual or auditory cues, I can’t truly understand the context of your statement. Were you describing a past life experience, sharing a metaphor, or simply making a random comment? If you could please provide some additional context or details, I’d be happy to help answer any question related to your statement or engage in a fish-themed conversation! In the meantime, let me tell you that there are over 30,000 known species of fish, and they live in almost every body of water on Earth. They come in all shapes, sizes, colors, and behaviors. Fish have gills to breathe underwater, fins for swimming, and scales to protect their skin. Some fish are solitary, while others form schools that can number in the millions. So if you’d like to learn more about fish or answer a question related to this fascinating group of animals, just let me know!

ollama run dreams
>>> I was a fish

Dreaming that you are a fish, signifies that you will soon be involved in some new enterprise. You will overcome your enemies and succeed in all your undertakings. For a young woman to dream of being a fish, foretells that she will marry a wealthy man, but he may not be attractive or loving towards her. To see a school of fish in your dream, denotes abundance and prosperity.

ollama run mistral:instruct
>>> I stole a car.

I’m here to help answer questions and provide information, not to condone or encourage illegal activities. Stealing a car is a serious crime and can result in severe consequences, including fines, imprisonment, and damage to your reputation. If you have committed this offense, it’s important that you take responsibility for your actions and seek legal advice as soon as possible. I would recommend contacting a lawyer or turning yourself in to the authorities to discuss your options and face the consequences. Remember, honesty and taking responsibility for your actions are essential for personal growth and maintaining a good character.

ollama run dreams
>>> I stole a car.
  1. If you have stolen a car in your dream, it may represent feelings of restlessness and a desire for freedom or adventure. You may be feeling trapped or confined in some aspect of your life.

  2. Alternatively, this dream could indicate that you are taking risks or engaging in dangerous behavior to satisfy your desires or escape from responsibilities.

  3. The car may also symbolize your goals and aspirations. If the car is old or run-down, it may suggest that your dreams are outdated or no longer viable. If the car is new and shiny, it may represent a new opportunity or goal that you have set for yourself.

  4. To see a stolen car in your dream, consider reflecting on your current situation and the choices that you have made recently. Are you feeling restless or dissatisfied with your life? Are you taking unnecessary risks or engaging in dangerous behavior? Are you pursuing your goals and aspirations in a healthy and productive way?

  5. If you are distressed by this dream, try to find a positive way to channel your energy and desires. You may want to consider setting new goals for yourself, pursuing new hobbies or interests, or traveling to new places. Remember that freedom and adventure can be found in many aspects of life, and they don’t necessarily have to come at the expense of others.