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

LLM standardisation #320

Merged
merged 10 commits into from
Nov 9, 2024
Merged

LLM standardisation #320

merged 10 commits into from
Nov 9, 2024

Conversation

dylanratcliffe
Copy link
Member

This is a pretty substantial piece of work that aims to standardise the methods we use to call out to LLMs everywhere in the product.

Why?

  • As we look at ways to improve the assistant (better tools, learning, new RAG approaches) we also need to make sure that whatever work we do there, also improves risks and vice versa.
  • We need to be able to evaluate new models more easily
  • We need to support things like Amazon Bedrock for our enterprise customers to allow them to keep data completely in-house

How?

This has been achieved by creating a new interface for an assistant conversation, and for tools, that allows the actual LLM provider to be pluggable without changing anything else. The three interfaces that matter here are:

  • Provider: This represents the actual LLM, I have created providers for OpenAI and Anthropic
  • Conversation: This represents a back and forth conversation with one of the providers. This interface stores state which means that it not only simplifies the way we need to interact with it, but abstracts over some of the differences between OpenAI and Anthropic. Like for example the fact that Anthropic doesn't really do server-side storage of conversations, however there is prompt caching which seems kind of similar...?
  • ToolImplementation: This is the one I'm the most proud of. It allows anyone to use the Tool struct with nothing but a name, description and a function. The JSON schema is automatically determined from the data type, which uses generics. Very nice.

@dylanratcliffe
Copy link
Member Author

Note, this is failing linting due to a non-inherited context. I wanted to get a quick review on this. Is what I'm doing sane?

@tphoney
Copy link
Contributor

tphoney commented Nov 4, 2024

seems sane so far,

  • it would be good to see how this fits in with the assistant in Gateway. so there is a single place for an llm conversation.
  • having shared otel metrics, for conversations.
  • where the configuration is for linking your llm to a customer. how granular should this be.

@dylanratcliffe
Copy link
Member Author

it would be good to see how this fits in with the assistant in Gateway. so there is a single place for an llm conversation.

Agreed. This has been designed so that we can replace all of the stuff in gateway with this too so that it's a unified implementation. All we need to do is refactor the tools to this (simpler IMO) format and we're good to go

where the configuration is for linking your llm to a customer. how granular should this be

I think that's outside the scope of this library, but you can see how I've done it in api-server i.e.

We can change the granularity as required for each use-case

Copy link
Contributor

@DavidS-ovm DavidS-ovm left a comment

Choose a reason for hiding this comment

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

I like the overall approach and left some more detailed technical comments below.

If this works out as a model we could consider splitting it out into its own dedicated OSS project and make some promotional activities around it to see if there's interest from others.

llm/anthropic.go Outdated Show resolved Hide resolved
llm/main.go Outdated Show resolved Hide resolved
llm/main.go Outdated Show resolved Hide resolved
llm/main.go Outdated Show resolved Hide resolved
llm/openai.go Show resolved Hide resolved
// Capture data from the LLM
rates := run.GetRateLimitHeaders()
span.SetAttributes(
attribute.String("ovm.openai.model", run.Model),
Copy link
Contributor

Choose a reason for hiding this comment

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

todo: review if there is overlap to metrics from anthropic we'd like to share attribute names (ovm.llm.*?)

Copy link
Member Author

Choose a reason for hiding this comment

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

The only overlap is:

span.SetAttributes(
	attribute.Int64("ovm.anthropic.usage.inputTokens", response.Usage.InputTokens),
	attribute.Int64("ovm.anthropic.usage.outputTokens", response.Usage.OutputTokens),
	attribute.String("ovm.anthropic.model", response.Model),
)

I decided to use anthropic in the name so that we didn't get overlap as I thought it could be confusing, but I used the same names otherwise i.e. InputTokens etc.

@dylanratcliffe dylanratcliffe self-assigned this Nov 6, 2024
Copy link
Contributor

@DavidS-ovm DavidS-ovm left a comment

Choose a reason for hiding this comment

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

👨‍🍳 💋

llm/anthropic_test.go Show resolved Hide resolved
@dylanratcliffe dylanratcliffe merged commit 7b101b0 into main Nov 9, 2024
3 checks passed
@dylanratcliffe dylanratcliffe deleted the llm-standardisation branch November 9, 2024 09:18
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.

3 participants