1515 Chat ,
1616 DictSchema ,
1717 LlmInfo ,
18+ LlmPredictionConfigDict ,
1819 LlmPredictionFragment ,
1920 LlmPredictionStats ,
2021 LMStudioModelNotFoundError ,
2728 EXPECTED_LLM_ID ,
2829 PROMPT ,
2930 RESPONSE_FORMATS ,
31+ RESPONSE_SCHEMA ,
32+ SCHEMA_FIELDS ,
3033 SHORT_PREDICTION_CONFIG ,
3134 check_sdk_error ,
3235)
@@ -93,7 +96,7 @@ async def test_complete_stream_async(caplog: LogCap) -> None:
9396@pytest .mark .asyncio
9497@pytest .mark .lmstudio
9598@pytest .mark .parametrize ("format_type" , RESPONSE_FORMATS )
96- async def test_complete_structured_async (
99+ async def test_complete_response_format_async (
97100 format_type : Type [ModelSchema ] | DictSchema , caplog : LogCap
98101) -> None :
99102 prompt = PROMPT
@@ -107,7 +110,35 @@ async def test_complete_structured_async(
107110 assert isinstance (response .content , str )
108111 assert isinstance (response .parsed , dict )
109112 assert response .parsed == json .loads (response .content )
110- assert "response" in response .parsed
113+ assert SCHEMA_FIELDS .keys () == response .parsed .keys ()
114+
115+
116+ @pytest .mark .asyncio
117+ @pytest .mark .lmstudio
118+ async def test_complete_structured_config_async (caplog : LogCap ) -> None :
119+ prompt = PROMPT
120+ caplog .set_level (logging .DEBUG )
121+ model_id = EXPECTED_LLM_ID
122+ async with AsyncClient () as client :
123+ llm = await client .llm .model (model_id )
124+ config : LlmPredictionConfigDict = {
125+ # snake_case keys are accepted at runtime,
126+ # but the type hinted spelling is the camelCase names
127+ # This test case checks the schema field name is converted,
128+ # but *not* the snake_case and camelCase field names in the
129+ # schema itself
130+ "structured" : {
131+ "type" : "json" ,
132+ "json_schema" : RESPONSE_SCHEMA ,
133+ } # type: ignore[typeddict-item]
134+ }
135+ response = await llm .complete (prompt , config = config )
136+ assert isinstance (response , PredictionResult )
137+ logging .info (f"LLM response: { response !r} " )
138+ assert isinstance (response .content , str )
139+ assert isinstance (response .parsed , dict )
140+ assert response .parsed == json .loads (response .content )
141+ assert SCHEMA_FIELDS .keys () == response .parsed .keys ()
111142
112143
113144@pytest .mark .asyncio
0 commit comments