mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-07-30 23:28:35 +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
|
||||
[service.web]
|
||||
host = "127.0.0.1"
|
||||
host = "0.0.0.0"
|
||||
port = 5670
|
||||
|
||||
[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
|
||||
[service.web]
|
||||
host = "127.0.0.1"
|
||||
host = "0.0.0.0"
|
||||
port = 5670
|
||||
|
||||
[service.web.database]
|
||||
|
@ -297,6 +297,9 @@ class ModelRequestContext:
|
||||
request_id: Optional[str] = None
|
||||
"""The request id of the model inference."""
|
||||
|
||||
is_reasoning_model: Optional[bool] = False
|
||||
"""Whether the model is a reasoning model."""
|
||||
|
||||
|
||||
@dataclass
|
||||
@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.util.i18n_utils import _
|
||||
|
||||
from ...utils.parse_utils import (
|
||||
parse_chat_message,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -120,6 +124,7 @@ class OllamaLLMClient(ProxyLLMClient):
|
||||
messages = request.to_common_messages()
|
||||
|
||||
model = request.model or self._model
|
||||
is_reasoning_model = getattr(request.context, "is_reasoning_model", False)
|
||||
client = Client(self._api_base)
|
||||
try:
|
||||
stream = client.chat(
|
||||
@ -130,9 +135,12 @@ class OllamaLLMClient(ProxyLLMClient):
|
||||
content = ""
|
||||
for chunk in stream:
|
||||
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:
|
||||
yield ModelOutput(
|
||||
yield ModelOutput.build(
|
||||
text=f"**Ollama Response Error, Please CheckErrorInfo.**: {e}",
|
||||
error_code=-1,
|
||||
)
|
||||
|
@ -91,6 +91,7 @@ def parse_model_request(
|
||||
stream=stream,
|
||||
user_name=params.get("user_name"),
|
||||
request_id=params.get("request_id"),
|
||||
is_reasoning_model=params.get("is_reasoning_model", False),
|
||||
)
|
||||
request = ModelRequest.build_request(
|
||||
default_model,
|
||||
|
Loading…
Reference in New Issue
Block a user