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

Gemini request mech tool #228

Merged
merged 9 commits into from
Jun 17, 2024
Merged
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
4 changes: 2 additions & 2 deletions .example.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FILE_HASH_TO_TOOLS='[["bafybeibdcttrlgp5udygntka5fofi566pitkxhquke37ng7csvndhy4s2i",["openai-gpt-3.5-turbo-instruct","openai-gpt-3.5-turbo","openai-gpt-4"]],["bafybeiegbsq2ajxyipajac4mmxyvbt22ctwyuypuid6ziavqpndns6fsjy",["stabilityai-stable-diffusion-v1-5","stabilityai-stable-diffusion-xl-beta-v2-2-2","stabilityai-stable-diffusion-512-v2-1","stabilityai-stable-diffusion-768-v2-1"]],["bafybeihugaylajwh2fgypxatcw5qrw5qxadtrsi2h2s2246442wlvjirtm",["transfer-native"]],["bafybeiayity7o6c2yynrpe6libyak37hgf4fp7a4kjfcnqkkxwy3zkp3ie",["prediction-offline","prediction-online"]]]'
API_KEYS='[["openai","dummy_api_key"],["stabilityai","dummy_api_key"]]'
FILE_HASH_TO_TOOLS='[["bafybeibdcttrlgp5udygntka5fofi566pitkxhquke37ng7csvndhy4s2i",["openai-gpt-3.5-turbo-instruct","openai-gpt-3.5-turbo","openai-gpt-4"]],["bafybeiegbsq2ajxyipajac4mmxyvbt22ctwyuypuid6ziavqpndns6fsjy",["stabilityai-stable-diffusion-v1-5","stabilityai-stable-diffusion-xl-beta-v2-2-2","stabilityai-stable-diffusion-512-v2-1","stabilityai-stable-diffusion-768-v2-1"]],["bafybeihugaylajwh2fgypxatcw5qrw5qxadtrsi2h2s2246442wlvjirtm",["transfer-native"]],["bafybeiayity7o6c2yynrpe6libyak37hgf4fp7a4kjfcnqkkxwy3zkp3ie",["prediction-offline","prediction-online"]],["bafybeifpalgiya4dyu42hehsqxlwr36fjtxdo75xf3gcpfrauvoxgargy4",["gemini-pro", "gemini-1.0-pro-001", "gemini-1.0-pro-latest", "gemini-1.5-pro-latest"]]]'
API_KEYS='[["openai","dummy_api_key"],["stabilityai","dummy_api_key"],["gemini","dummy_api_key"]]'
ETHEREUM_LEDGER_RPC_0=https://rpc.eu-central-2.gateway.fm/v4/gnosis/non-archival/mainnet
GNOSIS_RPC_0=https://rpc.eu-central-2.gateway.fm/v4/gnosis/non-archival/mainnet
ETHEREUM_WEBSOCKET_RPC_0=wss://rpc.eu-central-2.gateway.fm/ws/v4/gnosis/non-archival/mainnet
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/common_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ jobs:
NEWS_API_KEY: ${{ secrets.NEWS_API_KEY }}
OPENROUTER_API_KEY: ${{ secrets.OPEN_ROUTER_API_KEY }}
GNOSIS_RPC_URL: ${{ secrets.GNOSIS_RPC_URL }}
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: |
printenv
tox -e check-tools
9 changes: 5 additions & 4 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
"custom/napthaai/prediction_url_cot_claude/0.1.0": "bafybeicbjywni5hx5ssoiv6tnnjbqzsck6cmtsdpr6m562z6afogz5eh44",
"custom/napthaai/prediction_request_reasoning_claude/0.1.0": "bafybeihtx2cejxoy42jwk2i5m4evfzz537aic5njuawxnzdzwlo63kdduq",
"custom/napthaai/prediction_request_rag_claude/0.1.0": "bafybeickr32t7nmapuoymjyo3cf5rr2v2zapksxcivuqsgjr2gn6zo6y7y",
"custom/napthaai/prediction_request_rag_cohere/0.1.0": "bafybeicrpk5oktsmr4bnk5flpkfqfwbcttq6n2oo742334d2iaixu6w5qa",
"custom/napthaai/prediction_request_rag_cohere/0.1.0": "bafybeihh26kwgqkzojd4zastto5mgod7o7esll4f4icurvwumvwuzmosrm",
"custom/valory/prediction_request_lite/0.1.0": "bafybeidlrn4siraksldhiq3vbhhil4lbzuaqzooppkfhfql5rzii6cnziq",
"custom/nickcom007/prediction_request_sme_lite/0.1.0": "bafybeidhuikn322h7oxgl5n2t5lvcl2dmv7cbmnes5tomabuucg6a42zkm",
"custom/napthaai/prediction_request_reasoning_lite/0.1.0": "bafybeigxs5tq4w7ouamwlvv7vjw3z3jeercynsuka4mcpveshopvej4cyu",
"custom/napthaai/prediction_request_rag_cohere/0.1.0": "bafybeihh26kwgqkzojd4zastto5mgod7o7esll4f4icurvwumvwuzmosrm",
"custom/valory/prediction_langchain/0.1.0": "bafybeihhii7veepp6ovkmqjnkp6euhkwm52obabgdltdj34ikisfd7yvqi",
"custom/victorpolisetty/gemini_request/0.1.0": "bafybeig5x6b5jtanet2q5sk7er7fdzpippbvh4q5p7uxmxpriq66omjnaq",
"custom/gnosis/omen_tools/0.1.0": "bafybeifxrawgu6m3dgsxvj7jrhxzr5gwi3zjk2m4gltkr5w3hxjjbla6nu",
"protocol/valory/acn_data_share/0.1.0": "bafybeih5ydonnvrwvy2ygfqgfabkr47s4yw3uqxztmwyfprulwfsoe7ipq",
"protocol/valory/websocket_client/0.1.0": "bafybeifjk254sy65rna2k32kynzenutujwqndap2r222afvr3zezi27mx4",
"contract/valory/agent_mech/0.1.0": "bafybeiah6b5epo2hlvzg5rr2cydgpp2waausoyrpnoarf7oa7bw33rex34",
Expand All @@ -39,8 +40,8 @@
"skill/valory/task_execution/0.1.0": "bafybeic27brlpaamu3gfmdribywjvjyzxz2evqneh3e2kb3karubllz6xi",
"skill/valory/websocket_client/0.1.0": "bafybeif7rrvsu6z4evqkhblxj3u6wwv2eqou576hgkyoehxuj7cntw7o2m",
"skill/valory/subscription_abci/0.1.0": "bafybeihtortmv4fqua5wrnshpnvqsbpaf52frwynrmpuv2uw5j7wkauhze",
"agent/valory/mech/0.1.0": "bafybeid2hlmwtoze3xhhqqayisdg6xzxzgf42zw7hccdaszur7qfgp5vu4",
"service/valory/mech/0.1.0": "bafybeibr425raoxalifrnspyph4r2u2ilijlvdm3yexxuzsmwzyx7vlica"
"agent/valory/mech/0.1.0": "bafybeih2oex4yt4mmiyarp2ivkqqfscoavyb7metchciiqmqdmv7lhyutq",
"service/valory/mech/0.1.0": "bafybeic4lql2xbqfgjyyiacsthfkkx5zea2khackffhoh36hhajhjyhgdi"
},
"third_party": {
"protocol/valory/default/1.0.0": "bafybeifqcqy5hfbnd7fjv4mqdjrtujh2vx3p2xhe33y67zoxa6ph7wdpaq",
Expand Down
2 changes: 2 additions & 0 deletions packages/valory/agents/mech/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ dependencies:
prediction-market-agent-tooling:
git: https://github.com/gnosis/prediction-market-agent-tooling
ref: gabriel/olas-deps
google-generativeai:
version: ==0.6.0
default_connection: null
---
public_id: valory/websocket_client:0.1.0:bafybeiexove4oqyhoae5xmk2hilskthosov5imdp65olpgj3cfrepbouyy
Expand Down
19 changes: 19 additions & 0 deletions packages/victorpolisetty/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2024 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------------
19 changes: 19 additions & 0 deletions packages/victorpolisetty/customs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2024 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------------
18 changes: 18 additions & 0 deletions packages/victorpolisetty/customs/gemini_request/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2024 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------------
17 changes: 17 additions & 0 deletions packages/victorpolisetty/customs/gemini_request/component.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: gemini_request
author: victorpolisetty
version: 0.1.0
type: custom
description: A tool that runs a prompt against Google Gemini.
license: Apache-2.0
aea_version: '>=1.0.0, <2.0.0'
fingerprint:
__init__.py: bafybeidlhllgpf65xwk357wukpguuaz6hxhkyh7dwplv2xkxlrlk4b7zty
gemini_request.py: bafybeigae5an6ewsboran33o2x7d6itcoxwgrnoucoluhsyrzp462afida
fingerprint_ignore_patterns: []
entry_point: gemini_request.py
callable: run
dependencies:
google-generativeai:
version: ==0.5.3
requests: {}
78 changes: 78 additions & 0 deletions packages/victorpolisetty/customs/gemini_request/gemini_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2023-2024 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------------
"""Contains the job definitions"""

from typing import Any, Dict, Optional, Tuple

import google.generativeai as genai

DEFAULT_GEMINI_SETTINGS = {
"candidate_count": 1,
"stop_sequences": None,
"max_output_tokens": 500,
"temperature": 0.7,
}
PREFIX = "gemini-"
ENGINES = {
"chat": ["pro", "1.0-pro-001", "1.0-pro-latest", "1.5-pro-latest"],
}

ALLOWED_TOOLS = [PREFIX + value for value in ENGINES["chat"]]

def count_tokens(text: str) -> int:
"""Count the number of tokens in a text using the Gemini model's tokenizer."""
return genai.count_message_tokens(prompt=text)

def run(**kwargs) -> Tuple[Optional[str], Optional[Dict[str, Any]], Any, Any]:
"""Run the task"""

api_key = kwargs["api_keys"]["gemini"]
tool = kwargs["tool"]
prompt = kwargs["prompt"]

if tool not in ALLOWED_TOOLS:
return f"Model {tool} is not in the list of supported models.", None, None, None,

candidate_count = kwargs.get("candidate_count", DEFAULT_GEMINI_SETTINGS["candidate_count"])
stop_sequences = kwargs.get("stop_sequences", DEFAULT_GEMINI_SETTINGS["stop_sequences"])
max_output_tokens = kwargs.get("max_output_tokens", DEFAULT_GEMINI_SETTINGS["max_output_tokens"])
temperature = kwargs.get("temperature", DEFAULT_GEMINI_SETTINGS["temperature"])

counter_callback = kwargs.get("counter_callback", None)

genai.configure(api_key=api_key)
engine = genai.GenerativeModel(tool)

try:
response = engine.generate_content(
prompt,
generation_config=genai.types.GenerationConfig(
candidate_count=candidate_count,
stop_sequences=stop_sequences,
max_output_tokens=max_output_tokens,
temperature=temperature)
)

# Ensure response has a .text attribute
response_text = getattr(response, 'text', None)

except Exception as e:
return f"An error occurred: {str(e)}", None, None, None

return response.text, prompt, None, counter_callback
victorpolisetty marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading