-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-openai): add OpenAI integration for text generation (#2463)
* feat: add plugin-openai for text generation using OpenAI API (#1234) * fix: apply code review suggestions from coderabbitai * add remaining updates for plugin * Refactor: Centralize OpenAI action utilities in action.ts - Introduced shared constants (DEFAULT_MODEL, DEFAULT_MAX_TOKENS, etc.). - Added reusable functions: - validatePrompt: Validates text input for OpenAI actions. - validateApiKey: Ensures API key is present. - callOpenAiApi: Handles HTTP requests with timeout and error handling. - buildRequestData: Creates structured request payloads. - Updated all action files to leverage shared logic. - Improved maintainability and consistency across all OpenAI-related actions. * feat(plugin-openai): finalize plugin setup and configuration - Updated to enhance terminal output with plugin details and accounts (Twitter, GitHub). - Adjusted scripts and dependencies for compatibility and functionality. - Added a localized for specific TypeScript configurations within the plugin. - Improved initialization and logging to streamline the startup process. This commit completes the setup for the OpenAI plugin and ensures integration with the framework. --------- Co-authored-by: 0xrubusdata <[email protected]> Co-authored-by: Sayo <[email protected]> Co-authored-by: Sayo <[email protected]>
- Loading branch information
1 parent
a5dccdb
commit 9319fd3
Showing
17 changed files
with
1,565 additions
and
735 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,119 +1,120 @@ | ||
{ | ||
"name": "@elizaos/agent", | ||
"version": "0.1.9-alpha.1", | ||
"main": "src/index.ts", | ||
"type": "module", | ||
"scripts": { | ||
"start": "node --loader ts-node/esm src/index.ts", | ||
"dev": "node --loader ts-node/esm src/index.ts", | ||
"check-types": "tsc --noEmit", | ||
"test": "jest" | ||
}, | ||
"nodemonConfig": { | ||
"watch": [ | ||
"src", | ||
"../core/dist" | ||
], | ||
"ext": "ts,json", | ||
"exec": "node --enable-source-maps --loader ts-node/esm src/index.ts" | ||
}, | ||
"dependencies": { | ||
"@elizaos/adapter-supabase": "workspace:*", | ||
"@elizaos/adapter-postgres": "workspace:*", | ||
"@elizaos/adapter-redis": "workspace:*", | ||
"@elizaos/adapter-sqlite": "workspace:*", | ||
"@elizaos/adapter-pglite": "workspace:*", | ||
"@elizaos/client-auto": "workspace:*", | ||
"@elizaos/client-direct": "workspace:*", | ||
"@elizaos/client-discord": "workspace:*", | ||
"@elizaos/client-farcaster": "workspace:*", | ||
"@elizaos/client-lens": "workspace:*", | ||
"@elizaos/client-telegram": "workspace:*", | ||
"@elizaos/client-twitter": "workspace:*", | ||
"@elizaos/client-instagram": "workspace:*", | ||
"@elizaos/client-slack": "workspace:*", | ||
"@elizaos/core": "workspace:*", | ||
"@elizaos/plugin-0g": "workspace:*", | ||
"@elizaos/plugin-abstract": "workspace:*", | ||
"@elizaos/plugin-agentkit": "workspace:*", | ||
"@elizaos/plugin-aptos": "workspace:*", | ||
"@elizaos/plugin-birdeye": "workspace:*", | ||
"@elizaos/plugin-coingecko": "workspace:*", | ||
"@elizaos/plugin-coinmarketcap": "workspace:*", | ||
"@elizaos/plugin-binance": "workspace:*", | ||
"@elizaos/plugin-avail": "workspace:*", | ||
"@elizaos/plugin-bootstrap": "workspace:*", | ||
"@elizaos/plugin-di": "workspace:*", | ||
"@elizaos/plugin-cosmos": "workspace:*", | ||
"@elizaos/plugin-intiface": "workspace:*", | ||
"@elizaos/plugin-coinbase": "workspace:*", | ||
"@elizaos/plugin-conflux": "workspace:*", | ||
"@elizaos/plugin-evm": "workspace:*", | ||
"@elizaos/plugin-echochambers": "workspace:*", | ||
"@elizaos/plugin-flow": "workspace:*", | ||
"@elizaos/plugin-gitbook": "workspace:*", | ||
"@elizaos/plugin-story": "workspace:*", | ||
"@elizaos/plugin-gitcoin-passport": "workspace:*", | ||
"@elizaos/plugin-goat": "workspace:*", | ||
"@elizaos/plugin-lensNetwork": "workspace:*", | ||
"@elizaos/plugin-icp": "workspace:*", | ||
"@elizaos/plugin-image-generation": "workspace:*", | ||
"@elizaos/plugin-movement": "workspace:*", | ||
"@elizaos/plugin-massa": "workspace:*", | ||
"@elizaos/plugin-nft-generation": "workspace:*", | ||
"@elizaos/plugin-node": "workspace:*", | ||
"@elizaos/plugin-solana": "workspace:*", | ||
"@elizaos/plugin-injective": "workspace:*", | ||
"@elizaos/plugin-solana-agent-kit": "workspace:*", | ||
"@elizaos/plugin-squid-router": "workspace:*", | ||
"@elizaos/plugin-autonome": "workspace:*", | ||
"@elizaos/plugin-starknet": "workspace:*", | ||
"@elizaos/plugin-stargaze": "workspace:*", | ||
"@elizaos/plugin-giphy": "workspace:*", | ||
"@elizaos/plugin-ton": "workspace:*", | ||
"@elizaos/plugin-sui": "workspace:*", | ||
"@elizaos/plugin-sgx": "workspace:*", | ||
"@elizaos/plugin-iq6900": "workspace:*", | ||
"@elizaos/plugin-tee": "workspace:*", | ||
"@elizaos/plugin-tee-log": "workspace:*", | ||
"@elizaos/plugin-tee-marlin": "workspace:*", | ||
"@elizaos/plugin-multiversx": "workspace:*", | ||
"@elizaos/plugin-near": "workspace:*", | ||
"@elizaos/plugin-zksync-era": "workspace:*", | ||
"@elizaos/plugin-twitter": "workspace:*", | ||
"@elizaos/plugin-primus": "workspace:*", | ||
"@elizaos/plugin-cronoszkevm": "workspace:*", | ||
"@elizaos/plugin-3d-generation": "workspace:*", | ||
"@elizaos/plugin-fuel": "workspace:*", | ||
"@elizaos/plugin-avalanche": "workspace:*", | ||
"@elizaos/plugin-video-generation": "workspace:*", | ||
"@elizaos/plugin-web-search": "workspace:*", | ||
"@elizaos/plugin-dexscreener": "workspace:*", | ||
"@elizaos/plugin-letzai": "workspace:*", | ||
"@elizaos/plugin-thirdweb": "workspace:*", | ||
"@elizaos/plugin-genlayer": "workspace:*", | ||
"@elizaos/plugin-tee-verifiable-log": "workspace:*", | ||
"@elizaos/plugin-depin": "workspace:*", | ||
"@elizaos/plugin-open-weather": "workspace:*", | ||
"@elizaos/plugin-obsidian": "workspace:*", | ||
"@elizaos/plugin-arthera": "workspace:*", | ||
"@elizaos/plugin-allora": "workspace:*", | ||
"@elizaos/plugin-opacity": "workspace:*", | ||
"@elizaos/plugin-hyperliquid": "workspace:*", | ||
"@elizaos/plugin-akash": "workspace:*", | ||
"@elizaos/plugin-quai": "workspace:*", | ||
"@elizaos/plugin-b2": "workspace:*", | ||
"@elizaos/plugin-nft-collections": "workspace:*", | ||
"@elizaos/plugin-pyth-data": "workspace:*", | ||
"readline": "1.3.0", | ||
"ws": "8.18.0", | ||
"yargs": "17.7.2" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^29.5.14", | ||
"jest": "^29.7.0", | ||
"ts-jest": "^29.2.5", | ||
"ts-node": "10.9.2", | ||
"tsup": "8.3.5" | ||
} | ||
"name": "@elizaos/agent", | ||
"version": "0.1.9-alpha.1", | ||
"main": "src/index.ts", | ||
"type": "module", | ||
"scripts": { | ||
"start": "node --loader ts-node/esm src/index.ts", | ||
"dev": "node --loader ts-node/esm src/index.ts", | ||
"check-types": "tsc --noEmit", | ||
"test": "jest" | ||
}, | ||
"nodemonConfig": { | ||
"watch": [ | ||
"src", | ||
"../core/dist" | ||
], | ||
"ext": "ts,json", | ||
"exec": "node --enable-source-maps --loader ts-node/esm src/index.ts" | ||
}, | ||
"dependencies": { | ||
"@elizaos/adapter-supabase": "workspace:*", | ||
"@elizaos/adapter-postgres": "workspace:*", | ||
"@elizaos/adapter-redis": "workspace:*", | ||
"@elizaos/adapter-sqlite": "workspace:*", | ||
"@elizaos/adapter-pglite": "workspace:*", | ||
"@elizaos/client-auto": "workspace:*", | ||
"@elizaos/client-direct": "workspace:*", | ||
"@elizaos/client-discord": "workspace:*", | ||
"@elizaos/client-farcaster": "workspace:*", | ||
"@elizaos/client-lens": "workspace:*", | ||
"@elizaos/client-telegram": "workspace:*", | ||
"@elizaos/client-twitter": "workspace:*", | ||
"@elizaos/client-instagram": "workspace:*", | ||
"@elizaos/client-slack": "workspace:*", | ||
"@elizaos/core": "workspace:*", | ||
"@elizaos/plugin-0g": "workspace:*", | ||
"@elizaos/plugin-abstract": "workspace:*", | ||
"@elizaos/plugin-agentkit": "workspace:*", | ||
"@elizaos/plugin-aptos": "workspace:*", | ||
"@elizaos/plugin-birdeye": "workspace:*", | ||
"@elizaos/plugin-coingecko": "workspace:*", | ||
"@elizaos/plugin-coinmarketcap": "workspace:*", | ||
"@elizaos/plugin-binance": "workspace:*", | ||
"@elizaos/plugin-avail": "workspace:*", | ||
"@elizaos/plugin-bootstrap": "workspace:*", | ||
"@elizaos/plugin-di": "workspace:*", | ||
"@elizaos/plugin-cosmos": "workspace:*", | ||
"@elizaos/plugin-intiface": "workspace:*", | ||
"@elizaos/plugin-coinbase": "workspace:*", | ||
"@elizaos/plugin-conflux": "workspace:*", | ||
"@elizaos/plugin-evm": "workspace:*", | ||
"@elizaos/plugin-echochambers": "workspace:*", | ||
"@elizaos/plugin-flow": "workspace:*", | ||
"@elizaos/plugin-gitbook": "workspace:*", | ||
"@elizaos/plugin-story": "workspace:*", | ||
"@elizaos/plugin-gitcoin-passport": "workspace:*", | ||
"@elizaos/plugin-goat": "workspace:*", | ||
"@elizaos/plugin-lensNetwork": "workspace:*", | ||
"@elizaos/plugin-icp": "workspace:*", | ||
"@elizaos/plugin-image-generation": "workspace:*", | ||
"@elizaos/plugin-movement": "workspace:*", | ||
"@elizaos/plugin-massa": "workspace:*", | ||
"@elizaos/plugin-nft-generation": "workspace:*", | ||
"@elizaos/plugin-node": "workspace:*", | ||
"@elizaos/plugin-solana": "workspace:*", | ||
"@elizaos/plugin-injective": "workspace:*", | ||
"@elizaos/plugin-solana-agent-kit": "workspace:*", | ||
"@elizaos/plugin-squid-router": "workspace:*", | ||
"@elizaos/plugin-autonome": "workspace:*", | ||
"@elizaos/plugin-starknet": "workspace:*", | ||
"@elizaos/plugin-stargaze": "workspace:*", | ||
"@elizaos/plugin-giphy": "workspace:*", | ||
"@elizaos/plugin-ton": "workspace:*", | ||
"@elizaos/plugin-sui": "workspace:*", | ||
"@elizaos/plugin-sgx": "workspace:*", | ||
"@elizaos/plugin-iq6900": "workspace:*", | ||
"@elizaos/plugin-tee": "workspace:*", | ||
"@elizaos/plugin-tee-log": "workspace:*", | ||
"@elizaos/plugin-tee-marlin": "workspace:*", | ||
"@elizaos/plugin-multiversx": "workspace:*", | ||
"@elizaos/plugin-near": "workspace:*", | ||
"@elizaos/plugin-zksync-era": "workspace:*", | ||
"@elizaos/plugin-twitter": "workspace:*", | ||
"@elizaos/plugin-primus": "workspace:*", | ||
"@elizaos/plugin-cronoszkevm": "workspace:*", | ||
"@elizaos/plugin-3d-generation": "workspace:*", | ||
"@elizaos/plugin-fuel": "workspace:*", | ||
"@elizaos/plugin-avalanche": "workspace:*", | ||
"@elizaos/plugin-video-generation": "workspace:*", | ||
"@elizaos/plugin-web-search": "workspace:*", | ||
"@elizaos/plugin-dexscreener": "workspace:*", | ||
"@elizaos/plugin-letzai": "workspace:*", | ||
"@elizaos/plugin-thirdweb": "workspace:*", | ||
"@elizaos/plugin-genlayer": "workspace:*", | ||
"@elizaos/plugin-tee-verifiable-log": "workspace:*", | ||
"@elizaos/plugin-depin": "workspace:*", | ||
"@elizaos/plugin-open-weather": "workspace:*", | ||
"@elizaos/plugin-obsidian": "workspace:*", | ||
"@elizaos/plugin-arthera": "workspace:*", | ||
"@elizaos/plugin-allora": "workspace:*", | ||
"@elizaos/plugin-opacity": "workspace:*", | ||
"@elizaos/plugin-hyperliquid": "workspace:*", | ||
"@elizaos/plugin-akash": "workspace:*", | ||
"@elizaos/plugin-quai": "workspace:*", | ||
"@elizaos/plugin-b2": "workspace:*", | ||
"@elizaos/plugin-nft-collections": "workspace:*", | ||
"@elizaos/plugin-pyth-data": "workspace:*", | ||
"@elizaos/plugin-openai": "workspace:*", | ||
"readline": "1.3.0", | ||
"ws": "8.18.0", | ||
"yargs": "17.7.2" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^29.5.14", | ||
"jest": "^29.7.0", | ||
"ts-jest": "^29.2.5", | ||
"ts-node": "10.9.2", | ||
"tsup": "8.3.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
# @elizaos/plugin-openai | ||
|
||
A plugin for OpenAI integration, providing automated text generation capabilities. | ||
|
||
## Overview | ||
|
||
This plugin provides functionality to: | ||
|
||
- Generate text using OpenAI's GPT models. | ||
- Customize prompts for context-aware content generation. | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install @elizaos/plugin-openai | ||
``` | ||
|
||
## Configuration | ||
|
||
The plugin requires the following environment variable: | ||
|
||
```env | ||
OPENAI_API_KEY=your_openai_api_key | ||
``` | ||
|
||
## Usage | ||
|
||
Import and register the plugin in your Eliza configuration: | ||
|
||
```typescript | ||
import { openaiPlugin } from "@elizaos/plugin-openai"; | ||
|
||
export default { | ||
plugins: [openaiPlugin], | ||
// ... other configuration | ||
}; | ||
``` | ||
|
||
### Generating Text | ||
|
||
```typescript | ||
const result = await generateTextAction.handler(runtime, message, state); | ||
console.log(result.text); // Output generated by OpenAI | ||
``` | ||
|
||
## Development | ||
|
||
### Building | ||
|
||
```bash | ||
npm run build | ||
``` | ||
|
||
### Testing | ||
|
||
```bash | ||
npm run test | ||
``` | ||
|
||
## License | ||
|
||
This plugin is part of the Eliza project. See the main project repository for license information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
{ | ||
"name": "@elizaos/plugin-openai", | ||
"version": "0.1.0", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"module": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"import": { | ||
"@elizaos/source": "./src/index.ts", | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
} | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"dependencies": { | ||
"@elizaos/core": "workspace:*", | ||
"axios": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"tsup": "8.3.5", | ||
"vitest": "^1.0.0" | ||
}, | ||
"scripts": { | ||
"build": "tsup src/index.ts --format esm --dts --tsconfig ./tsconfig.json", | ||
"dev": "tsup src/index.ts --format esm --dts --watch --tsconfig ./tsconfig.json" | ||
} | ||
} |
Oops, something went wrong.