Skip to content

Commit

Permalink
feat: add debug-chat-completion-delay30s model
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkW77 authored and jameszyao committed Oct 10, 2024
1 parent 38a9d32 commit add30eb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
17 changes: 17 additions & 0 deletions inference/providers/debug/chat_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ async def chat_completion(
):
if provider_model_id == "debug-error" and messages[-1].content != "Only say your name":
raise_http_error(ErrorCode.PROVIDER_ERROR, "Debug error for test")

if provider_model_id == "debug-chat-completion-delay":
# content format should be "#number#some other content"
message = messages[-1].content
second = int(message.split("#")[1]) if message.startswith("#") else 30
import asyncio

await asyncio.sleep(second)

input_tokens = estimate_input_tokens(
[message.model_dump() for message in messages],
[function.model_dump() for function in functions] if functions else None,
Expand Down Expand Up @@ -99,6 +108,14 @@ async def chat_completion_stream(
if provider_model_id == "debug-error":
raise_http_error(ErrorCode.PROVIDER_ERROR, "Debug error for test")

if provider_model_id == "debug-chat-completion-delay":
# content format should be "#number#some other content"
message = messages[-1].content
second = int(message.split("#")[1]) if message.startswith("#") else 30
import asyncio

await asyncio.sleep(second)

if provider_model_id == "debug-tool-call-hallucinations" and messages[-1].role == ChatCompletionRole.user:
output_message = create_tool_call_hallucination_message()
finish_reason = ChatCompletionFinishReason.function_calls
Expand Down
3 changes: 3 additions & 0 deletions inference/providers/debug/resources/i18n/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ debug_api_key_description: "debug"
debug_chat_completion_name: "Debug Chat Completion"
debug_chat_completion_description: "Debug chat completion model for testing purposes."

debug_chat_completion_delay_name: "Debug Chat Completion Delay"
debug_chat_completion_delay_description: "Chat completion model with a delay for testing response latency and behavior."

debug_error_name: "Debug Error"
debug_error_description: "Debug error model for testing purposes."

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
model_schema_id: debug/debug-chat-completion-delay
provider_model_id: debug-chat-completion-delay
type: chat_completion
name: "i18n:debug_chat_completion_delay_name"
description: "i18n:debug_chat_completion_delay_description"
default_endpoint_url:


properties:
function_call: false
streaming: true
input_token_limit: 8096
output_token_limit: 8096

config_schemas:
- config_id: temperature
- config_id: top_p
- config_id: max_tokens
- config_id: stop
- config_id: top_k

pricing:
input_token: 0
output_token: 0
unit: 1000
currency: USD
2 changes: 1 addition & 1 deletion inference/providers/debug/resources/models/debug-error.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ default_endpoint_url:


properties:
function_call: false
function_call: true
streaming: true
input_token_limit: 8096
output_token_limit: 8096
Expand Down
7 changes: 4 additions & 3 deletions inference/test/test_chat_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def test_chat_completion_by_normal_function_call(self, test_data):
message = test_data["message"]
function_call = test_data["function_call"]

if not function_call or "azure" in model_schema_id or "openrouter" in model_schema_id:
if not function_call or "azure" in model_schema_id or "openrouter" or "debug-error" in model_schema_id:
pytest.skip("Skip the test case without function call.")
configs = {
"temperature": 0.5,
Expand Down Expand Up @@ -287,6 +287,7 @@ async def test_chat_completion_by_stream_and_function_call(self, test_data):
or not stream
or "azure" in model_schema_id
or "openrouter" in model_schema_id
or "debug-error" in model_schema_id
or "togetherai" in model_schema_id
):
pytest.skip("Skip the test case without function call or stream.")
Expand Down Expand Up @@ -384,7 +385,7 @@ async def test_chat_completion_by_function_call_and_length(self, test_data):
if (
not function_call
or "google_gemini" in model_schema_id
or "debug-tool-call-hallucinations" in model_schema_id
or "debug" in model_schema_id
or "sensetime" in model_schema_id
or "openrouter" in model_schema_id
):
Expand Down Expand Up @@ -445,7 +446,7 @@ async def test_chat_completion_by_stream_and_function_call_and_length(self, test
not function_call
or not stream
or "azure" in model_schema_id
or "debug-tool-call-hallucinations" in model_schema_id
or "debug" in model_schema_id
or "mistralai" in model_schema_id
or "google_gemini" in model_schema_id
or "sensetime" in model_schema_id
Expand Down

0 comments on commit add30eb

Please sign in to comment.