Examples

NeuralNode Examples

Learn by example — from beginner to advanced.

Basic Text Generation

Generate human-like text using powerful LLMs.

LLM / Generation
example.py
1import neuralnode as nn
2
3# Initialize the client
4client = nn.Client(api_key="YOUR_API_KEY")
5
6# Generate text
7response = client.generate(
8    model="claude-3-5-sonnet",
9    prompt="Write a short poem about AI."
10)
11
12print(response.text)

AI Agent with Tools

Create an autonomous AI agent capable of using custom tools.

AI Agent
example.py
1import neuralnode as nn
2
3# Define a tool
4@nn.tool
5def get_weather(location: str):
6    """Get the weather for a location."""
7    return f"The weather in {location} is sunny."
8
9# Create the agent
10agent = nn.Agent(
11    model="gpt-4o",
12    tools=[get_weather],
13    system_prompt="You are a helpful assistant."
14)
15
16# Run the agent
17response = agent.run("What's the weather like in Paris?")
18print(response)

Streaming Responses

Stream the LLM response token by token in real-time.

Streaming
example.py
1import neuralnode as nn
2
3client = nn.Client()
4
5# Stream the response
6stream = client.stream(
7    model="gemini-1.5-pro",
8    prompt="Explain quantum computing in simple terms."
9)
10
11for chunk in stream:
12    print(chunk.text, end="", flush=True)

API Deployment

Deploy your AI agent as a REST API endpoint.

Deployment
example.py
1import neuralnode as nn
2from neuralnode.api import API
3
4# Create your agent
5agent = nn.Agent(model="mistral-large")
6
7# Create API
8app = API(agent, rate_limit=1000)
9
10@app.post("/chat")
11def chat_endpoint(data: dict):
12    result = agent.run(data["message"])
13    return {"reply": result}
14
15@app.get("/health")
16def health():
17    return {"status": "healthy", "version": "v1.0"}
18
19if __name__ == "__main__":
20    app.run(host="0.0.0.0", port=8000)