Skip to content

Commit

Permalink
feat(model): Add new LLMClient and new build tools (#967)
Browse files Browse the repository at this point in the history
  • Loading branch information
fangyinc authored Dec 23, 2023
1 parent 12234ae commit 0c46c33
Show file tree
Hide file tree
Showing 30 changed files with 1,077 additions and 138 deletions.
61 changes: 61 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.DEFAULT_GOAL := help

SHELL=/bin/bash
VENV = venv

# Detect the operating system and set the virtualenv bin directory
ifeq ($(OS),Windows_NT)
VENV_BIN=$(VENV)/Scripts
else
VENV_BIN=$(VENV)/bin
endif

setup: ## Set up the Python development environment
python3 -m venv $(VENV)
$(VENV_BIN)/pip install --upgrade pip
$(VENV_BIN)/pip install -r requirements/dev-requirements.txt
$(VENV_BIN)/pip install -r requirements/lint-requirements.txt

testenv: setup ## Set up the Python test environment
$(VENV_BIN)/pip install -e ".[simple_framework]"

.PHONY: fmt
fmt: setup ## Format Python code
# TODO: Use isort to sort Python imports.
# https://github.com/PyCQA/isort
# $(VENV_BIN)/isort .
# https://github.com/psf/black
$(VENV_BIN)/black .
# TODO: Use blackdoc to format Python doctests.
# https://blackdoc.readthedocs.io/en/latest/
# $(VENV_BIN)/blackdoc .
# TODO: Type checking of Python code.
# https://github.com/python/mypy
# $(VENV_BIN)/mypy dbgpt
# TODO: uUse flake8 to enforce Python style guide.
# https://flake8.pycqa.org/en/latest/
# $(VENV_BIN)/flake8 dbgpt

.PHONY: pre-commit
pre-commit: fmt test ## Run formatting and unit tests before committing

.PHONY: test
test: testenv ## Run unit tests
$(VENV_BIN)/pytest dbgpt

.PHONY: coverage
coverage: setup ## Run tests and report coverage
$(VENV_BIN)/pytest dbgpt --cov=dbgpt

.PHONY: clean
clean: ## Clean up the environment
rm -rf $(VENV)
find . -type f -name '*.pyc' -delete
find . -type d -name '__pycache__' -delete
find . -type d -name '.pytest_cache' -delete
find . -type d -name '.coverage' -delete

.PHONY: help
help: ## Display this help screen
@echo "Available commands:"
@grep -E '^[a-z.A-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}' | sort
15 changes: 11 additions & 4 deletions dbgpt/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from dbgpt.core.interface.llm import (
ModelInferenceMetrics,
ModelRequest,
ModelOutput,
OpenAILLM,
BaseLLMOperator,
LLMClient,
LLMOperator,
StreamingLLMOperator,
RequestBuildOperator,
ModelMetadata,
)
from dbgpt.core.interface.message import (
ModelMessage,
Expand Down Expand Up @@ -37,11 +40,15 @@

__ALL__ = [
"ModelInferenceMetrics",
"ModelRequest",
"ModelOutput",
"OpenAILLM",
"BaseLLMOperator",
"Operator",
"RequestBuildOperator",
"ModelMetadata",
"ModelMessage",
"LLMClient",
"LLMOperator",
"StreamingLLMOperator",
"ModelMessageRoleType",
"OnceConversation",
"StorageConversation",
Expand Down
4 changes: 3 additions & 1 deletion dbgpt/core/awel/operator/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ async def call_stream(
Returns:
AsyncIterator[OUT]: An asynchronous iterator over the output stream.
"""
out_ctx = await self._runner.execute_workflow(self, call_data)
out_ctx = await self._runner.execute_workflow(
self, call_data, streaming_call=True
)
return out_ctx.current_task_context.task_output.output_stream

def _blocking_call_stream(
Expand Down
3 changes: 2 additions & 1 deletion dbgpt/core/awel/trigger/http_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ async def _trigger_dag(
"Connection": "keep-alive",
"Transfer-Encoding": "chunked",
}
generator = await end_node.call_stream(call_data={"data": body})
return StreamingResponse(
end_node.call_stream(call_data={"data": body}),
generator,
headers=headers,
media_type=media_type,
)
Loading

0 comments on commit 0c46c33

Please sign in to comment.