22Basic example of using Grok model in PraisonAI
33"""
44
5- from praisonai import PraisonAI
5+ from praisonaiagents import Agent
66
7- def main ():
8- # Initialize PraisonAI with Grok model
9- praison = PraisonAI (
10- model = "grok" ,
11- api_key = "your-grok-api-key-here" # Replace with your actual Grok API key
12- )
13-
14- # Create a simple agent
15- agent = praison .create_agent (
16- name = "Grok Agent" ,
17- description = "A basic agent using Grok model"
18- )
19-
20- # Example conversation
21- response = agent .run ("Hello! Can you explain quantum computing in simple terms?" )
22- print ("Agent Response:" , response )
23-
24- # Example with mathematical reasoning
25- math_task = """
26- Solve this problem step by step:
27- If a train travels at 60 mph for 2.5 hours, how far does it travel?
28- """
29-
30- response = agent .run (math_task )
31- print ("\n Math Task Response:" )
32- print (response )
33-
34- # Example with creative writing
35- creative_task = """
36- Write a short story about a robot learning to paint.
37- Make it engaging and about 100 words.
38- """
39-
40- response = agent .run (creative_task )
41- print ("\n Creative Task Response:" )
42- print (response )
7+ # Initialize Agent with Grok model
8+ agent = Agent (
9+ instructions = "You are a helpful assistant" ,
10+ llm = "xai/grok-beta" ,
11+ )
4312
44- if __name__ == "__main__" :
45- main ()
13+ # Example conversation
14+ response = agent .start ("Hello! Can you explain quantum computing in simple terms?" )
15+
16+ # Example with mathematical reasoning
17+ math_task = """
18+ Solve this problem step by step:
19+ If a train travels at 60 mph for 2.5 hours, how far does it travel?
20+ """
21+
22+ response = agent .start (math_task )
23+
24+ # Example with creative writing
25+ creative_task = """
26+ Write a short story about a robot learning to paint.
27+ Make it engaging and about 100 words.
28+ """
29+
30+ response = agent .start (creative_task )
0 commit comments