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

Feature cookie api #22

Merged
merged 40 commits into from
Feb 7, 2025
Merged

Feature cookie api #22

merged 40 commits into from
Feb 7, 2025

Conversation

AlexM369
Copy link
Contributor

This PR integrates three new API endpoints from cookie.fun into the repo, enabling retrieval of agent details via different identifiers. The changes include:
Get Agent by Twitter Username
• Retrieves agent details based on a given Twitter username at a specified interval.
• Example: "get agent metrics for twitter username 'griffaindotcom'"

Get Agent by Contract Address
• Retrieves agent details based on a supported token contract address.
• Also enables token symbol lookup using ChainConfig.get_token_info_or_none() from config.py.
• Example: "What are mindshare metrics for SEKOIA?" or "Mindshare change of 0xc0041ef357b183448b235a8ea73ce4e4ec8c265f"

Get Agents Paged
• Retrieves a paginated list of agents ordered by 7-day mindshare (descending).
• Example: "What are top 25 AI agents?"

@AlexM369 AlexM369 requested a review from gkoch78 January 31, 2025 18:58
Comment on lines 121 to 123
except Exception:
logger.exception(f"Failed to find token address for {symbol}")
return None, None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be better to raise the exception here, rather than return (None, None) to differentiate between actually no result and error in execution

Suggested change
except Exception:
logger.exception(f"Failed to find token address for {symbol}")
return None, None
except Exception:
logger.exception(f"Failed to find token address for {symbol}")
raise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


@dataclass
class Tweet:
tweetUrl: str
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property name in python should be lower_snake_case. To enable proper mapping with API schema, use tweet_url: str = Field(alias="tweet_url")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made changes

