diff --git a/SERVER.md b/SERVER.md index 1517818b..6415708d 100644 --- a/SERVER.md +++ b/SERVER.md @@ -299,7 +299,7 @@ Modifies existing images based on a single prompt. } ``` -### 6. Text-to-Image: /v1/txt2speech +### 6. Text-to-Speech: /v1/txt2speech Generates wav format voices based on a single prompt. @@ -330,7 +330,57 @@ The `language` argument applies only to OuteTTS models. } ``` -### 7. Audio Transcriptions: /v1/audio/transcriptions +### 7. Function Calling API: /v1/function_calling + +Generate function calling command based on provided messages and available tools. + +#### Request body: + +```json +{ + "tools": [ + { + "type": "function", + "function": { + "name": "add_integer", + "description": "Returns the addition of input integers.", + "parameters": { + "type": "object", + "properties": { + "num1": {"type": "integer", "description": "An integer to add."}, + "num2": {"type": "integer", "description": "An integer to add."} + }, + "required": ["num1", "num2"], + "additionalProperties": false + }, + "strict": true + } + } + ], + "messages": [ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": "Please calculate the sum of 42 and 100."} + ] +} + +#### Example Response: + +```json +{ + "created": 1738610394.597405, + "response": [ + { + "type": "function", + "function": { + "name": "add_integer", + "arguments": "{\"num1\": 42, \"num2\": 100}" + } + } + ] +} +``` + +### 8. Audio Transcriptions: /v1/audio/transcriptions Transcribes audio files to text. @@ -356,7 +406,7 @@ Transcribes audio files to text. } ``` -### 8. Audio Translations: /v1/audio/translations +### 9. Audio Translations: /v1/audio/translations Translates audio files to text in English. @@ -381,7 +431,7 @@ Translates audio files to text in English. } ``` -### 9. Generate Embeddings: /v1/embeddings +### 10. Generate Embeddings: /v1/embeddings Generate embeddings for a given text. diff --git a/nexa/cli/entry.py b/nexa/cli/entry.py index 7ca998c5..8d3dae6c 100644 --- a/nexa/cli/entry.py +++ b/nexa/cli/entry.py @@ -160,7 +160,7 @@ def run_ggml_server(args): hf = kwargs.pop('huggingface', False) ms = kwargs.pop('modelscope', False) use_function_calling = kwargs.pop('function_calling', False) - + run_type = None if model_type: run_type = ModelType[model_type].value @@ -194,8 +194,8 @@ def run_ggml_server(args): model_type_arg=run_type, huggingface=hf, modelscope=ms, + function_calling=use_function_calling, projector_local_path_arg=projector_local_path, - use_function_calling=use_function_calling **kwargs ) diff --git a/nexa/gguf/server/nexa_service.py b/nexa/gguf/server/nexa_service.py index 19d51252..30e49e57 100644 --- a/nexa/gguf/server/nexa_service.py +++ b/nexa/gguf/server/nexa_service.py @@ -357,12 +357,6 @@ async def load_model(): global model, chat_format, completion_template, model_path, n_ctx, is_local_path, model_type, is_huggingface, is_modelscope, projector_path global use_function_calling - if use_function_calling and model_type != "NLP": - raise ValueError( - "Function calling is only supported for NLP models. " - "Please ensure that you are using a compatible NLP model before enabling this feature." - ) - if is_local_path: if model_type == "Multimodal": if not projector_path: @@ -394,6 +388,12 @@ async def load_model(): if use_function_calling: print('Function calling option is enabled') + if use_function_calling and model_type != "NLP": + raise ValueError( + "Function calling is only supported for NLP models. " + "Please ensure that you are using a compatible NLP model before enabling this feature." + ) + if model_type == "NLP" or model_type == "Text Embedding": if model_type == "NLP" and use_function_calling: from nexa.gguf.nexa_inference_text import NexaTextInference @@ -768,7 +768,7 @@ def load_audio_from_bytes(audio_bytes: bytes): a = librosa.resample(a, orig_sr=sr, target_sr=SAMPLING_RATE) return a -def run_nexa_ai_service(model_path_arg=None, is_local_path_arg=False, model_type_arg=None, huggingface=False, modelscope=False, projector_local_path_arg=None, function_calling=False, **kwargs): +def run_nexa_ai_service(model_path_arg=None, is_local_path_arg=False, model_type_arg=None, huggingface=False, modelscope=False, function_calling=False, projector_local_path_arg=None, **kwargs): global model_path, n_ctx, is_local_path, model_type, is_huggingface, is_modelscope, projector_path, use_function_calling is_local_path = is_local_path_arg is_huggingface = huggingface