MCPcopy Create free account
hub / github.com/microsoft/TypeChat / main

Function main

python/examples/music/demo.py:10–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8from client import handle_call, get_client_context
9
10async def main():
11 env_vals = dotenv_values()
12 model = create_language_model(env_vals)
13 validator = TypeChatValidator(music.PlayerActions)
14 translator = TypeChatJsonTranslator(model, validator, music.PlayerActions)
15 player_context = await get_client_context(env_vals)
16
17 async def request_handler(message: str):
18 result = await translator.translate(message)
19 if isinstance(result, Failure):
20 print(result.message)
21 else:
22 result = result.value
23 print(json.dumps(result, indent=2))
24 try:
25 for action in result["actions"]:
26 await handle_call(action, player_context)
27 except Exception as error:
28 print("An exception occurred: ", error)
29
30 if any(item["actionName"] == "Unknown" for item in result["actions"]):
31 print("I did not understand the following")
32 for item in result["actions"]:
33 if item["actionName"] == "Unknown":
34 print(item["text"])
35
36 file_path = sys.argv[1] if len(sys.argv) == 2 else None
37 await process_requests("🎵> ", file_path, request_handler)
38
39
40if __name__ == "__main__":

Callers 1

demo.pyFile · 0.70

Calls 5

create_language_modelFunction · 0.90
TypeChatValidatorClass · 0.90
get_client_contextFunction · 0.90
process_requestsFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…