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

MLflow model adapter #517

Merged
merged 3 commits into from
Nov 6, 2023
Merged

MLflow model adapter #517

merged 3 commits into from
Nov 6, 2023

Conversation

fedefernandez
Copy link
Contributor

@fedefernandez fedefernandez commented Nov 3, 2023

Overview

This PR adds a new Ktor client's plugin for adapting the Xef request/response model (OpenAI compatible models) to MLflow.

sequenceDiagram
    actor Client
    participant A as XefServer
    participant B as MLflowModelAdapter
    participant C as MLflowGateway
    Client->>+A: OpenAI Request
    A->>+B: OpenAI Request
    B->>+C: MLflow Request
    C-->>-B: MLflow Response
    B-->>-A: OpenAI Response
    A-->>-Client: OpenAI Response

Change details

  1. Simplify ModelUriAdapter.kt by intercepting the "request pipeline" (instead of "send pipeline") since we only need to change the request
  2. Add the models that will be used for transforming Xef requests into MLflow requests and MLflow responses into Xef responses.
  3. Add the MLflowModelAdapter.kt and the builder

How to test it?

  1. Follow the Quickstart Guide for starting an MLflow Gateway instance
  2. Add the interceptors to the Ktor HTTP client in Server
install(com.xebia.functional.xef.server.http.client.ModelUriAdapter) {
  addToPath(
    com.xebia.functional.xef.server.http.client.OpenAIPathType.EMBEDDINGS, 
    "embedding-model" to "http://127.0.0.1:5000/gateway/embeddings/invocations"
  )
  addToPath(
    com.xebia.functional.xef.server.http.client.OpenAIPathType.CHAT, 
    "chat-model" to "http://127.0.0.1:5000/gateway/chat/invocations"
  )
}
install(com.xebia.functional.xef.server.http.client.mlflow.MLflowModelAdapter) {
  addToPath(
    "http://127.0.0.1:5000/gateway/embeddings/invocations",
    com.xebia.functional.xef.server.http.client.OpenAIPathType.EMBEDDINGS
  )
  addToPath(
    "http://127.0.0.1:5000/gateway/chat/invocations",
    com.xebia.functional.xef.server.http.client.OpenAIPathType.CHAT
  )
}

Next Steps

Necessary code for automatically starting Xef server with an MLflow Gateway connection through configuration and presumably just with an environment variable.

@fedefernandez fedefernandez changed the title Feature/model adapter MLflow model adapter Nov 6, 2023
@fedefernandez fedefernandez marked this pull request as ready for review November 6, 2023 09:38
@fedefernandez fedefernandez marked this pull request as draft November 6, 2023 09:41
@fedefernandez fedefernandez marked this pull request as ready for review November 6, 2023 11:41
Copy link
Contributor

@raulraja raulraja left a comment

Choose a reason for hiding this comment

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

Looks great @fedefernandez !

@fedefernandez fedefernandez merged commit 3a8c11a into main Nov 6, 2023
5 checks passed
@fedefernandez fedefernandez deleted the feature/model-adapter branch November 6, 2023 16:27
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.

None yet

2 participants