
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
@chaingpt/generalchat
Advanced tools
This library provides convenient access to the ChainGPT General Chat REST API from TypeScript or JavaScript.
npm install --save @chaingpt/generalchat
# or
yarn add generalchat
Retrieve a chat response as a stream without custom context injection:
import { GeneralChat } from '@chaingpt/generalchat';
const generalchat = new GeneralChat({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const stream = await generalchat.createChatStream({
question: 'Explain quantum computing in simple terms',
chatHistory: "off", // Set to "on" to save chat history; otherwise, keep it "off"
});
stream.on('data', (chunk: any)=>console.log(chunk.toString()));
stream.on('end', () => console.log("Stream ended"));
}
main();
import { GeneralChat } from '@chaingpt/generalchat';
import { AI_TONE, BLOCKCHAIN_NETWORK, PRE_SET_TONES } from "@chaingpt/generalchat/dist/enum/context.enum.js";
const generalchat = new GeneralChat({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const stream = await generalchat.createChatStream({
question: 'Explain quantum computing in simple terms',
chatHistory: "off", // Set to "on" to save chat history; otherwise, keep it "off"
useCustomContext: true // When useCustomContext is true and no contextInjection object is provided, the default custom context is fetched based on the API key (additional information).
});
stream.on('data', (chunk: any)=>console.log(chunk.toString()));
stream.on('end', () => console.log("Stream ended"));
}
main()
contextInjection
object is optional, and all its fields are optional. You can provide additional company details for a more tailored chatbot experience . Any chunk of information added here will override the company default details that are added from AI Hubconst contextInjection = {
companyName: "Company name for AI chatbot",
companyDescription: "Company description for AI chatbot",
companyWebsiteUrl: "https://www.example.com",
whitePaperUrl: "https://www.example.com",
purpose: "Purpose of AI Chatbot for this company.",
cryptoToken: true,
tokenInformation: {
tokenName: "Token name for AI chatbot",
tokenSymbol: "$TOKEN",
tokenAddress: "Token address for AI chatbot",
tokenSourceCode: "Token source code for AI chatbot",
tokenAuditUrl: "https://www.example.com",
exploreUrl: "https://www.example.com",
cmcUrl: "https://www.example.com",
coingeckoUrl: "https://www.example.com",
blockchain: [BLOCKCHAIN_NETWORK.ETHEREUM, BLOCKCHAIN_NETWORK.POLYGON_ZKEVM]
},
socialMediaUrls: [{ name: "LinkedIn", url: "https://abc.com" }],
limitation: false,
aiTone: AI_TONE.PRE_SET_TONE,
selectedTone: PRE_SET_TONES.FRIENDLY,
customTone: "Only for custom AI Tone"
};
import { GeneralChat } from '@chaingpt/generalchat';
import { AI_TONE, BLOCKCHAIN_NETWORK, PRE_SET_TONES } from "@chaingpt/generalchat/dist/enum/context.enum.js";
const generalchat = new GeneralChat({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const stream = await generalchat.createChatStream({
question: 'Explain quantum computing in simple terms',
chatHistory: "off",
useCustomContext: true,
contextInjection: {
aiTone: AI_TONE.PRE_SET_TONE,
selectedTone: PRE_SET_TONES.FORMAL,
}
});
stream.on('data', (chunk: any) => console.log(chunk.toString()));
stream.on('end', () => console.log("Stream ended"));
}
main();
import { GeneralChat } from '@chaingpt/generalchat';
import { AI_TONE, BLOCKCHAIN_NETWORK, PRE_SET_TONES } from "@chaingpt/generalchat/dist/enum/context.enum.js";
const generalchat = new GeneralChat({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const stream = await generalchat.createChatStream({
question: 'Explain blockchain security best practices',
chatHistory: "on",
useCustomContext: true,
contextInjection: {
companyName: "Crypto Solutions",
companyDescription: "A blockchain security firm",
cryptoToken: true,
tokenInformation: {
tokenName: "SecureToken",
tokenSymbol: "$SEC",
blockchain: [BLOCKCHAIN_NETWORK.ETHEREUM]
},
socialMediaUrls: [{ name: "Twitter", url: "https://twitter.com/cryptosolutions" }],
aiTone: AI_TONE.CUSTOM_TONE,
customTone: "Provide detailed security explanations."
}
});
stream.on('data', (chunk: any) => console.log(chunk.toString()));
stream.on('end', () => console.log("Stream ended"));
}
main();
Retrieve a chat response as a blob without custom context injection:
import { GeneralChat } from '@chaingpt/generalchat';
const generalchat = new GeneralChat({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const response = await generalchat.createChatBlob({
question: 'Explain quantum computing in simple terms',
chatHistory: "on",
})
console.log(response.data.bot);
}
main();
import { GeneralChat } from '@chaingpt/generalchat';
import { AI_TONE, BLOCKCHAIN_NETWORK, PRE_SET_TONES } from "@chaingpt/generalchat/dist/enum/context.enum.js";
const generalchat = new GeneralChat({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const response = await generalchat.createChatBlob({
question: 'Explain quantum computing in simple terms',
chatHistory: "off",
useCustomContext: true // When useCustomContext is true and no contextInjection object is provided, the default custom context is fetched based on the API key (additional information).
});
console.log(response.data.bot);
}
main()
contextInjection
object is optional, and all its fields are optional. You can provide additional company details for a more tailored chatbot experience . Any chunck of information Added here will override the your company default details that are added from AI Hubconst contextInjection = {
companyName: "Company name for AI chatbot",
companyDescription: "Company description for AI chatbot",
companyWebsiteUrl: "https://www.example.com",
whitePaperUrl: "https://www.example.com",
purpose: "Purpose of AI Chatbot for this company.",
cryptoToken: true,
tokenInformation: {
tokenName: "Token name for AI chatbot",
tokenSymbol: "$TOKEN",
tokenAddress: "Token address for AI chatbot",
tokenSourceCode: "Token source code for AI chatbot",
tokenAuditUrl: "https://www.example.com",
exploreUrl: "https://www.example.com",
cmcUrl: "https://www.example.com",
coingeckoUrl: "https://www.example.com",
blockchain: [BLOCKCHAIN_NETWORK.ETHEREUM, BLOCKCHAIN_NETWORK.POLYGON_ZKEVM]
},
socialMediaUrls: [{ name: "LinkedIn", url: "https://abc.com" }],
limitation: false,
aiTone: AI_TONE.PRE_SET_TONE,
selectedTone: PRE_SET_TONES.FRIENDLY,
customTone: "Only for custom AI Tone"
};
import { GeneralChat } from '@chaingpt/generalchat';
import { AI_TONE, BLOCKCHAIN_NETWORK, PRE_SET_TONES } from "@chaingpt/generalchat/dist/enum/context.enum.js";
const generalchat = new GeneralChat({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const response = await generalchat.createChatBlob({
question: 'Explain quantum computing in simple terms',
chatHistory: "off",
useCustomContext: true,
contextInjection: {
aiTone: AI_TONE.PRE_SET_TONE,
selectedTone: PRE_SET_TONES.FORMAL,
}
});
console.log(response.data.bot);
}
main();
import { GeneralChat } from '@chaingpt/generalchat';
import { AI_TONE, BLOCKCHAIN_NETWORK, PRE_SET_TONES } from "@chaingpt/generalchat/dist/enum/context.enum.js";
const generalchat = new GeneralChat({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const response = await generalchat.createChatBlob({
question: 'Explain blockchain security best practices',
chatHistory: "on",
useCustomContext: true,
contextInjection: {
companyName: "Crypto Solutions",
companyDescription: "A blockchain security firm",
cryptoToken: true,
tokenInformation: {
tokenName: "SecureToken",
tokenSymbol: "$SEC",
blockchain: [BLOCKCHAIN_NETWORK.ETHEREUM]
},
socialMediaUrls: [{ name: "Twitter", url: "https://twitter.com/cryptosolutions" }],
aiTone: AI_TONE.CUSTOM_TONE,
customTone: "Provide detailed security explanations."
}
});
console.log(response.data.bot);
}
main();
We support multiple blockchains to fetch and display crypto token information for chat interactions. Below is the list of supported blockchains:
blockchain = [ ETHEREUM, BSC, ARBITRUM, BASE, BLAST, AVALANCHE, POLYGON, SCROLL, OPTIMISM, LINEA, ZKSYNC, POLYGON_ZKEV, GNOSIS, FANTOM, MOONRIVER, MOONBEAM, BOBA, MODE, METIS, LISK, AURORA, SEI, IMMUTABLE_ZK, GRAVITY, TAIKO, CRONOS, FRAXTAL, ABSTRACT, CELO, WORLD_CHAIN, MANTLE, BERACHAIN
]
Our AI supports multiple tone options to customize responses based on user preferences. The following tone selection options are available:
1) DEFAULT_TONE // if we select DEFAULT_TONE then no need for customTone and selectedTone
2) CUSTOM_TONE // if we select CUSTOM_TONE then customTone text is required
3) PRE_SET_TONE // if we select PRE_SET_TONE then selectedTone is required
If PRE_SET_TONE is selected, users can choose from the following tones: If we select PRE_SET_TONE then we select given option
1) PROFESSIONAL
2) FRIENDLY
3) INFORMATIVE
4) FORMAL
5) CONVERSATIONAL
6) AUTHORITATIVE
7) PLAYFUL
8) INSPIRATIONAL
9) CONCISE
10) EMPATHETIC
11) ACADEMIC
12) NEUTRAL
13) SARCASTIC_MEME_STYLE
We support multiple social media platforms for interaction and sharing
socialMediaUrls = [
{name:"linkedIn",url:"https://www.example.com"},
{name:"telegram",url:"https://www.example.com"},
{name:"instagram",url:"https://www.example.com"},
{name:"twitter",url:"https://www.example.com"},
{name:"youtube",url:"https://www.example.com"},
{name:"medium",url:"https://www.example.com"}
]
sdkUniqueId
parameter along with the chat history. This applies to both streaming and blob cases.import { GeneralChat } from '@chaingpt/generalchat';
const generalchat = new GeneralChat({
apiKey: 'Your ChainGPT API Key',
});
const uniqueUUid="907208eb-0929-42c3-a372-c21934fbf44f" // any unique uuid
async function main() {
const stream = await generalchat.createChatStream({
question: 'Explain quantum computing in simple terms',
chatHistory: "on", // Set to "on" to save chat history; otherwise, keep it "off"
sdkUniqueId:uniqueUUid
});
stream.on('data', (chunk: any)=>console.log(chunk.toString()));
stream.on('end', () => console.log("Stream ended"));
}
main();
import { GeneralChat } from '@chaingpt/generalchat';
const generalchat = new GeneralChat({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const response = await generalchat.getChatHistory({
limit: 10,
offset: 0,
sortBy: "createdAt",
sortOrder: "ASC"
})
console.log(response.data.rows);
}
main();
import { GeneralChat } from '@chaingpt/generalchat';
const generalchat = new GeneralChat({
apiKey: 'Your ChainGPT API Key',
});
const uniqueUUid="907208eb-0929-42c3-a372-c21934fbf44f" // your unique uuid of your specific user
async function main() {
const response = await generalchat.getChatHistory({
limit: 10,
offset: 0,
sortBy: "createdAt",
sortOrder: "ASC",
sdkUniqueId:uniqueUUid // your unique uuid of your specific user
})
console.log(response.data.rows);
}
main();
When the library is unable to connect to the API,
or if the API returns a non-success status code (i.e., 4xx or 5xx response),
and error of the class GeneralChatError
will be thrown:
import { Errors } from '@chaingpt/generalchat';
async function main() {
try {
const stream = await generalchat.createChatStream({
question: 'Explain quantum computing in simple terms',
chatHistory: "off"
});
stream.on('data', (chunk: any)=>console.log(chunk.toString()));
stream.on('end', () => console.log("Stream ended"));
} catch(error) {
if(error instanceof Errors.GeneralChatError) {
console.log(error.message)
}
}
}
main();
FAQs
SDK for GeneralChat
The npm package @chaingpt/generalchat receives a total of 27 weekly downloads. As such, @chaingpt/generalchat popularity was classified as not popular.
We found that @chaingpt/generalchat demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.