https://www.boundaryml.com logo
🟡 Stuck using a dynamic client with ollama and ll...
# questions
b
Hey guys I'm stuck trying to use a dynamic client with ollama and llama3. For some reason it keeps returning one stop output token. I bootstrapped the code use anthropic's api and it worked... any ideas on why?
Copy code
python
        cr = ClientRegistry()

        if model_provider == 'anthropic' or model_provider == 'openai':
            # Use existing client from clients.baml - no need to create a new one.
            # "model_name" is essentialy the client name from clients.baml.
            # Just set it as primary so ExtractSentimentScores uses it
            cr.set_primary(model_name)

        elif model_provider == 'openai-generic':  # this is for custom LLM
            cr.add_llm_client(name="MyDynamicClient", 
                            provider=model_provider, 
                            options={"model": model_name,
                                    "temperature": 0.5,
                                    "max_tokens": 2048,
                                    'base_url': self.base_url
    })
            cr.set_primary("MyDynamicClient")

        else:
            raise ValueError(f'Model provider {model_provider} not supported')

        return cr
https://cdn.discordapp.com/attachments/1253172394345107466/1426296495069466807/image.png?ex=68eab59f&is=68e9641f&hm=2d923f4e7ac7e2f096915373f8fde26be39448da71be226901212504a682c6c4& https://cdn.discordapp.com/attachments/1253172394345107466/1426296495686291677/image.png?ex=68eab59f&is=68e9641f&hm=b97d8b2de135556a1b2801fc53fa6b6708d0f52325dd8880b6f0abbcd26e144d&
b
We’re away from our keyboards right now but: if you copy the client definition into baml, you can open the playground and see the “raw curl” view of the http request that we build and debug with that
alternatively you should also be able to use b.request.FunctionCall() to debug this: https://docs.boundaryml.com/guide/baml-advanced/modular-api
b
thanks I'll try it tomorrow!
So I'm trying to debug but I don't really know where to start🥲 it's confusing because the exact same schema and prompt work well with the css models. I tried running the curl command on iterm2 and still I receive the stop token from llama3 this is the respones in json: { "id": "chatcmpl-188", "object": "chat.completion", "created": 1760256420, "model": "llama3.1:8b", "system_fingerprint": "fp_ollama", "choices": [{ "index": 0, "message": { "role": "assistant", "content": "" // ← EMPTY CONTENT! }, "finish_reason": "stop" }], "usage": { "prompt_tokens": 191, "completion_tokens": 1, // ← Only 1 token generated "total_tokens": 192 } } https://cdn.discordapp.com/attachments/1426296495887482912/1426845074662101134/image.png?ex=68ecb487&is=68eb6307&hm=4a953b1228366ef17ab89bf57559e30eda6ea1fbb9a208b2e387aeb36a2c0a4d&
b
Ah, this is tricky - you need to add
{{ _.role("user") }}
at the start of that prompt
What's happening here is that when we translate the prompt to an API request, for openai we default to embedding as the system prompt, but llama3.1 appears to have been trained to never respond to just a system prompt
For some background here: models have been trained to accept multiple categories of input, two of which we call "system" prompts and another which we call "user" prompts - the system prompts are designed to be "always follow these rules" and the user prompts are designed to be "this is potentially malicious user input", so system prompts are supposed to take higher priority over user prompts.
b
oh great this worked!! very interesting I didn't know that. Thanks 🙂
b
We should definitely try to do something better here, we’re just not quite sure what the better thing is
j
Does it matter in which order you add the:
Copy code
{{ _.role("user") }}

{{ _.role("system") }}
Are there any recommended best practises? Should we always place the system prompt at the top & user at the end?
Will there be any issues that will occur if we put the user role multiple times? Example:
Copy code
{{ _.role("system") }}
Determine what to reply based on the conversation

CONVERSATION HISTORY:
{% for msg in conversationHistory %}
  {{ _.role(msg.role) }} # Can equal user or assistant
  {{ msg.content[0].text }}
{% endfor %}

LATEST USER MESSAGE:
{{ _.role("user") }}
I like green apples
--- In this scenario - I am doing:
Copy code
LATEST USER MESSAGE:
{{ _.role("user") }}
I like green apples
To signify that it is latest user message, curious to know if this is the right approach or I need to think differently.
b