Przeglądaj źródła

refac: ollama tool calling support

Co-Authored-By: smonux <85928277+smonux@users.noreply.github.com>
Timothy Jaeryang Baek 2 miesięcy temu
rodzic
commit
23df351239

+ 2 - 0
backend/open_webui/routers/ollama.py

@@ -939,6 +939,7 @@ async def generate_completion(
 class ChatMessage(BaseModel):
     role: str
     content: str
+    tool_calls: Optional[list[dict]] = None
     images: Optional[list[str]] = None
 
 
@@ -950,6 +951,7 @@ class GenerateChatCompletionForm(BaseModel):
     template: Optional[str] = None
     stream: Optional[bool] = True
     keep_alive: Optional[Union[int, str]] = None
+    tools: Optional[list[dict]] = None
 
 
 async def get_ollama_url(request: Request, model: str, url_idx: Optional[int] = None):

+ 7 - 0
backend/open_webui/utils/tools.py

@@ -73,6 +73,13 @@ def get_tools(
             # convert to function that takes only model params and inserts custom params
             original_func = getattr(module, function_name)
             callable = apply_extra_params_to_tool_function(original_func, extra_params)
+
+            if callable.__doc__ and callable.__doc__.strip() != "":
+                s = re.split(":(param|return)", callable.__doc__, 1)
+                spec["description"] = s[0]
+            else:
+                spec["description"] = function_name
+
             # TODO: This needs to be a pydantic model
             tool_dict = {
                 "toolkit_id": tool_id,