Skip to content

Commit

Permalink
add support for format
Browse files Browse the repository at this point in the history
  • Loading branch information
adilhafeez committed Dec 11, 2024
1 parent 5bf9a80 commit 0ef9d62
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 19 deletions.
2 changes: 2 additions & 0 deletions arch/arch_config_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ properties:
type: string
in_path:
type: boolean
format:
type: string
additionalProperties: false
required:
- name
Expand Down
5 changes: 5 additions & 0 deletions crates/common/src/api/open_ai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ pub struct FunctionParameter {
pub enum_values: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub default: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub format: Option<String>,
}

impl Serialize for FunctionParameter {
Expand All @@ -96,6 +98,9 @@ impl Serialize for FunctionParameter {
if let Some(default) = &self.default {
map.serialize_entry("default", default)?;
}
if let Some(format) = &self.format {
map.serialize_entry("format", format)?;
}
map.end()
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/common/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ pub struct Parameter {
pub enum_values: Option<Vec<String>>,
pub default: Option<String>,
pub in_path: Option<bool>,
pub format: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Default)]
Expand Down Expand Up @@ -250,6 +251,7 @@ impl From<&PromptTarget> for ChatCompletionTool {
required: entity.required,
enum_values: entity.enum_values.clone(),
default: entity.default.clone(),
format: entity.format.clone(),
};
properties.insert(entity.name.clone(), param);
}
Expand Down
1 change: 1 addition & 0 deletions demos/weather_forecast/arch_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ prompt_targets:
description: The location to get the weather for
required: true
type: string
format: city, state
- name: days
description: the number of days for the request
required: true
Expand Down
70 changes: 63 additions & 7 deletions e2e_tests/api_model_server.rest
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ Content-Type: application/json
"description": "The location to get the weather for",
"format": "City, State"
},
"unit": {
"type": "str",
"description": "The unit to return the weather in.",
"enum": ["celsius", "fahrenheit"],
"default": "celsius"
},
"days": {
"type": "str",
"description": "the number of days for the request."
Expand Down Expand Up @@ -236,7 +230,6 @@ Content-Type: application/json
}



### archgw to model_server 2
POST {{model_server_endpoint}}/function_calling HTTP/1.1
Content-Type: application/json
Expand Down Expand Up @@ -292,3 +285,66 @@ Content-Type: application/json
],
"stream": false
}


### archgw to model_server 3
POST {{model_server_endpoint}}/function_calling HTTP/1.1
Content-Type: application/json

{
"model": "--",
"messages": [
{
"role": "user",
"content": "how is the weather in seattle"
},
{
"role": "assistant",
"content": "Of course, I can help with that. Could you please specify the days you want the weather forecast for?",
"model": "Arch-Function"
},
{
"role": "user",
"content": "for 2 days please"
}
],
"tools": [
{
"id": "weather-112",
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get current weather at a location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "str",
"description": "The location to get the weather for",
"format": "City, State"
},
"days": {
"type": "str",
"description": "the number of days for the request"
}
},
"required": [
"days", "location"
]
}
}
},
{
"type": "function",
"function": {
"name": "default_target",
"description": "This is the default target for all unmatched prompts.",
"parameters": {
"type": "object",
"properties": {}
}
}
}
],
"stream": true
}
9 changes: 0 additions & 9 deletions e2e_tests/api_prompt_gateway.rest
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,6 @@ Content-Type: application/json
{
"role": "user",
"content": "for next 10 days"
},
{
"role": "assistant",
"content": "Could you tell me what units you want the weather in? (For example: Celsius or Fahrenheit)",
"model": "Arch-Function-1.5b"
},
{
"role": "user",
"content": "Fahrenheit"
}
]
}
Expand Down
6 changes: 3 additions & 3 deletions e2e_tests/test_prompt_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_prompt_gateway_param_gathering(stream):
def test_prompt_gateway_param_tool_call(stream):
expected_tool_call = {
"name": "get_current_weather",
"arguments": {"location": "seattle", "days": "2"},
"arguments": {"location": "seattle, wa", "days": "2"},
}

body = {
Expand All @@ -181,11 +181,11 @@ def test_prompt_gateway_param_tool_call(stream):
{
"role": "assistant",
"content": "Of course, I can help with that. Could you please specify the days you want the weather forecast for?",
"model": "Arch-Function-1.5B",
"model": "Arch-Function",
},
{
"role": "user",
"content": "2 days",
"content": "for 2 days please",
},
],
"stream": stream,
Expand Down
7 changes: 7 additions & 0 deletions model_server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ archgw_modelserver = "src.cli:run_server"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
python_files = ["test*.py"]
addopts = ["-v", "-s"]
retries = 2
retry_delay = 0.5
cumulative_timing = false

0 comments on commit 0ef9d62

Please sign in to comment.