Python
CGPT SDK Docs
AI Chatbot & LLM SDK Documentation
The ChainGPT AI Chatbot & LLM feature allows you to integrate powerful conversational AI capabilities into your applications. You can send prompts, manage chat history, and customize the AI's responses using context injection.
Table of Contents
Installation
Quick Start
ChainGPTClient Parameters
LLM Service
LLMChatRequestModel Parameters
Basic LLM Usage
Buffered Chat (Complete Response)
Streaming Chat (Real-time Response)
Context Injection
ContextInjectionModel Parameters
TokenInformationModel Parameters
SocialMediaUrlModel Parameters
Context Injection Example
Enums and Constants
ChatHistoryMode
AITone Options
PresetTone Options
Supported Blockchain Networks
Error Handling
Exception Types
Error Handling Example
Complete Example
Best Practices
Installation
Install via pip:
Or add to your requirements.txt:
Quick Start
Basic Client Initialization
ChainGPTClient Parameters
api_key
str
Required
Your ChainGPT API key
base_url
str
"https://api.chaingpt.org"
The base URL for the ChainGPT API
timeout
HTTPTimeout
DEFAULT_TIMEOUT
Default timeout for regular requests (seconds)
stream_timeout
HTTPTimeout
DEFAULT_STREAM_TIMEOUT
Default timeout for streaming requests (seconds)
LLM Service
The LLM service provides both buffered (complete response) and streaming chat capabilities.
LLMChatRequestModel Parameters
model
str
"general_assistant"
Model ID to use (currently only "general_assistant" supported)
question
str
Required
User's question or prompt (1-10,000 characters)
chat_history
ChatHistoryMode
ChatHistoryMode.OFF
Enable/disable chat history (ON or OFF)
sdk_unique_id
str
None
Unique session identifier (1-100 characters)
use_custom_context
bool
False
Whether to use custom context injection
context_injection
ContextInjectionModel
None
Custom context data (required if use_custom_context=True)
Basic LLM Usage
Buffered Chat (Complete Response)
Streaming Chat (Real-time Response)
Context Injection
Context injection allows you to customize the AI's responses with specific company, project, or token information.
ContextInjectionModel Parameters
company_name
str
None
Company or project name
company_description
str
None
Brief description of the company/project
company_website_url
HttpUrl
None
Company website URL
white_paper_url
HttpUrl
None
Whitepaper URL
purpose
str
None
Purpose or role of the AI chatbot
crypto_token
bool
None
Whether the project has a crypto token
token_information
TokenInformationModel
None
Token details (required if crypto_token=True)
social_media_urls
List[SocialMediaUrlModel]
None
Social media URLs
limitation
bool
None
Content limitation flag
ai_tone
AITone
None
AI tone setting
selected_tone
PresetTone
None
Selected preset tone (required if ai_tone=PRE_SET_TONE)
custom_tone
str
None
Custom tone description (required if ai_tone=CUSTOM_TONE)
TokenInformationModel Parameters
token_name
str
None
Name of the token
token_symbol
str
None
Token symbol/ticker
token_address
str
None
Token contract address
token_source_code
str
None
Token source code or repository URL
token_audit_url
HttpUrl
None
URL to token audit report
explorer_url
HttpUrl
None
Block explorer URL for the token
cmc_url
HttpUrl
None
CoinMarketCap URL
coingecko_url
HttpUrl
None
CoinGecko URL
blockchain
List[BlockchainNetwork]
None
List of supported blockchain networks
SocialMediaUrlModel Parameters
name
str
Required
Name of the social media platform
url
HttpUrl
Required
URL to the social media profile
Context Injection Example
Enums and Constants
ChatHistoryMode
ChatHistoryMode.ON: Enable chat historyChatHistoryMode.OFF: Disable chat history
AITone Options
AITone.DEFAULT_TONE: Use default AI toneAITone.CUSTOM_TONE: Use custom tone (requirescustom_toneparameter)AITone.PRE_SET_TONE: Use preset tone (requiresselected_toneparameter)
PresetTone Options
PROFESSIONAL
Professional business tone
FRIENDLY
Casual and friendly tone
INFORMATIVE
Educational and detailed tone
FORMAL
Formal and structured tone
CONVERSATIONAL
Natural conversation tone
AUTHORITATIVE
Expert and confident tone
PLAYFUL
Light and entertaining tone
INSPIRATIONAL
Motivational and uplifting tone
CONCISE
Brief and to-the-point tone
EMPATHETIC
Understanding and caring tone
ACADEMIC
Scholarly and research-focused tone
NEUTRAL
Balanced and objective tone
SARCASTIC_MEME_STYLE
Humorous and meme-like tone
Supported Blockchain Networks
Ethereum
ETHEREUM
Binance Smart Chain
BSC
Arbitrum
ARBITRUM
Base
BASE
Blast
BLAST
Avalanche
AVALANCHE
Polygon
POLYGON
Scroll
SCROLL
Optimism
OPTIMISM
Linea
LINEA
zkSync
ZKSYNC
Polygon zkEVM
POLYGON_ZKEVM
Gnosis
GNOSIS
Fantom
FANTOM
Moonriver
MOONRIVER
Moonbeam
MOONBEAM
Boba
BOBA
Metis
METIS
Lisk
LISK
Aurora
AURORA
Sei
SEI
Immutable zkEVM
IMMUTABLE_ZK
Gravity
GRAVITY
Taiko
TAIKO
Cronos
CRONOS
Fraxtal
FRAXTAL
Abstract
ABSTRACT
World Chain
WORLD_CHAIN
Mantle
MANTLE
Mode
MODE
Celo
CELO
Berachain
BERACHAIN
Error Handling
The SDK provides comprehensive error handling with specific exception types:
Exception Types
ChainGPTError
Base exception for all SDK errors
General SDK errors
APIError
API returned an error response
API-specific errors
AuthenticationError
Authentication failed (401)
Invalid API key
ValidationError
Request validation failed (400)
Invalid request parameters
InsufficientCreditsError
Account has insufficient credits (402/403)
No credits remaining
RateLimitError
Rate limit exceeded (429)
Too many requests
NotFoundError
Endpoint not found (404)
Invalid endpoint
ServerError
Server error (5xx)
API server issues
TimeoutError
Request timed out
Network timeout
StreamingError
Streaming encountered an error
Streaming-specific issues
ConfigurationError
SDK configuration is invalid
Invalid configuration
Error Handling Example
Complete Example
Here's a comprehensive example demonstrating various features:
Best Practices
Always use context managers or remember to call
close()to properly clean up resourcesHandle exceptions appropriately - use specific exception types for better error handling
Use unique session IDs when maintaining chat history across multiple requests
Validate context injection - ensure required fields are provided when using custom context
Consider rate limits - implement retry logic with exponential backoff for production use
Use streaming for long responses - better user experience for lengthy AI responses
Store API keys securely - use environment variables, not hardcoded values
This concludes the documentation for the AI Chatbot & LLM feature!
Last updated
Was this helpful?