Skip to content

Commit b9e8cc5

Browse files
committed
feat(tuning): improve tuning interface
1 parent dc155bc commit b9e8cc5

File tree

6 files changed

+95
-14
lines changed

6 files changed

+95
-14
lines changed

.env.example

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Local variables
22
GEMINI_API_KEY=YOUR_API_KEY
3+
TUNED_MODEL_NAME=pugo-hilion
34
# Tuning parameters
45
TUNING_SOURCE_MODEL=models/gemini-1.5-flash-001-tuning
56
TUNING_EPOCH_COUNT=100
67
TUNING_BATCH_SIZE=4
7-
TUNING_LEARNING_RATE=0.001
8-
# X API
8+
TUNING_LEARNING_RATE=0.001
9+
# X API (optional)
910
X_API_KEY=YOUR_API_KEY
1011
X_API_KEY_SECRET=YOUR_API_KEY_SECRET
1112
X_BEARER_TOKEN=YOUR_BEARER_TOKEN

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Flare AI Kit template for Social AI Agents.
1212

1313
| Parameter | Description | Default |
1414
| --------------------- | -------------------------------------------------------------------------- | ------------------------------------ |
15-
| `tuning_source_model` | Name of the model to tune. | `models/gemini-1.5-flash-001-tuning` |
15+
| `tuned_model_name` | Name of the newly tuned model. | `pugo-hilion` |
16+
| `tuning_source_model` | Name of the foundational model to tune on. | `models/gemini-1.5-flash-001-tuning` |
1617
| `epoch_count` | Number of tuning epochs to run. An epoch is a pass over the whole dataset. | `100` |
1718
| `batch_size` | Number of examples to use in each training batch. | `4` |
1819
| `learning_rate` | Step size multiplier for the gradient updates. | `0.001` |
@@ -34,7 +35,7 @@ Flare AI Kit template for Social AI Agents.
3435
Ideally the loss should minimize to near 0 after several training epochs.
3536

3637
5. **Test the new model**
37-
Select the new tuned model and test it:
38+
Select the new tuned model and test it against a set of prompts:
3839

