8000 feat(serve.py): add api_path parameter to cli options to allow custom API endpoint configuration by botirk38 · Pull Request #2080 · Lightning-AI/litgpt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(serve.py): add api_path parameter to cli options to allow custom API endpoint configuration #2080

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

botirk38
Copy link

Currently users of the library cannot override the api path, this makes it hard to integrate with the openai sdk for example. This PR introduces a fix for this use case.

@botirk38 botirk38 requested review from lantiga, t-vi and Borda as code owners June 21, 2025 01:11
@botirk38 botirk38 force-pushed the main branch 2 times, most recently from ba60cc1 to 883dda3 Compare June 21, 2025 01:53
…ses to allow custom API endpoint configuration

refactor(serve.py): improve code readability by formatting long lines and restructuring some method calls for clarity

style(serve.py): format code for improved readability by removing unnecessary line breaks and aligning parameters

fix(serve.py): resolve api_path to default value when not using OpenAI spec or stream to ensure server functionality

fix(serve.py): set default api_path to "/predict" for run_server function to ensure consistent behavior when no path is provided
refactor(serve.py): simplify api_path handling by removing unnecessary resolved_api_path variable
@bhimrazy
Copy link
Contributor
bhimrazy commented Jun 24, 2025

Hi @botirk38,
Just out of curiosity, could you briefly explain how not having the api_path override makes integrating with the OpenAI SDK harder?

I assume to integrate via the OpenAI SDK you would use the chat completions API, right?

@botirk38
Copy link
Author

Hi @botirk38, Just out of curiosity, could you briefly explain how not having the api_path override makes integrating with the OpenAI SDK harder?

I assume to integrate via the OpenAI SDK you would use the chat completions API, right?

Take this a grain of salt, im nmew to LitGPT. So the open ai sdk for a completions endpoint looks for /chat/completions, right now the path is set to/predict because of the lit serve dependency, therefore I want to override the path to /chat/completions.

@bhimrazy
Copy link
Contributor

Hi @botirk38, just a quick note — LitGPT already supports the OpenAI-compatible /v1/chat/completions endpoint via the --openai_spec true flag.

Example usage:

litgpt serve HuggingFaceTB/SmolLM2-135M-Instruct --openai_spec true

Then you can hit it using the OpenAI SDK or curl:

curl -X POST http://127.0.0.1:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "SmolLM2-135M-Instruct",
    "messages": [{"role": "user", "content": "Hello! How are you?"}]
  }'

Will also update the docs soon to make this more visible. Hope this helps!

@botirk38
Copy link
Author

Hi @botirk38, just a quick note — LitGPT already supports the OpenAI-compatible /v1/chat/completions endpoint via the --openai_spec true flag.

Example usage:

litgpt serve HuggingFaceTB/SmolLM2-135M-Instruct --openai_spec true

Then you can hit it using the OpenAI SDK or curl:

curl -X POST http://127.0.0.1:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "SmolLM2-135M-Instruct",
    "messages": [{"role": "user", "content": "Hello! How are you?"}]
  }'

Will also update the docs soon to make this more visible. Hope this helps!

Hi thats amazing here, thanks for the support. Do you think its still worth adding the api path override? Otherwise Ill close it

@bhimrazy
Copy link
Contributor

Yes @botirk38, we can keep it — just need to update the PR description.

@@ -1,4 +1,3 @@
# Copyright Lightning AI. Licensed under the Apache License 2.0, see LICENSE file.
Copy link
Member

Choose a reason for hiding this comment

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

Why is this removed?

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
0