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

[Feature] Create tokenizer for applying chat template for mistral, llama etc #625

Closed
narengogi opened this issue Sep 24, 2024 · 3 comments
Closed
Labels
enhancement New feature or request triage

Comments

@narengogi
Copy link
Contributor

What Would You Like to See with the Gateway?

Open source models like Llama and mistral expect instruction and completion inputs in a chat template format for optimal text completions
example:

<|begin_of_text|>\\n<|start_header_id|>user<|end_header_id|>\\nCountry: United States\\nCapital: <|eot_id|><|start_header_id|>assistant<|end_header_id|>\\nWashington DC<|eot_id|><|start_header_id|>user<|end_header_id|>\\nWhat is up my good friend?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\\n

use the following for reference:
https://www.llama.com/docs/model-cards-and-prompt-formats/llama3_1
https://medium.com/@marketing_novita.ai/how-to-use-mistral-chat-template-e0b2a973f031

Portkey's current implementation does not apply the templates, rather appends roles this way

    transform: (params: Params) => {
      let prompt: string = '';
      if (!!params.messages) {
        let messages: Message[] = params.messages;
        messages.forEach((msg, index) => {
          if (index === 0 && msg.role === 'system') {
            prompt += `system: ${msg.content}\n`;
          } else if (msg.role == 'user') {
            prompt += `user: ${msg.content}\n`;
          } else if (msg.role == 'assistant') {
            prompt += `assistant: ${msg.content}\n`;
          } else {
            prompt += `${msg.role}: ${msg.content}\n`;
          }
        });
        prompt += 'Assistant:';
      }
      return prompt;
    },

Context for your Request

No response

Your Twitter/LinkedIn

No response

@narengogi narengogi added the enhancement New feature or request label Sep 24, 2024
@keshavkrishna
Copy link
Contributor

@narengogi can i work on this??

@narengogi
Copy link
Contributor Author

I'm already working on this @keshavkrishna

@narengogi
Copy link
Contributor Author

This is no longer relevant as the gateway has migrated to use AWS Converse API internally, tokenization and chat templating is handled by Bedrock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage
Projects
None yet
Development

No branches or pull requests

2 participants