Skip to content

Commit

Permalink
Fixed function calling server api bugs; Updated SERVER.md
Browse files Browse the repository at this point in the history
  • Loading branch information
xsxszab committed Feb 3, 2025
1 parent 79a53cd commit c6a46f8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 13 deletions.
58 changes: 54 additions & 4 deletions SERVER.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ Modifies existing images based on a single prompt.
}
```

### 6. Text-to-Image: <code>/v1/txt2speech</code>
### 6. Text-to-Speech: <code>/v1/txt2speech</code>

Generates wav format voices based on a single prompt.

Expand Down Expand Up @@ -330,7 +330,57 @@ The `language` argument applies only to OuteTTS models.
}
```

### 7. Audio Transcriptions: <code>/v1/audio/transcriptions</code>
### 7. Function Calling API: <code>/v1/function_calling</code>

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: <code>/v1/audio/transcriptions</code>

Transcribes audio files to text.

Expand All @@ -356,7 +406,7 @@ Transcribes audio files to text.
}
```

### 8. Audio Translations: <code>/v1/audio/translations</code>
### 9. Audio Translations: <code>/v1/audio/translations</code>

Translates audio files to text in English.

Expand All @@ -381,7 +431,7 @@ Translates audio files to text in English.
}
```

### 9. Generate Embeddings: <code>/v1/embeddings</code>
### 10. Generate Embeddings: <code>/v1/embeddings</code>

Generate embeddings for a given text.

Expand Down
4 changes: 2 additions & 2 deletions nexa/cli/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)

Expand Down
14 changes: 7 additions & 7 deletions nexa/gguf/server/nexa_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c6a46f8

Please sign in to comment.