mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-08-02 00:28:00 +00:00
refactor(ollama): add ollama config and support ollama model output (#2411)
This commit is contained in:
parent
4e993a2be8
commit
bb06e93215
@ -7,7 +7,7 @@ encrypt_key = "your_secret_key"
|
|||||||
|
|
||||||
# Server Configurations
|
# Server Configurations
|
||||||
[service.web]
|
[service.web]
|
||||||
host = "127.0.0.1"
|
host = "0.0.0.0"
|
||||||
port = 5670
|
port = 5670
|
||||||
|
|
||||||
[service.web.database]
|
[service.web.database]
|
||||||
|
33
configs/dbgpt-proxy-ollama.toml
Normal file
33
configs/dbgpt-proxy-ollama.toml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
[system]
|
||||||
|
# Load language from environment variable(It is set by the hook)
|
||||||
|
language = "${env:DBGPT_LANG:-en}"
|
||||||
|
api_keys = []
|
||||||
|
encrypt_key = "your_secret_key"
|
||||||
|
|
||||||
|
# Server Configurations
|
||||||
|
[service.web]
|
||||||
|
host = "0.0.0.0"
|
||||||
|
port = 5670
|
||||||
|
|
||||||
|
[service.web.database]
|
||||||
|
type = "sqlite"
|
||||||
|
path = "pilot/meta_data/dbgpt.db"
|
||||||
|
|
||||||
|
[rag.storage]
|
||||||
|
[rag.storage.vector]
|
||||||
|
type = "Chroma"
|
||||||
|
persist_path = "pilot/data"
|
||||||
|
|
||||||
|
# Model Configurations
|
||||||
|
[models]
|
||||||
|
[[models.llms]]
|
||||||
|
name = "deepseek-r1:1.5b"
|
||||||
|
provider = "proxy/ollama"
|
||||||
|
api_base = "http://localhost:11434"
|
||||||
|
api_key = ""
|
||||||
|
|
||||||
|
[[models.embeddings]]
|
||||||
|
name = "bge-m3:latest"
|
||||||
|
provider = "proxy/ollama"
|
||||||
|
api_url = "http://localhost:11434"
|
||||||
|
api_key = ""
|
@ -6,7 +6,7 @@ encrypt_key = "your_secret_key"
|
|||||||
|
|
||||||
# Server Configurations
|
# Server Configurations
|
||||||
[service.web]
|
[service.web]
|
||||||
host = "127.0.0.1"
|
host = "0.0.0.0"
|
||||||
port = 5670
|
port = 5670
|
||||||
|
|
||||||
[service.web.database]
|
[service.web.database]
|
||||||
|
@ -297,6 +297,9 @@ class ModelRequestContext:
|
|||||||
request_id: Optional[str] = None
|
request_id: Optional[str] = None
|
||||||
"""The request id of the model inference."""
|
"""The request id of the model inference."""
|
||||||
|
|
||||||
|
is_reasoning_model: Optional[bool] = False
|
||||||
|
"""Whether the model is a reasoning model."""
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@PublicAPI(stability="beta")
|
@PublicAPI(stability="beta")
|
||||||
|
@ -19,6 +19,10 @@ from dbgpt.model.proxy.base import (
|
|||||||
from dbgpt.model.proxy.llms.proxy_model import ProxyModel, parse_model_request
|
from dbgpt.model.proxy.llms.proxy_model import ProxyModel, parse_model_request
|
||||||
from dbgpt.util.i18n_utils import _
|
from dbgpt.util.i18n_utils import _
|
||||||
|
|
||||||
|
from ...utils.parse_utils import (
|
||||||
|
parse_chat_message,
|
||||||
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -120,6 +124,7 @@ class OllamaLLMClient(ProxyLLMClient):
|
|||||||
messages = request.to_common_messages()
|
messages = request.to_common_messages()
|
||||||
|
|
||||||
model = request.model or self._model
|
model = request.model or self._model
|
||||||
|
is_reasoning_model = getattr(request.context, "is_reasoning_model", False)
|
||||||
client = Client(self._api_base)
|
client = Client(self._api_base)
|
||||||
try:
|
try:
|
||||||
stream = client.chat(
|
stream = client.chat(
|
||||||
@ -130,9 +135,12 @@ class OllamaLLMClient(ProxyLLMClient):
|
|||||||
content = ""
|
content = ""
|
||||||
for chunk in stream:
|
for chunk in stream:
|
||||||
content = content + chunk["message"]["content"]
|
content = content + chunk["message"]["content"]
|
||||||
yield ModelOutput(text=content, error_code=0)
|
msg = parse_chat_message(content, extract_reasoning=is_reasoning_model)
|
||||||
|
yield ModelOutput.build(
|
||||||
|
text=msg.content, thinking=msg.reasoning_content, error_code=0
|
||||||
|
)
|
||||||
except ollama.ResponseError as e:
|
except ollama.ResponseError as e:
|
||||||
yield ModelOutput(
|
yield ModelOutput.build(
|
||||||
text=f"**Ollama Response Error, Please CheckErrorInfo.**: {e}",
|
text=f"**Ollama Response Error, Please CheckErrorInfo.**: {e}",
|
||||||
error_code=-1,
|
error_code=-1,
|
||||||
)
|
)
|
||||||
|
@ -91,6 +91,7 @@ def parse_model_request(
|
|||||||
stream=stream,
|
stream=stream,
|
||||||
user_name=params.get("user_name"),
|
user_name=params.get("user_name"),
|
||||||
request_id=params.get("request_id"),
|
request_id=params.get("request_id"),
|
||||||
|
is_reasoning_model=params.get("is_reasoning_model", False),
|
||||||
)
|
)
|
||||||
request = ModelRequest.build_request(
|
request = ModelRequest.build_request(
|
||||||
default_model,
|
default_model,
|
||||||
|
Loading…
Reference in New Issue
Block a user