Comment on lines 243 to 248
return PagedAgentsResponse(
data=[AgentMetrics(**agent) for agent in data["data"]],
currentPage=data["currentPage"],
totalPages=data["totalPages"],
totalCount=data["totalCount"],
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pydantic dataclasses should already handling this for you. This might work

Suggested change
return PagedAgentsResponse(
data=[AgentMetrics(**agent) for agent in data["data"]],
currentPage=data["currentPage"],
totalPages=data["totalPages"],
totalCount=data["totalCount"],
)
return PagedAgentsResponse(**data)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

def cookiefun_client(default_config: Config) -> CookieFunClient:
"""Create CookieFun client for testing"""
# Set test API key if not present
return CookieFunClient()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would properly the API key to be set in CI

Copy link
Contributor

@gkoch78 gkoch78 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see inline comments

alphaswarm/services/cookiefun/cookiefun_client.py Outdated Show resolved Hide resolved
Comment on lines 46 to 62
agent_name: str = Field(alias="agentName")
twitter_usernames: List[str] = Field(alias="twitterUsernames")
mindshare_delta_percent: float = Field(alias="mindshareDeltaPercent")
market_cap: float = Field(alias="marketCap")
market_cap_delta_percent: float = Field(alias="marketCapDeltaPercent")
price_delta_percent: float = Field(alias="priceDeltaPercent")
volume_24_hours: float = Field(alias="volume24Hours")
volume_24_hours_delta_percent: float = Field(alias="volume24HoursDeltaPercent")
holders_count: int = Field(alias="holdersCount")
holders_count_delta_percent: float = Field(alias="holdersCountDeltaPercent")
average_impressions_count: float = Field(alias="averageImpressionsCount")
average_impressions_count_delta_percent: float = Field(alias="averageImpressionsCountDeltaPercent")
average_engagements_count: float = Field(alias="averageEngagementsCount")
average_engagements_count_delta_percent: float = Field(alias="averageEngagementsCountDeltaPercent")
followers_count: int = Field(alias="followersCount")
smart_followers_count: int = Field(alias="smartFollowersCount")
top_tweets: List[Tweet] = Field(alias="topTweets")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we group in a logical manner all those fields

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like
`
# Optional/fields with defaults after
# Basic agent info
agent_name: str = Field(alias="agentName")
twitter_usernames: List[str] = Field(alias="twitterUsernames")

# Market metrics
market_cap: float = Field(alias="marketCap") 
market_cap_delta_percent: float = Field(alias="marketCapDeltaPercent")
price_delta_percent: float = Field(alias="priceDeltaPercent")
volume_24_hours: float = Field(alias="volume24Hours")
volume_24_hours_delta_percent: float = Field(alias="volume24HoursDeltaPercent")

# Mindshare metrics
mindshare_delta_percent: float = Field(alias="mindshareDeltaPercent")

# Holder metrics
holders_count: int = Field(alias="holdersCount")
holders_count_delta_percent: float = Field(alias="holdersCountDeltaPercent")

# Engagement metrics
average_impressions_count: float = Field(alias="averageImpressionsCount")
average_impressions_count_delta_percent: float = Field(alias="averageImpressionsCountDeltaPercent")
average_engagements_count: float = Field(alias="averageEngagementsCount") 
average_engagements_count_delta_percent: float = Field(alias="averageEngagementsCountDeltaPercent")

# Social metrics
followers_count: int = Field(alias="followersCount")
smart_followers_count: int = Field(alias="smartFollowersCount")
top_tweets: List[Tweet] = Field(alias="topTweets")

`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but this is the order in api output schema. Wouldn't it be easier to reconcile dataclass with api for users if in same order?

alphaswarm/services/cookiefun/cookiefun_client.py Outdated Show resolved Hide resolved
logger.exception("Error fetching data from Cookie.fun")
raise

def _parse_agent_response(self, response_data: dict) -> AgentMetrics:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _parse_agent_response(self, response_data: dict) -> AgentMetrics:
def _parse_agent_metrics_response(self, response_data: dict) -> AgentMetrics:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

alphaswarm/services/cookiefun/cookiefun_client.py Outdated Show resolved Hide resolved
alphaswarm/services/cookiefun/cookiefun_client.py Outdated Show resolved Hide resolved
ApiException: If API request fails
"""
if not 1 <= page_size <= 25:
raise ValueError("page_size must be between 1 and 25")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise ValueError("page_size must be between 1 and 25")
raise ValueError(f"page_size must be between 1 and 25, got {page_size}")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

alphaswarm/tools/cookie/cookie_metrics.py Outdated Show resolved Hide resolved
@AlexM369 AlexM369 requested review from aflament and gkoch78 February 3, 2025 15:21
Copy link
Contributor

@aflament aflament left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😔

@AlexM369 AlexM369 merged commit 0f40685 into main Feb 7, 2025
2 checks passed
@AlexM369 AlexM369 deleted the feature_cookie_api branch February 7, 2025 14:02
ethancjackson added a commit that referenced this pull request Feb 7, 2025
* feat cookiefun api

* feat cookiefun api Get Agents Paged functionality

* refactor cookiefun api

* add cookie tools to examples/terminal

* add integration test for cookie fun api

* feat cookie fun api by token address

* add cookie fun metrics by token symbol

* add conftest to cookie integration test

* reformat code to fix linting

* reformat imports using poetry

* fix property names to be lower_snake_case

* fix linting

* fix linting

* refactor method naming

* refactor method naming

* add CookieMetricsBySymbol as tool

* add cookie_metrics to examples/terminal

* fix linting

* resolve merge conflict in examples/terminal

* add default values to cookiefun_client

* fix linting

* fix linting

* add default values to dataclasses

* fix linting

* Decouple trading strategy from core AlphaSwarmAgent. (#32)

* momentum strategy analysis as agent specilization instead of tool (#27)

* inital work on research agent

* rename to momentum strategy agent; added price chg calculator tool

* lint

* Remove lab directory from git tracking

* Implement telegram image sending

* Refactor evm client (#28)

* extract erc20contract

* WIP signing transaction

* lint

* clean up

* clean up

* use EMVClient in Uniswap

* clean up

* clean up

* clean up

* clean up

* clean up

* clean up

* clean up ExactInputSingleParams

* Create test_v3_router_contract.py

* more clean up

* more clean up

* more clean up

* fix test

* Install matplotlib

* Progress

* Fix output formatting (#35)

* Introduce hints file

* Tune instructions in SendTelegramNotificationTool

* Use claude-3-5-sonnet-20241022 as a model

* Rename token_set to token_name_to_address

* Fix comments

* Add manual test for swap (#40)

* add a couple of integration test on swap to run manually

* add ExecuteSwapTool in terminal

* quick fix

* Adding project README and basic examples (#26)

* Update README
* Introduce basic tutorial examples

---------

Co-authored-by: Arnaud Flament <[email protected]>

* Create image as part of forecasting tool

* reorganize lab agent tools; cookie tool description update

* fixed wrong substitution in system prompt

* added trading to lab advisor agent

* simplified momentum agent in lab

* Feature uniswap more clean up (#42)

* use TokenInfo to convert in uniswap v2

* clean up private key and wallet address in UniswapClientBase

* clean up PoolContract

* fix return type for ERC20Cotnract.get_balance

* clean up

* fix integration test

* Fix Telegram RuntimeError('Event loop is closed')

* simiplfy cookie page description

* Fix Telegram RuntimeError('Event loop is closed') (#44)

* Decouple Config from class constructors (#45)

* Initial commit

* Merge with main

* Update

* Code clean-up (#46)

* Code clean-up

* Update

* Fix tests

* fix tests

* Feature more lint (#47)

* lint

* more lint

* more lint

* clean up

* clean up

* enable `warn_unused_ignores` (#48)

* enable `warn_unused_ignores`

* Update terminal.py

* updated research system prompt

* Feature introduce slippage class (#50)

* Create Slippage class

* Add Unit tests

* Update

* Feature improve CI (#49)

* add test reports to CI

* update test artifacts

* Update python.yaml

* Update python.yaml

* lint

* Update pyproject.toml

* fix workflow

* Feature fix decimal from float (#51)

* Update sol.py

* Update sol.py

* Update sol.py

* Feature cookie api (#22)

* feat cookiefun api

* feat cookiefun api Get Agents Paged functionality

* refactor cookiefun api

* add cookie tools to examples/terminal

* add integration test for cookie fun api

* feat cookie fun api by token address

* add cookie fun metrics by token symbol

* add conftest to cookie integration test

* reformat code to fix linting

* reformat imports using poetry

* fix property names to be lower_snake_case

* fix linting

* fix linting

* refactor method naming

* refactor method naming

* add CookieMetricsBySymbol as tool

* add cookie_metrics to examples/terminal

* fix linting

* resolve merge conflict in examples/terminal

* add default values to cookiefun_client

* fix linting

* fix linting

* add default values to dataclasses

* fix linting

* add token details todefault

* added cookie api key to github workflow

* fix linting

* fix linting

* add typing

* add cookiefun_client to conftest

---------

Co-authored-by: AlexM369 <[email protected]>
Co-authored-by: Ethan <[email protected]>

* research agent system prompt tweaks

* debugging

* resolve merge errors

---------

Co-authored-by: AlexM369 <[email protected]>
Co-authored-by: Dmytro Nikolaiev <[email protected]>
Co-authored-by: Guillaume Koch <[email protected]>
Co-authored-by: david <[email protected]>
Co-authored-by: Arnaud Flament <[email protected]>
Co-authored-by: Arnaud Flament <[email protected]>
Co-authored-by: AlexM369 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants