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

Feedback on LLM Python API #56

Open
simonw opened this issue Feb 4, 2024 · 4 comments
Open

Feedback on LLM Python API #56

simonw opened this issue Feb 4, 2024 · 4 comments

Comments

@simonw
Copy link

simonw commented Feb 4, 2024

I just saw you're using https://llm.datasette.io for this, which is really cool!

It's still pre-1.0 and I'm not yet 100% sure I've got the Python library API right. As such I'd love to get your feedback on that aspect of the library - is there anything that would make it easier to use?

@simonw
Copy link
Author

simonw commented Feb 4, 2024

Looks like everything your are using is encapsulated in this code:

def prompt_with_context(
self, *, pre_prompt: str, context: str, post_prompt: str | None = None
) -> AIResponse:
model = self.get_llm_model()
parts = [pre_prompt, context]
if post_prompt is not None:
parts.append(post_prompt)
full_prompt = os.linesep.join(parts)
prompt_kwargs = {}
if self.config.prompt_kwargs is not None:
prompt_kwargs.update(self.config.prompt_kwargs)
return model.prompt(full_prompt, **prompt_kwargs)
def get_llm_model(self) -> llm.Model:
model = llm.get_model(self.config.model_id)
if self.config.init_kwargs is not None:
for config_key, config_val in self.config.init_kwargs.items():
setattr(model, config_key, config_val)
return model

@tomusher
Copy link
Member

tomusher commented Feb 5, 2024

Thanks for checking in @simonw!

We've been very pleased with llm, it's made it very easy for us to support loads of models in wagtail-ai. There's a few things we've stumbled with, but nothing that's been a major blocker so far. Here's a few off the top of my head:

  • llm doesn't currently provide a way to determine the context token limit for a model. We use this for determining where/when to split content both in wagtail-ai and wagtail-vector-index. At the moment, we maintain a simple mapping and ask users to specify a value if they use their own models, but it would be really useful if this was something we could request from llm.
  • Similarly, we currently need to maintain our own mapping of embedding models to number of output dimensions (as vector databases often need this value to size their vector columns).
  • There are cases where we'd like to request multiple choices for a given call to prompt (e.g. the n argument to the OpenAI API). I can see that this wouldn't be hard to implement in the OpenAI plugin, but we can't rely on model-specific options as users may swap this out. Not sure if this is something that could be standardised, or whether there could be a way to interrogate whether an API/plugin supports this sort of feature.
  • This is probably less solvable, but there are various cases where practices for interacting with these LLMs vary, e.g. using system prompts is more effective in GPT4 than GPT3.5. We're considering wrapping up these best practices in our own per-model classes, and seeing as we'll likely be sharing this logic between wagtail-ai and wagtail-vector-index, that will probably involve us breaking those out in to a new package. Do you have any thoughts/plans to bring this higher level of abstraction in to llm?

@tm-kn
Copy link
Member

tm-kn commented Feb 6, 2024

Thanks for reaching out @simonw, and that's excellent feedback @tomusher.

One point from me would be:

@tomdyson
Copy link
Contributor

tomdyson commented Feb 6, 2024

Hi @simonw, thanks for llm! wagtail-ai started with just support for OpenAI, then @tomusher wrote https://github.com/tomusher/every-ai to abstract other AI platform APIs, then we decided to adopt a more actively developed wrapper and picked llm.

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

4 participants