Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(integration): Chess player integration #529

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions integrations/top_chess_players/README.md
Original file line number Diff line number Diff line change
@@ -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.
118 changes: 118 additions & 0 deletions integrations/top_chess_players/agent.py
Original file line number Diff line number Diff line change
@@ -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)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions integrations/top_chess_players/project.json
Original file line number Diff line number Diff line change
@@ -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
}
Loading