-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from stackhpc/feature/pydantic
Refactor to use Pydantic-validated config file for frontend web app
- Loading branch information
Showing
13 changed files
with
172 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import requests, json | ||
from urllib.parse import urljoin | ||
import gradio as gr | ||
from api_startup_check import wait_for_backend | ||
from config import AppSettings | ||
|
||
settings = AppSettings.load("./settings.yml") | ||
|
||
backend_url = str(settings.backend_url) | ||
wait_for_backend(backend_url) | ||
|
||
|
||
def inference(message, history): | ||
context = "" | ||
for user_input, system_response in history: | ||
if settings.include_past_system_responses_in_context: | ||
context += settings.user_context_template.format(user_input=user_input) | ||
if settings.include_past_system_responses_in_context: | ||
context += settings.system_context_template.format( | ||
system_response=system_response | ||
) | ||
context += settings.user_context_template.format(user_input=message) | ||
|
||
headers = {"User-Agent": "vLLM Client"} | ||
payload = { | ||
"prompt": settings.prompt_template.format(context=context), | ||
"stream": True, | ||
"max_tokens": settings.llm_max_tokens, | ||
**settings.llm_params, | ||
} | ||
response = requests.post( | ||
urljoin(backend_url, "/generate"), headers=headers, json=payload, stream=True | ||
) | ||
|
||
for chunk in response.iter_lines( | ||
chunk_size=8192, decode_unicode=False, delimiter=b"\0" | ||
): | ||
if chunk: | ||
data = json.loads(chunk.decode("utf-8")) | ||
output = data["text"][0] | ||
# Manually trim the context from output | ||
delimiter = settings.prompt_template.splitlines()[-1] | ||
if delimiter in output: | ||
output = output.split(delimiter)[-1] | ||
yield output | ||
|
||
|
||
gr.ChatInterface( | ||
inference, | ||
chatbot=gr.Chatbot( | ||
height=500, | ||
show_copy_button=True, | ||
# layout='panel', | ||
), | ||
textbox=gr.Textbox(placeholder="Ask me anything...", container=False, scale=7), | ||
title=settings.page_title, | ||
retry_btn="Retry", | ||
undo_btn="Undo", | ||
clear_btn="Clear", | ||
).queue().launch(server_name="0.0.0.0") |
Oops, something went wrong.