forked from julep-ai/julep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
02-Sarcastic_News_Headline_Generator.py
89 lines (75 loc) · 2.06 KB
/
02-Sarcastic_News_Headline_Generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import os
import uuid
import yaml
from julep import Client
# Global UUID is generated for agent and task
AGENT_UUID = uuid.uuid4()
TASK_UUID = uuid.uuid4()
# Create Julep Client with the API Key
api_key = os.getenv("JULEP_API_KEY")
if not api_key:
raise ValueError("JULEP_API_KEY not found in environment variables")
client = Client(api_key=api_key, environment="dev")
# Define agent properties
name = "Sarcastic News Bot"
about = "An AI agent specialized in generating sarcastic news headlines."
default_settings = {
"temperature": 0.7,
"top_p": 1,
"min_p": 0.01,
"presence_penalty": 0,
"frequency_penalty": 0,
"length_penalty": 1.0,
"max_tokens": 150,
}
# Create the agent
agent = client.agents.create_or_update(
agent_id=AGENT_UUID,
name=name,
about=about,
model="gpt-4o",
)
# Define the task
task_def = yaml.safe_load("""
name: Sarcasm Headline Generator
tools:
- name: brave_search
type: integration
integration:
provider: brave
setup:
api_key: "YOUR_BRAVE_API_KEY"
main:
- tool: brave_search
arguments:
query: "_.topic + ' funny'"
- prompt:
- role: system
content: >-
You are a sarcastic news headline writer. Generate a witty and sarcastic headline
for the topic {{inputs[0].topic}}. Use the following information for context: {{_}}
unwrap: true
""")
# Creating/Updating a task
task = client.tasks.create_or_update(
task_id=TASK_UUID,
agent_id=AGENT_UUID,
**task_def
)
# Creating an Execution
execution = client.executions.create(
task_id=TASK_UUID,
input={
"topic": "elon musk"
}
)
# Getting the execution details
execution = client.executions.get(execution.id)
print("Execution output:", execution.output)
# Listing all the steps of a defined task
transitions = client.executions.transitions.list(execution_id=execution.id).items
print("Execution transitions:", transitions)
# Stream the steps of the defined task
print("Streaming execution transitions:")
for transition in client.executions.transitions.stream(execution_id=execution.id):
print(transition)