Skip to content

Commit

Permalink
feat(cookbooks): fixed bugs in 6,7,8. Markdwon updates in cookbook 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Vedantsahai18 committed Oct 7, 2024
1 parent 5ede3ff commit c682ea4
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 73 deletions.
13 changes: 9 additions & 4 deletions cookbooks/01-Website_Crawler_using_Spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,20 @@
input={}
)

# Waiting for the execution to complete
import time
time.sleep(5)

# 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)
print("Execution Steps:")
for transition in transitions:
print(transition)

# Streaming the execution steps
# Stream the steps of the defined task
print("Streaming execution transitions:")
for transition in client.executions.transitions.stream(execution_id=execution.id):
print(transition)
print(client.executions.transitions.stream(execution_id=execution.id))
12 changes: 9 additions & 3 deletions cookbooks/02-Sarcastic_News_Headline_Generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,21 @@
}
)

# Waiting for the execution to complete
import time
time.sleep(5)

# 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)
print("Execution Steps:")
for transition in transitions:
print(transition)

# Stream the steps of the defined task
print("Streaming execution transitions:")
for transition in client.executions.transitions.stream(execution_id=execution.id):
print(transition)
print(client.executions.transitions.stream(execution_id=execution.id))

14 changes: 10 additions & 4 deletions cookbooks/03-SmartResearcher_With_WebSearch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import uuid
from julep import Client
import yaml
import yaml, time

# Global UUID is generated for agent and task
AGENT_UUID = uuid.uuid4()
Expand Down Expand Up @@ -92,13 +92,19 @@

print(execution.id)

# Wait for the execution to complete
time.sleep(10)

# Getting the execution details
execution = client.executions.get(execution.id)
print(execution.output)

# Listing all the steps of a defined task
transitions = client.executions.transitions.list(execution_id=execution.id).items
print(transitions)
print("Execution Steps:")
for transition in transitions:
print(transition)

# Streaming the execution steps
client.executions.transitions.stream(execution_id=execution.id)
# Stream the steps of the defined task
print("Streaming execution transitions:")
print(client.executions.transitions.stream(execution_id=execution.id))
2 changes: 1 addition & 1 deletion cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"div align=\"center\">\n",
"<div align=\"center\">\n",
" <img src=\"https://socialify.git.ci/julep-ai/julep/image?description=1&descriptionEditable=Build%20AI%20agents%20and%20workflows%20with%20a%20simple%20API&font=Source%20Code%20Pro&logo=https%3A%2F%2Fraw.githubusercontent.com%2Fjulep-ai%2Fjulep%2Fdev%2F.github%2Fjulep-logo.svg&owner=1&pattern=Solid&stargazers=1&theme=Auto\" alt=\"julep\" width=\"640\" height=\"320\" />\n",
"</div>\n",
"\n",
Expand Down
17 changes: 11 additions & 6 deletions cookbooks/04-TripPlanner_With_Weather_And_WikiInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,22 @@

print(f"Execution ID: {execution.id}")

# Wait for the execution to complete
import time
time.sleep(10)

# Getting the execution details
execution = client.executions.get(execution.id)
print("Execution Output:")
print(execution.output)

# List all steps of the executed task
print("Execution Steps:")
for item in client.executions.transitions.list(execution_id=execution.id).items:
print(item)
transitions = client.executions.transitions.list(execution_id=execution.id).items
print("Execution Steps:")
for transition in transitions:
print(transition)

# Stream the execution steps in real-time
print("Streaming Execution Steps:")
for step in client.executions.transitions.stream(execution_id=execution.id):
print(step)
# Stream the steps of the defined task
print("Streaming execution transitions:")
print(client.executions.transitions.stream(execution_id=execution.id))
14 changes: 8 additions & 6 deletions cookbooks/06-Designing_Multi-Step_Tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uuid
import yaml
import yaml, time
from julep import Client

# Global UUID is generated for agent and task
Expand Down Expand Up @@ -121,18 +121,20 @@

print(f"Execution ID: {execution.id}")

# Wait for the execution to complete
time.sleep(10)

# Getting the execution details
execution = client.executions.get(execution.id)
print("Execution Output:")
print(execution.output)
print(client.executions.transitions.list(execution_id=execution.id).items[0].output)

# Listing all the steps of a defined task
transitions = client.executions.transitions.list(execution_id=execution.id).items
print("Execution Steps:")
for transition in transitions:
print(transition)

# Streaming the execution steps
print("Streaming Execution Steps:")
for transition in client.executions.transitions.stream(execution_id=execution.id):
print(transition)
# Stream the steps of the defined task
print("Streaming execution transitions:")
print(client.executions.transitions.stream(execution_id=execution.id))
16 changes: 10 additions & 6 deletions cookbooks/07-Integrating_External_Tools_and_APIs.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,21 @@

print(f"Execution ID: {execution.id}")

# Waiting for the execution to complete
import time
time.sleep(10)

# Getting the execution details
execution = client.executions.get(execution.id)
print("Execution Output:")
print(execution.output)

# List all steps of the executed task
transitions = client.executions.transitions.list(execution_id=execution.id).items
print("Execution Steps:")
for item in client.executions.transitions.list(execution_id=execution.id).items:
print(item)
for transition in transitions:
print(transition)

