Create Chat
Create a new chat instance to interact with AI models using Python.Constructor
Parameters
ZGComputeBroker
required
The compute broker instance for connecting to the 0G network
str
required
The provider address on the 0G network for the AI model
float
default:"0.7"
Controls randomness in responses (0.0-2.0)
int
default:"1000"
Maximum number of tokens in the response
Response
Returns aChat instance that can be used to send messages and stream responses.
Example
Available Models
The 0G AI SDK connects to models running on the 0G decentralized compute network:Methods
ask()
Send a simple question to the AI model.question(str): The question to ask the AIsystem_prompt(Optional[str]): Optional system prompt to set context
str - The AI’s response
Example:
chat_completion()
Send a structured chat completion request.messages(List[ChatMessage]): List of chat messages
ChatCompletionResponse - Structured response with usage info
Example:
stream_chat_completion()
Stream responses for real-time chat.messages(List[ChatMessage]): List of chat messageson_chunk(callable): Callback function for each chunk
str - Complete response text
Example:
get_service_info()
Get information about the AI service.ServiceMetadata - Service information including endpoint and model
Example:
Configuration Methods
set_temperature()
Update the temperature setting.temperature(float): New temperature value (0.0-2.0)
set_max_tokens()
Update the maximum tokens setting.max_tokens(int): New maximum tokens value
get_config()
Get current configuration.Dict[str, Any] - Current configuration settings
Example:
Error Handling
The constructor and methods will raise exceptions if:- Invalid provider address is provided
- Network connection fails
- Invalid configuration parameters are passed