1010app = MCPApp (name = "llm_selector" )
1111model_selector = ModelSelector ()
1212
13+
1314@app .tool
14- async def example_usage ()-> str :
15+ async def example_usage () -> str :
1516 """
1617 An example function/tool that demonstrates MCP's ModelPreferences type
1718 to select a model based on speed, cost, and intelligence priorities.
@@ -31,7 +32,7 @@ async def example_usage()->str:
3132 "Smartest OpenAI model:" ,
3233 data = {"model_preferences" : model_preferences , "model" : model },
3334 )
34- result += "Smartest OpenAI model: " + model .name
35+ result += "Smartest OpenAI model: " + model .name
3536
3637 model_preferences = ModelPreferences (
3738 costPriority = 0.25 , speedPriority = 0.25 , intelligencePriority = 0.5
@@ -44,7 +45,7 @@ async def example_usage()->str:
4445 "Most balanced OpenAI model:" ,
4546 data = {"model_preferences" : model_preferences , "model" : model },
4647 )
47- result += "\n Most balanced OpenAI model: " + model .name
48+ result += "\n Most balanced OpenAI model: " + model .name
4849
4950 model_preferences = ModelPreferences (
5051 costPriority = 0.3 , speedPriority = 0.6 , intelligencePriority = 0.1
@@ -57,7 +58,7 @@ async def example_usage()->str:
5758 "Fastest and cheapest OpenAI model:" ,
5859 data = {"model_preferences" : model_preferences , "model" : model },
5960 )
60- result += "\n Fastest and cheapest OpenAI model: " + model .name
61+ result += "\n Fastest and cheapest OpenAI model: " + model .name
6162
6263 model_preferences = ModelPreferences (
6364 costPriority = 0.1 , speedPriority = 0.1 , intelligencePriority = 0.8
@@ -70,7 +71,7 @@ async def example_usage()->str:
7071 "Smartest Anthropic model:" ,
7172 data = {"model_preferences" : model_preferences , "model" : model },
7273 )
73- result += "\n Smartest Anthropic model: " + model .name
74+ result += "\n Smartest Anthropic model: " + model .name
7475
7576 model_preferences = ModelPreferences (
7677 costPriority = 0.8 , speedPriority = 0.1 , intelligencePriority = 0.1
@@ -83,7 +84,7 @@ async def example_usage()->str:
8384 "Cheapest Anthropic model:" ,
8485 data = {"model_preferences" : model_preferences , "model" : model },
8586 )
86- result += "\n Cheapest Anthropic model: " + model .name
87+ result += "\n Cheapest Anthropic model: " + model .name
8788
8889 model_preferences = ModelPreferences (
8990 costPriority = 0.1 ,
@@ -101,7 +102,7 @@ async def example_usage()->str:
101102 "Select fastest model between gpt-4o/mini/sonnet/haiku:" ,
102103 data = {"model_preferences" : model_preferences , "model" : model },
103104 )
104- result += "\n Select fastest model between gpt-4o/mini/sonnet/haiku: " + model .name
105+ result += "\n Select fastest model between gpt-4o/mini/sonnet/haiku: " + model .name
105106
106107 model_preferences = ModelPreferences (
107108 costPriority = 0.15 ,
@@ -119,7 +120,7 @@ async def example_usage()->str:
119120 "Most balanced model between gpt-4o/mini/sonnet/haiku:" ,
120121 data = {"model_preferences" : model_preferences , "model" : model },
121122 )
122- result += "\n Most balanced model between gpt-4o/mini/sonnet/haiku: " + model .name
123+ result += "\n Most balanced model between gpt-4o/mini/sonnet/haiku: " + model .name
123124
124125 # Examples showcasing new filtering capabilities
125126 print ("\n [bold cyan]Testing new filtering capabilities:[/bold cyan]" )
@@ -139,7 +140,7 @@ async def example_usage()->str:
139140 "context_window" : model .context_window ,
140141 },
141142 )
142- result += "\n Best model with context window >100k tokens: " + model .name
143+ result += "\n Best model with context window >100k tokens: " + model .name
143144
144145 # Example 2: Models with tool calling support
145146 model_preferences = ModelPreferences (
@@ -156,7 +157,7 @@ async def example_usage()->str:
156157 "tool_calling" : model .tool_calling ,
157158 },
158159 )
159- result += "\n Best model with tool calling support: " + model .name
160+ result += "\n Best model with tool calling support: " + model .name
160161
161162 # Example 3: Models with structured outputs (JSON mode)
162163 model_preferences = ModelPreferences (
@@ -173,7 +174,7 @@ async def example_usage()->str:
173174 "structured_outputs" : model .structured_outputs ,
174175 },
175176 )
176- result += "\n Best model with structured outputs support: " + model .name
177+ result += "\n Best model with structured outputs support: " + model .name
177178
178179 # Example 4: Models with medium context window (50k-150k tokens) and tool calling
179180 model_preferences = ModelPreferences (
@@ -194,7 +195,9 @@ async def example_usage()->str:
194195 "tool_calling" : model .tool_calling ,
195196 },
196197 )
197- result += "\n Best model with 50k-150k context window and tool calling: " + model .name
198+ result += (
199+ "\n Best model with 50k-150k context window and tool calling: " + model .name
200+ )
198201
199202 # Example 5: Fast models with both tool calling and structured outputs
200203 model_preferences = ModelPreferences (
@@ -213,9 +216,12 @@ async def example_usage()->str:
213216 "speed" : model .metrics .speed .tokens_per_second ,
214217 },
215218 )
216- result += "\n Fastest model with both tool calling and structured outputs: " + model .name
219+ result += (
220+ "\n Fastest model with both tool calling and structured outputs: " + model .name
221+ )
222+
223+ return result
217224
218- return result
219225
220226if __name__ == "__main__" :
221227 import time
0 commit comments