Skip to content

feat: Improved LLM public API #243

Merged
pweglik merged 8 commits intov0.4.0-rc1from
@pw/improvements-in-llm-api
May 8, 2025
Merged

feat: Improved LLM public API #243
pweglik merged 8 commits intov0.4.0-rc1from
@pw/improvements-in-llm-api

Conversation

@pweglik
Copy link
Copy Markdown
Contributor

@pweglik pweglik commented May 6, 2025

Added generate function, and some little re…formats

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (improves or adds clarity to existing documentation)

Tested on

  • iOS
  • Android

Related issues

#226

Checklist

  • I have performed a self-review of my code
  • I have updated the documentation accordingly
  • My changes generate no new warnings

@pweglik pweglik requested review from chmjkb, jakmro and mkopcins May 6, 2025 10:40
@pweglik pweglik self-assigned this May 6, 2025
@pweglik pweglik linked an issue May 6, 2025 that may be closed by this pull request
@pweglik pweglik changed the title Improved LLM public API feat: Improved LLM public API May 6, 2025
Base automatically changed from @nk/qwen-3 to v0.4.0-rc1 May 7, 2025 07:21
@pweglik pweglik requested a review from NorbertKlockiewicz May 7, 2025 08:35
Comment thread docs/docs/typescript-api/LLMModule.md Outdated
Alternatively, you can use `runInference`. It provides direct access to the model, without any wrapper, so the input string is passed straight into the model. If you're not sure what are implications of that, you're better off with `sendMessage`
Alternatively, you can use `generate` method. It allows you to simply pass chat messages and receive completion from the model. It doesn't provide any message history management.

If you need raw model, without any wrappers, you can use `forward`. It provides direct access to the model, so the input string is passed straight into the model. It may be useful to work with models that aren't finetuned for chat completions. If you're not sure what are implications of that, you're better off with `sendMessage`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you need raw model, without any wrappers, you can use `forward`. It provides direct access to the model, so the input string is passed straight into the model. It may be useful to work with models that aren't finetuned for chat completions. If you're not sure what are implications of that, you're better off with `sendMessage`
If you need raw model, without any wrappers, you can use `forward`. It provides direct access to the model, so the input string is passed straight into the model. It may be useful to work with models that aren't finetuned for chat completions. If you're not sure what are implications of that, you're better off with `sendMessage`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can mention here that you need to add special tokens to make it work

Comment thread examples/llm/App.tsx Outdated
import { View, StyleSheet, Text } from 'react-native';

enum ModelType {
enum ModeType {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just Mode instead of ModeType

Comment thread src/controllers/LLMController.ts Outdated
this.responseCallback('');
this.isGeneratingCallback(true);
await this.nativeModule.runInference(input);
console.log('INPUT:', input);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console.log

@NorbertKlockiewicz
Copy link
Copy Markdown
Contributor

Can you also bump huggingface/jinja to newest version(0.5.0), as the current has problems with qwen 3 tokenizer.

@pweglik pweglik requested a review from NorbertKlockiewicz May 7, 2025 11:09
Comment thread README.md
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that this is wrong, you're supposed to pass all the special tokens to forward(), but the above prompt definition doesn't do that. Change the call of this method to generate() (not sure if this one is ok)

Comment thread docs/docs/typescript-api/LLMModule.md Outdated
Alternatively, you can use `runInference`. It provides direct access to the model, without any wrapper, so the input string is passed straight into the model. If you're not sure what are implications of that, you're better off with `sendMessage`
Alternatively, you can use `generate` method. It allows you to simply pass chat messages and receive completion from the model. It doesn't provide any message history management.

If you need raw model, without any wrappers, you can use `forward`. It provides direct access to the model, so the input string is passed straight into the model. It may be useful to work with models that aren't finetuned for chat completions. If you're not sure what are implications of that, you're better off with `sendMessage`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can mention here that you need to add special tokens to make it work

Comment thread src/controllers/LLMController.ts Outdated
messages: Message[],
tokenizerConfig: any,
tools?: LLMTool[],
template_flags?: Object
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make template_flags camel case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, missed it, maybe we should enforce camel case with eslint? Can you create issue for it?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, will do

@pweglik pweglik requested a review from chmjkb May 7, 2025 12:49
@pweglik pweglik merged commit 270faa6 into v0.4.0-rc1 May 8, 2025
1 check passed
@pweglik pweglik deleted the @pw/improvements-in-llm-api branch May 8, 2025 14:04
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

Successfully merging this pull request may close these issues.

Allow users to manage conversation history in LLM

3 participants