Private
Public Access
refactor(ai_client): _send_llama_native_result() returns Result[str]
This commit is contained in:
+6
-3
@@ -2536,14 +2536,15 @@ def ollama_chat(
|
|||||||
resp = requests.post(f"{base_url}/api/chat", json=payload, timeout=120)
|
resp = requests.post(f"{base_url}/api/chat", json=payload, timeout=120)
|
||||||
return resp.json()
|
return resp.json()
|
||||||
|
|
||||||
def _send_llama_native(md_content: str, user_message: str, base_dir: str,
|
def _send_llama_native_result(md_content: str, user_message: str, base_dir: str,
|
||||||
file_items: list[dict[str, Any]] | None = None,
|
file_items: list[dict[str, Any]] | None = None,
|
||||||
discussion_history: str = "",
|
discussion_history: str = "",
|
||||||
stream: bool = False,
|
stream: bool = False,
|
||||||
pre_tool_callback: Optional[Callable[[str, str, Optional[Callable[[str], str]]], Optional[str]]] = None,
|
pre_tool_callback: Optional[Callable[[str, str, Optional[Callable[[str], str]]], Optional[str]]] = None,
|
||||||
qa_callback: Optional[Callable[[str], str]] = None,
|
qa_callback: Optional[Callable[[str], str]] = None,
|
||||||
stream_callback: Optional[Callable[[str], None]] = None,
|
stream_callback: Optional[Callable[[str], None]] = None,
|
||||||
patch_callback: Optional[Callable[[str, str], Optional[str]]] = None) -> str:
|
patch_callback: Optional[Callable[[str, str], Optional[str]]] = None) -> Result[str]:
|
||||||
|
try:
|
||||||
base_url = _llama_base_url.replace("/v1", "")
|
base_url = _llama_base_url.replace("/v1", "")
|
||||||
with _llama_history_lock:
|
with _llama_history_lock:
|
||||||
if discussion_history and not _llama_history:
|
if discussion_history and not _llama_history:
|
||||||
@@ -2565,7 +2566,9 @@ def _send_llama_native(md_content: str, user_message: str, base_dir: str,
|
|||||||
if thinking:
|
if thinking:
|
||||||
msg["thinking"] = thinking
|
msg["thinking"] = thinking
|
||||||
_llama_history.append(msg)
|
_llama_history.append(msg)
|
||||||
return (f"<thinking>\n{thinking}\n</thinking>\n" if thinking else "") + text
|
return Result(data=(f"<thinking>\n{thinking}\n</thinking>\n" if thinking else "") + text)
|
||||||
|
except Exception as exc:
|
||||||
|
return Result(data="", errors=[ErrorInfo(kind=ErrorKind.INTERNAL, message=str(exc), source="ai_client.llama_native", original=exc)])
|
||||||
def _list_llama_models() -> list[str]:
|
def _list_llama_models() -> list[str]:
|
||||||
from src.vendor_capabilities import list_models_for_vendor
|
from src.vendor_capabilities import list_models_for_vendor
|
||||||
return list_models_for_vendor("llama")
|
return list_models_for_vendor("llama")
|
||||||
|
|||||||
Reference in New Issue
Block a user