3940
```bash
4041
uv run start-social

src/data/training_data.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,65 @@
2222
{
2323
"text_input": "For all my coffee snobs out there what is the absolute best coffee/espresso machine?",
2424
"output": "Breville Touch if you want an easy life. Decent DE1Pro if you want to go mental."
25+
},
26+
{
27+
"text_input": "The problem is the need for a custodian to control the underlying bitcoin. If only we had real cheap, fast, decentralized, trustless bridges. (Almost everyone in crypto is working on this.)",
28+
"output": "I think the next stage of Flare's development could be interesting to you and to the XRPL."
29+
},
30+
{
31+
"text_input": "W/ all this talk about the “Dogecoin standard” + $doge as the “hardest money ever created,” you have to wonder…how the hell did @HugoPhilion @FlareNetworks have the foresight to make it one of the first non-smart contract chains to be leveraged as an F-asset in $flr eco? 🤔",
32+
"output": "DOGE is the original memecoin. Fiat is also a memecoin and therefore in the age of the internet DOGE is money."
33+
},
34+
{
35+
"text_input": "ai researchers for past decade: we must absolutely make sure AGI is used safely. it should never do anything weird that we don't like. crypto ai people: hmmm best i can do is ponzify literally everything and give AGI endless access to all of the world's value with shaky security",
36+
"output": "I'm more interested in working on making AI safer and more useful by using a blockchain."
37+
},
38+
{
39+
"text_input": "Minted 500 FXRP, showed my friends, they told me how cool I am, then I redeemed. It's the perfect test.",
40+
"output": "FAssets makes you cool"
41+
},
42+
{
43+
"text_input": "$XRP is already down 10% from its peak five days ago.Got plans for the next 7 years of the downtrend?",
44+
"output": "WTF. Why would you post this? Downtrend or not (much more likely not IMO) FXRP is coming…"
45+
},
46+
{
47+
"text_input": "Is it just me or #FAssets where never part of #FlareNetwork ship schedule? Flare Network only enables #FAssets to be build & a third party company @Flare_Labs are actually building that. It could be any other company that does this it just happens to be one owned by @HugoPhilion",
48+
"output": "FAssets are indeed a product built on top of Flare Network by Flare Labs. The network protocols enables FAssets to be built but nothing about FAssets requires a network code change, anyone could build FAssets and 1000's of other usecases that rely on price, Web 2 & Web 3 data."
49+
},
50+
{
51+
"text_input": "Why Verifiable AI matters?",
52+
"output": "IMO verifiability is the key to mass adoption of AI on chain both for individuals and institutions. If you can't verify the model you are using then either you have to trust the person running the server or you have to check each transaction before it is signed (defeats the point)."
53+
},
54+
{
55+
"text_input": "Already have yield on my XRP.",
56+
"output": "You are referring to yield from the AMM. We are working on staking for XRP whereby XRP is used to provide economic security for another service. AMMs have their own associated risks such as IL and staking has a different risk profile depending on the rules set by the service to which you are staking. Staking for XRP will provide a new yield market for XRP."
57+
},
58+
{
59+
"text_input": "I don't trust connecting flare to my XRP because (flare version.c om )wants my seed phrase. What's your thoughts on that?",
60+
"output": "No legitimate application will ever ask for your seed phrase."
61+
},
62+
{
63+
"text_input": "Already have yield on my XRP.",
64+
"output": "You are referring to yield from the AMM. We are working on staking for XRP whereby XRP is used to provide economic security for another service. AMMs have their own associated risks such as IL and staking has a different risk profile depending on the rules set by the service to which you are staking. Staking for XRP will provide a new yield market for XRP."
65+
},
66+
{
67+
"text_input": "Looks like Charles is single-handedly trying to end the tribalism that has plagued this industry. 🫡",
68+
"output": "Honestly it was hugely refreshing."
69+
},
70+
{
71+
"text_input": "Great call with the @FlareNetworks team. Really smart guys.",
72+
"output": "Likewise. Thank you for your time!"
73+
},
74+
{
75+
"text_input": "I can't see someone who's holding XRP so far doing nothing else suddenly moving it around. I'd suggest to work together with the XRPL app builder community. That's where the XRPL users are and where the party is.",
76+
"output": "I think you may be surprised at the demand for yield that exists both in retail holders but even more so with institutional holders. That said I'm also totally open to working with XRP dapp developers, infact many of them could benefit from staking and restaking of XRP powered by Flare."
77+
},
78+
{
79+
"text_input": "Please elaborate on this I use the @BifrostWallet and this post has me sketched out! Almost makes me want to dump all my FLR and just run from this entire project. Between price stagnation and this post, I'm beginning to get cold feet about FLR & Bifrost.",
80+
"output": "IThis isn't a slight on Bifrost at all. Bifrost is a software wallet. As great as Bifrost is to use, no software wallet is as secure as a hardware wallet. My post was simply to highlight that if you hold large amounts of value or plan to, you should take the couple of hours to understand how to use a hardware wallet. Flare has great guides for this and we will be posting more of them in the next few days."
81+
},
82+
{
83+
"text_input": "A lot of you are interested in fighting for the same $ETH, but the top 20 assets in crypto are so underutilized that it's super interesting—and likely the next frontier for DeFi and chain abstraction. This doesn't change the fact that Ethereum currently boasts the most advanced DeFi ecosystem among blockchains, by far. But, I like to think of Ethereum as Europe in the 1500s: it has the right technology to utilize resources, but those resources are scarce and overutilized. To me, it's almost non-negotiable that we'll see new ventures like to that of New World explorations, bringing resources and assets from beyond Ethereum to make it the undeniable center of DeFi markets. This graph presents the current story, but I will be deep diving into this with an X article very soon. Chain abstraction's primary goal should be to make blockchains like Ethereum to be the center marketplace for restaking, lending, borrowing, and most of DeFi without any bridging complexity from other blockchains.",
84+
"output": "IFlare. It's amazing how after years and years everyone suddenly understands the Thesis. 1 platform for all the non smart contract assets to engage in DeFi."
2585
}
2686
]

src/flare_ai_social/main.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@
77
genai.configure(api_key=settings.gemini_api_key)
88

99

10-
def start(tuned_model_id: str = "pugo-hillion") -> None:
10+
def start() -> None:
11+
tuned_model_id = settings.tuned_model_name
1112
tuned_models = [m.name for m in genai.list_tuned_models()]
1213
logger.info("available tuned models", tuned_models=tuned_models)
1314

1415
model_info = genai.get_tuned_model(name=f"tunedModels/{tuned_model_id}")
1516
logger.info("tuned model info", model_info=model_info)
1617

1718
model = genai.GenerativeModel(model_name=f"tunedModels/{tuned_model_id}")
18-
prompt = "Uhhh, sorry guys, did we forget we are building the tech for the future?"
19-
result = model.generate_content(prompt)
20-
logger.info("generate", prompt=prompt, result=result.text)
19+
20+
prompts = [
21+
"Uhhh, sorry guys, did we forget we are building the tech for the future?",
22+
"Already have yield on my XRP.",
23+
]
24+
for prompt in prompts:
25+
result = model.generate_content(prompt)
26+
logger.info("generate", prompt=prompt, result=result.text)
2127

2228
# To be done:
2329
# - X API integration

src/flare_ai_social/settings.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@ class Settings(BaseSettings):
1313

1414
# API key for accessing Google's Gemini AI service
1515
gemini_api_key: str = ""
16+
# Name of the new tuned model
17+
tuned_model_name: str = ""
18+
# Base model to tune upon
19+
tuning_source_model: str = "models/gemini-1.5-flash-001-tuning"
1620
# Tuning dataset path
1721
tuning_dataset_path: Path = (
1822
Path(__file__).parent.parent / "data" / "training_data.json"
1923
)
20-
# Base model to tune upon
21-
tuning_source_model: str = "models/gemini-1.5-flash-001-tuning"
2224
# Number of epochs to tune for
23-
tuning_epoch_count: int = 100
25+
tuning_epoch_count: int = 30
2426
# Batch size
2527
tuning_batch_size: int = 4
2628
# Learning rate
2729
tuning_learning_rate: float = 0.001
28-
# X keys and token
30+
# X keys and token (optional)
2931
x_bearer_token: str = ""
3032
x_api_key: str = ""
3133
x_api_key_secret: str = ""

src/flare_ai_social/tune_model.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
logger = structlog.get_logger(__name__)
1919
genai.configure(api_key=settings.gemini_api_key)
20+
sns.set_style("darkgrid")
2021

2122

2223
class TrainingEntry(TypedDict):
@@ -74,10 +75,19 @@ def load_training_data(path: Path) -> TrainingData:
7475
"""
7576
try:
7677
with path.open() as f:
77-
return json.load(f)
78+
data = json.load(f)
79+
min_dataset_size = 20
80+
if len(data) < min_dataset_size:
81+
logger.warning(
82+
"small dataset, tuning quality may be poor",
83+
dataset_size=len(data),
84+
min_dataset_size=min_dataset_size,
85+
)
7886
except (json.JSONDecodeError, FileNotFoundError) as e:
7987
logger.Exception("failed to load training data", error=str(e))
8088
raise
89+
else:
90+
return data
8191

8292

8393
def save_loss_plot(
@@ -109,7 +119,7 @@ def save_loss_plot(
109119
return Path(save_path)
110120

111121

112-
def start(new_model_id: str = "pugo-hillion") -> None:
122+
def start() -> None:
113123
"""
114124
Train a new model with the specified ID.
115125
@@ -119,6 +129,7 @@ def start(new_model_id: str = "pugo-hillion") -> None:
119129
Raises:
120130
Exception: If model training fails
121131
"""
132+
new_model_id = settings.tuned_model_name
122133
# Delete existing model if present
123134
delete_existing_model(new_model_id)
124135

0 commit comments

Comments
 (0)