diff --git a/integrations/top_chess_players/README.md b/integrations/top_chess_players/README.md new file mode 100644 index 00000000..91b5d947 --- /dev/null +++ b/integrations/top_chess_players/README.md @@ -0,0 +1,34 @@ +# uAgents Top Chess Players Integration + +## Overview +This integration allows users to search for the top 10 chess players on Lichess.com based on different gamemodes. It leverages the Lichess.com API to fetch player details. The integration is designed to run as an hosted uAgent on the Agentverse platform and can be interacted using deltaV, providing seamless song search functionality through a conversational interface. The agent has utilized the Chitchat Dialogue schema to allow the user to ask multiple rankings consecutively on DeltaV. + +API Documentation: `https://lichess.org/api` + +## Steps to use this integration on DeltaV +### This integration is already published and is available on DeltaV. The steps below outline the process of deploying a new agent function for DeltaV. + +1. Navigate to `https://agentverse.ai/agents` and log in. +2. Click on the `+ New Agent` button -> Choose `Skeleton Agent` -> Click on the `Create` button. +3. Copy the contents of `agent.py` in this repository and paste these contents in the `agent.py` file in the code editor on `Agentverse`. +4. Click on `Start` on the top-right just above the code editor. +5. To host this agent as a `Function` for discovery on `DeltaV`, click on `Deploy` and click on `+ New Function`. +6. Enter the `Function` details: +- Enter a suitable name for the function, we used the name: `Top Chess Players Dialogue`. +- Enter a suitable description for the function, we used the description: `This Function helps user to check the top 10 players for more than one perfType.` +7. The other details should be left as their default value(s). +8. Click on the `Create Function` button. +9. After the `Function` has been created, you can test the function on `DeltaV`, this can be done by going the link: `https://deltav.agentverse.ai` or by clicking on the `Test in deltav` button in the `Agentverse` UI. +10. Once satisfied with the results, we can publish the function. Click on the `Publish` button, read and accept the `Terms and Conditions` and click on `OK`. + +## Expected Output +Results: The agent provides a list of top 10 player usernames for the gamemode entered by the user. + +![alt text](./deltav_output_1.png) + +![alt text](./deltav_output_2.png) + + +## Future Work +- Currently only the top 10 players are returned, allowing users to input the number of users they want to see would a good next step. +- Implementing agents for all the `Lichess.com` APIs and creating them as `Secondary Functions` would a good next step to allow the user to interact with the APIs completely. diff --git a/integrations/top_chess_players/agent.py b/integrations/top_chess_players/agent.py new file mode 100644 index 00000000..10e6db53 --- /dev/null +++ b/integrations/top_chess_players/agent.py @@ -0,0 +1,118 @@ +# Import required libraries +import requests +from ai_engine.chitchat import ChitChatDialogue +from ai_engine.messages import DialogueMessage +from uagents import Context, Model + + +class InitiateChitChatDialogue(Model): + """I initiate ChitChat dialogue request""" + pass + + +class AcceptChitChatDialogue(Model): + """I accept ChitChat dialogue request""" + pass + + +class ChitChatDialogueMessage(DialogueMessage): + """ChitChat dialogue message""" + pass + + +class ConcludeChitChatDialogue(Model): + """I conclude ChitChat dialogue request""" + pass + + +class RejectChitChatDialogue(Model): + """I reject ChitChat dialogue request""" + pass + + +async def get_players(perfType): + url = f"https://lichess.org/api/player/top/10/{perfType}" + response = requests.get(url) + data = response.json() + return data + +chitchat_dialogue = ChitChatDialogue( + version="0.11.1", # example 0.11.1 + storage=agent.storage, +) + + +@chitchat_dialogue.on_initiate_session(InitiateChitChatDialogue) +async def start_chitchat( + ctx: Context, + sender: str, + msg: InitiateChitChatDialogue, +): + ctx.logger.info(f"Received init message from { + sender} Session: {ctx.session}") + # do something when the dialogue is initiated + await ctx.send(sender, AcceptChitChatDialogue()) + + +@chitchat_dialogue.on_start_dialogue(AcceptChitChatDialogue) +async def accepted_chitchat( + ctx: Context, + sender: str, + _msg: AcceptChitChatDialogue, +): + ctx.logger.info( + f"session with { + sender} was accepted. This shouldn't be called as this agent is not the initiator." + ) + + +@chitchat_dialogue.on_reject_session(RejectChitChatDialogue) +async def reject_chitchat( + ctx: Context, + sender: str, + _msg: RejectChitChatDialogue, +): + # do something when the dialogue is rejected and nothing has been sent yet + ctx.logger.info(f"Received conclude message from: {sender}") + + +@chitchat_dialogue.on_continue_dialogue(ChitChatDialogueMessage) +async def continue_chitchat( + ctx: Context, + sender: str, + msg: ChitChatDialogueMessage, +): + # do something when the dialogue continues + ctx.logger.info(f"Received message: {msg.user_message} from: {sender}") + if msg.user_message not in ["ultraBullet", "bullet", "blitz", "rapid", "classical", "chess960", "crazyhouse", "antichess", "atomic", "horde", "kingOfTheHill", "racingKings", "threeCheck"]: + final_string = f'Not a valid gamemode' + else: + top_players = await get_players(msg.user_message) + user_ids = [user['id'] for user in top_players['users']] + ctx.logger.info(f"Data: {top_players}") + final_string = f'The top 10 players are {", ".join(user_ids)}' + try: + await ctx.send( + sender, + ChitChatDialogueMessage( + type="agent_message", + agent_message=final_string + ), + ) + except EOFError: + await ctx.send(sender, ConcludeChitChatDialogue()) + + +@chitchat_dialogue.on_end_session(ConcludeChitChatDialogue) +async def conclude_chitchat( + ctx: Context, + sender: str, + _msg: ConcludeChitChatDialogue, +): + # do something when the dialogue is concluded after messages have been exchanged + ctx.logger.info(f"Received conclude message from: { + sender}; accessing history:") + ctx.logger.info(chitchat_dialogue.get_conversation(ctx.session)) + + +agent.include(chitchat_dialogue, publish_manifest=True) diff --git a/integrations/top_chess_players/deltav_output_1.png b/integrations/top_chess_players/deltav_output_1.png new file mode 100644 index 00000000..f280c290 Binary files /dev/null and b/integrations/top_chess_players/deltav_output_1.png differ diff --git a/integrations/top_chess_players/deltav_output_2.png b/integrations/top_chess_players/deltav_output_2.png new file mode 100644 index 00000000..cfb14433 Binary files /dev/null and b/integrations/top_chess_players/deltav_output_2.png differ diff --git a/integrations/top_chess_players/project.json b/integrations/top_chess_players/project.json new file mode 100644 index 00000000..d5489bbb --- /dev/null +++ b/integrations/top_chess_players/project.json @@ -0,0 +1,10 @@ +{ + "title": "Top Chess Players", + "description": "Top Chess Players is designed to fetch the top 10 chess players for gamemodes such as [\"ultraBullet\", \"bullet\", \"blitz\", \"rapid\", \"classical\", \"chess960\", \"crazyhouse\", \"antichess\", \"atomic\", \"horde\", \"kingOfTheHill\", \"racingKings\", \"threeCheck\"] on LiChess.com.", + "categories": [ + "Chess", + "AI Engine", + "API" + ], + "deltav": true +}