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

Class MusicAgent

python/examples/multiSchema/agents.py:92–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90
91
92class MusicAgent:
93 _validator: TypeChatValidator[music_schema.PlayerActions]
94 _translator: TypeChatJsonTranslator[music_schema.PlayerActions]
95 _client_context: ClientContext | None
96 _authentication_vals: dict[str, str | None]
97
98 def __init__(self, model: TypeChatLanguageModel, authentication_vals: dict[str, str | None]):
99 super().__init__()
100 self._validator = TypeChatValidator(music_schema.PlayerActions)
101 self._translator = TypeChatJsonTranslator(model, self._validator, music_schema.PlayerActions)
102 self._authentication_vals = authentication_vals
103 self._client_context = None
104
105 async def authenticate(self):
106 self._client_context = await get_client_context(self._authentication_vals)
107
108 async def handle_request(self, line: str):
109 if not self._client_context:
110 await self.authenticate()
111
112 assert self._client_context
113 result = await self._translator.translate(line)
114 if isinstance(result, Failure):
115 print(result.message)
116 else:
117 result = result.value
118 print(json.dumps(result, indent=2))
119
120 try:
121 for action in result["actions"]:
122 await handle_call(action, self._client_context)
123 except Exception as error:
124 print("An exception occurred: ", error)

Callers 1

mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…