Skip to content

Commit

Permalink
Improve Gradio UI and fix arch_state bug (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
adilhafeez authored Oct 29, 2024
1 parent 662a840 commit 6029924
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 262 deletions.
5 changes: 2 additions & 3 deletions chatbot_ui/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
{
"python": "${workspaceFolder}/venv/bin/python",
"name": "chatbot-ui",
"cwd": "${workspaceFolder}/app",
"type": "debugpy",
"request": "launch",
"program": "run.py",
"program": "run_stream.py",
"console": "integratedTerminal",
"env": {
"LLM": "1",
"CHAT_COMPLETION_ENDPOINT": "http://localhost:10000/v1",
"STREAMING": "True",
"ARCH_CONFIG": "../../demos/function_calling/arch_config.yaml"
"ARCH_CONFIG": "../demos/function_calling/arch_config.yaml"
}
},
{
Expand Down
6 changes: 2 additions & 4 deletions chatbot_ui/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ COPY requirements.txt /src/

RUN pip install --prefix=/runtime --force-reinstall -r requirements.txt

COPY . /src

FROM python:3.10-slim AS output

COPY --from=builder /runtime /usr/local

COPY /app /app
WORKDIR /app
COPY *.py .

CMD ["python", "run.py"]
CMD ["python", "run_stream.py"]
20 changes: 0 additions & 20 deletions chatbot_ui/app/arch_util.py

This file was deleted.

231 changes: 0 additions & 231 deletions chatbot_ui/app/run.py

This file was deleted.

77 changes: 77 additions & 0 deletions chatbot_ui/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import json
import logging
import os
import yaml

logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
)

log = logging.getLogger(__name__)


def process_stream_chunk(chunk, history):
delta = chunk.choices[0].delta
if delta.role and delta.role != history[-1]["role"]:
# create new history item if role changes
# this is likely due to arch tool call and api response
history.append({"role": delta.role})

history[-1]["model"] = chunk.model
# append tool calls to history if there are any in the chunk
if delta.tool_calls:
history[-1]["tool_calls"] = delta.tool_calls

if delta.content:
# append content to the last history item
history[-1]["content"] = history[-1].get("content", "") + delta.content
# yield content if it is from assistant
if history[-1]["role"] == "assistant":
return delta.content

return None


def convert_prompt_target_to_openai_format(target):
tool = {
"description": target["description"],
"parameters": {"type": "object", "properties": {}, "required": []},
}

if "parameters" in target:
for param_info in target["parameters"]:
parameter = {
"type": param_info["type"],
"description": param_info["description"],
}

for key in ["default", "format", "enum", "items", "minimum", "maximum"]:
if key in param_info:
parameter[key] = param_info[key]

tool["parameters"]["properties"][param_info["name"]] = parameter

required = param_info.get("required", False)
if required:
tool["parameters"]["required"].append(param_info["name"])

return {"name": target["name"], "info": tool}


def get_prompt_targets():
try:
with open(os.getenv("ARCH_CONFIG", "arch_config.yaml"), "r") as file:
config = yaml.safe_load(file)

available_tools = []
for target in config["prompt_targets"]:
if not target.get("default", False):
available_tools.append(
convert_prompt_target_to_openai_format(target)
)

return {tool["name"]: tool["info"] for tool in available_tools}
except Exception as e:
log.info(e)
return None
Loading

0 comments on commit 6029924

Please sign in to comment.