-
Notifications
You must be signed in to change notification settings - Fork 155
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
feat: Update OpenAI spec to include image url in message content #113
feat: Update OpenAI spec to include image url in message content #113
Conversation
Thanks for the PR @bhimrazy! |
no, good point /cc @aniketmaurya @bhimrazy for now you can take inspiration from:
|
thank you for the PR @bhimrazy! as Luca mentioned, you can take inspiration from the existing LitSpec test cases. Maybe you can try sending the request with image content to the server and check that it is able to parse and doesn't break.
|
Thanks, @lantiga, @williamFalcon, and @aniketmaurya for all of these feedback. |
awesome @bhimrazy!! don't hesitate to reach out if you need any help. |
Hi @aniketmaurya @lantiga , Could you please help me through the addition of end-to-end documentation to the README? LitServe's OpenAISpec also enables capability to handle images in the input. Below is an example of how to set this up using LitServe. import litserve as ls
from litserve.specs.openai import ChatMessage
class OpenAISpecLitAPI(ls.LitAPI):
def setup(self, device):
self.model = None
def predict(self, x):
yield {"role": "assistant", "content": "This is a generated output"}
def encode_response(self, output: dict) -> ChatMessage:
yield ChatMessage(role="assistant", content="This is a custom encoded output")
if __name__ == "__main__":
server = ls.LitServer(OpenAISpecLitAPI(), spec=ls.OpenAISpec())
server.run(port=8000) In this case,
The above server can be queried using a standard OpenAI client: import requests
response = requests.post("http://127.0.0.1:8000/v1/chat/completions", json={
"model": "my-gpt2",
"stream": False, # You can stream chunked response by setting this True
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{
"type": "image_url",
"image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
},
]
}
]
}) |
looks good @bhimrazy! would be nice if you can show that image content could be processed in predict or decode_request step. For example: def predict(self, x):
if isinstance(x["content"], list):
# do something with image url
image_url = x["content"][1]["image_url"]
yield {"role": "assistant", "content": "the image describes nature and bla bla..."}
else:
yield {"role": "assistant", "content": "This is a generated output."} |
Sure Thanks! |
Hi @lantiga, The PR is ready for review. |
Awesome @bhimrazy, reviewing now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Awesome job @bhimrazy, let's see what CI thinks and then we're ready to merge! |
Let's goo! Merged 🚀 |
congrats @bhimrazy! |
Before submitting
What does this PR do?
Fixes #107.