# Stream the execution steps in real-time
print("Streaming Execution Steps:")
for step in client.executions.transitions.stream(execution_id=execution.id):
print(step)
# Stream the steps of the defined task
print("Streaming execution transitions:")
print(client.executions.transitions.stream(execution_id=execution.id))
35 changes: 21 additions & 14 deletions cookbooks/08-Managing_Persistent_Sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
main:
- prompt:
role: system
- role: system
content: >-
You are a session management agent. Your task is to maintain context
across user interactions. Here's the current context: {{inputs[0].session_context}}
Expand All @@ -53,16 +53,17 @@
Respond to the user and update the context with any new relevant information.
unwrap: true
- evaluate:
updated_context: >-
{**inputs[0].session_context,
session_context: >-
{
**inputs[0].session_context,
'last_interaction': inputs[0].user_input,
'agent_response': _}
'agent_response': _}
- return:
response: _
context: outputs[1].updated_context
context: outputs[1].session_context
""")

# Creating the task
Expand All @@ -78,7 +79,7 @@ def user_interaction(prompt):

# Create a session
session = client.sessions.create(
agent_id=AGENT_UUID,
agent=agent.id,
context_overflow="adaptive" # Use adaptive context management
)

Expand All @@ -100,10 +101,15 @@ def user_interaction(prompt):

# Get the execution result
result = client.executions.get(execution.id)

time.sleep(2)

# Update the context and print the response
context = result.output['context']
print(f"Agent: {result.output['response']}")
final_response = client.executions.transitions.list(execution_id=result.id).items[0].output
print(final_response)
# print(client.executions.transitions.list(execution_id=result.id).items[0])
context = final_response['session_context']
print(f"Agent: {final_response['session_context']['agent_response']}")
print(f"Updated Context: {context}")
print()

Expand All @@ -127,11 +133,12 @@ def user_interaction(prompt):
)

overflow_result = client.executions.get(overflow_execution.id)
print(f"Agent response to large input: {overflow_result.output['response']}")
print(f"Updated context after overflow: {overflow_result.output['context']}")
time.sleep(2)
overflow_response = client.executions.transitions.list(execution_id=overflow_result.id).items[0].output
print(f"Agent response to large input: {overflow_response['session_context']['agent_response']}")
print(f"Updated context after overflow: {overflow_response['session_context']}")

# Display session history
print("\nSession History:")
history = client.sessions.messages.list(session_id=session.id)
for message in history.items:
print(f"{message.role}: {message.content}")
history = client.sessions.history(session_id=session.id)
print(history)
65 changes: 36 additions & 29 deletions cookbooks/09-User_Management_and_Personalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
main:
- prompt:
role: system
- role: system
content: >-
You are a user registration assistant. Create a user profile based on the following information:
Username: {{inputs[0].username}}
Expand All @@ -60,10 +60,10 @@
- evaluate:
user_profile: >-
{
"username": inputs[0].username,
"interests": inputs[0].interests,
"bio": _.split('\n\n')[0],
"content_preferences": _.split('\n\n')[1]
'username': {{inputs[0].username}},
'interests': {{inputs[0].interests}},
'bio': '_.split('\n\n')[0]',
'content_preferences': '_.split('\n\n')[1]'
}
- return: outputs[1].user_profile
Expand All @@ -85,44 +85,41 @@
properties:
user_profile:
type: object
tools:
- name: content_database
type: integration
integration:
provider: mock
setup:
data: [
{"id": 1, "title": "Introduction to AI", "category": "Technology"},
{"id": 2, "title": "Healthy Eating Habits", "category": "Health"},
{"id": 3, "title": "Financial Planning 101", "category": "Finance"},
{"id": 4, "title": "The Art of Photography", "category": "Art"},
{"id": 5, "title": "Beginner's Guide to Yoga", "category": "Fitness"}
]
description: User's profile containing their interests and preferences.
content_list:
type: array
description: List of available content to recommend from.
items:
type: object
properties:
id:
type: integer
title:
type: string
category:
type: string
main:
- tool: content_database
arguments: {}
- prompt:
role: system
- role: system
content: >-
You are a content recommendation system. Based on the user's profile and the available content,
recommend 3 pieces of content that best match the user's interests and preferences.
User Profile:
{{inputs[0].user_profile}}
Available Content:
{{outputs[0]}}
{{inputs[0].content_list}}
Provide your recommendations in the following format:
1. [Content ID] - [Content Title] - Reason for recommendation
2. [Content ID] - [Content Title] - Reason for recommendation
3. [Content ID] - [Content Title] - Reason for recommendation
unwrap: true
- return: _
""")

# Creating the recommendation task
Expand All @@ -144,17 +141,27 @@ def register_user(username, interests):
result = client.executions.get(execution.id)
return result.output

# Function to get personalized content recommendations
# Function to get personalized recommendations for a user
def get_recommendations(user_profile):
content_list = [
{"id": 1, "title": "Introduction to AI", "category": "Technology"},
{"id": 2, "title": "Healthy Eating Habits", "category": "Health"},
{"id": 3, "title": "Financial Planning 101", "category": "Finance"},
{"id": 4, "title": "The Art of Photography", "category": "Art"},
{"id": 5, "title": "Beginner's Guide to Yoga", "category": "Fitness"}
]

execution = client.executions.create(
task_id=RECOMMENDATION_TASK_UUID,
input={
"user_profile": user_profile
"user_profile": user_profile,
"content_list": content_list
}
)
result = client.executions.get(execution.id)
return result.output


# Function to update user preferences
def update_user_preferences(user_profile, new_interests):
user_profile["interests"] = list(set(user_profile["interests"] + new_interests))
Expand Down

0 comments on commit c682ea4

Please sign in to comment.