mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-28 15:11:17 +00:00
fixes and renames
This commit is contained in:
@@ -21,19 +21,19 @@ Create a new TypeScript file in the `src/tools/` directory for your tool (e.g.,
|
||||
|
||||
```typescript:src/tools/custom_tool.ts
|
||||
import { Tool } from "langchain/tools";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { SolanaAgent } from "../agent";
|
||||
|
||||
export class CustomTool extends Tool {
|
||||
name = "custom_tool";
|
||||
description = "Description of what the custom tool does.";
|
||||
|
||||
constructor(private solanaKit: SolanaAgentKit) {
|
||||
constructor(private solanaAgent: SolanaAgent) {
|
||||
super();
|
||||
}
|
||||
|
||||
protected async _call(input: string): Promise<string> {
|
||||
try {
|
||||
const result = await this.solanaKit.customFunction(input);
|
||||
const result = await this.solanaAgent.customFunction(input);
|
||||
return JSON.stringify({
|
||||
status: "success",
|
||||
message: "Custom tool executed successfully",
|
||||
@@ -53,7 +53,7 @@ export class CustomTool extends Tool {
|
||||
### 3. Add Supporting Functions to SolanaAgentKit
|
||||
|
||||
```typescript:src/agent/index.ts
|
||||
export class SolanaAgentKit {
|
||||
export class SolanaAgent {
|
||||
// ... existing code ...
|
||||
|
||||
async customFunction(input: string): Promise<string> {
|
||||
@@ -87,9 +87,9 @@ export function createSolanaTools(agent: SolanaAgentKit) {
|
||||
### 6. Usage Example
|
||||
|
||||
```typescript
|
||||
import { SolanaAgentKit, createSolanaTools } from "solana-agent-kit";
|
||||
import { SolanaAgent, createSolanaTools } from "solana-agent-kit";
|
||||
|
||||
const agent = new SolanaAgentKit(
|
||||
const agent = new SolanaAgent(
|
||||
"your-wallet-private-key-as-base58",
|
||||
"https://api.mainnet-beta.solana.com",
|
||||
"your-openai-api-key"
|
||||
@@ -118,19 +118,19 @@ Here's a complete example of implementing a tool to fetch token prices:
|
||||
|
||||
```typescript:src/tools/fetch_token_price.ts
|
||||
import { Tool } from "langchain/tools";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { SolanaAgent } from "../agent";
|
||||
|
||||
export class FetchTokenPriceTool extends Tool {
|
||||
name = "fetch_token_price";
|
||||
description = "Fetches the current price of a specified token.";
|
||||
|
||||
constructor(private solanaKit: SolanaAgentKit) {
|
||||
constructor(private solanaAgent: SolanaAgent) {
|
||||
super();
|
||||
}
|
||||
|
||||
protected async _call(tokenSymbol: string): Promise<string> {
|
||||
try {
|
||||
const price = await this.solanaKit.getTokenPrice(tokenSymbol);
|
||||
const price = await this.solanaAgent.getTokenPrice(tokenSymbol);
|
||||
return JSON.stringify({
|
||||
status: "success",
|
||||
message: `Price fetched successfully for ${tokenSymbol}.`,
|
||||
@@ -176,4 +176,4 @@ If you encounter any issues while implementing your custom tool:
|
||||
- Contact the maintainer
|
||||
- Check existing tools for implementation examples
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user