Skip to content

Commit

Permalink
Merge branch 'd/new-cookbooks' into d/update-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorrr committed Oct 6, 2024
2 parents 89612f3 + fab18f3 commit ee4d21f
Show file tree
Hide file tree
Showing 17 changed files with 3,244 additions and 147 deletions.
301 changes: 162 additions & 139 deletions agents-api/poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions agents-api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jupyterlab = "^4.2.4"
ipywidgets = "^8.1.3"

wat-inspector = "^0.2.1"
julep = ">=1.0,<2.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Expand Down
71 changes: 71 additions & 0 deletions cookbooks/01-Website_Crawler_using_Spider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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()

# Creating 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")

# Creating an "agent"
name = "Jarvis"
about = "The original AI conscious the Iron Man."

# Create the agent
agent = client.agents.create_or_update(
agent_id=AGENT_UUID,
name=name,
about=about,
model="gpt-4o",
)

# Defining a Task
task_def = yaml.safe_load("""
name: Agent Crawler
tools:
- name: spider_crawler
type: integration
integration:
provider: spider
setup:
spider_api_key: "{{SPIDER_API_KEY}}"
main:
- tool: spider_crawler
arguments:
url: '"https://spider.cloud"'
""")

# 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={}
)

# 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)

# Streaming the execution steps
print("Streaming execution transitions:")
for transition in client.executions.transitions.stream(execution_id=execution.id):
print(transition)
89 changes: 89 additions & 0 deletions cookbooks/02-Sarcastic_News_Headline_Generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
104 changes: 104 additions & 0 deletions cookbooks/03-SmartResearcher_With_WebSearch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import uuid
from julep import Client
import yaml

# Global UUID is generated for agent and task
AGENT_UUID = uuid.uuid4()
TASK_UUID = uuid.uuid4()

# Creating Julep Client with the API Key
api_key = "" # Your API key here
client = Client(api_key=api_key, environment="dev")

# Creating an "agent"
name = "Jarvis"
about = "The original AI conscious the Iron Man."
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",
)

# Defining a Task
task_def = yaml.safe_load("""
name: Research Assistant to find Wikipedia Keywords
input_schema:
type: object
properties:
topics:
type: array
items:
type: string
description: The topics to search for.
tools:
- name: brave_search
type: integration
integration:
provider: brave
setup:
api_key: "YOUR_API_KEY"
main:
- over: _.topics
map:
tool: brave_search
arguments:
query: "'the latest news about ' + _"
- over: _
parallelism: 2
map:
prompt:
- role: system
content: >-
You are a research assistant.
I need you to do in-depth research on topics trending in the news currently.
Based on the following latest html news snippet, come up with a list of wikipedia keywords to search:
"{{_}}"
Your response should be a list of keywords, separated by commas. Do not add any other text.
Example: `KEYWORDS: keyword1, keyword2, keyword3`
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.id,
input={
"topics": ["Burger King Cup on the Ground Behind a Wendy's", "Forbidden Chemical X", "Finger Bracelets", "Amusing Notions"]
}
)

print(execution.id)

# 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)

# Streaming the execution steps
client.executions.transitions.stream(execution_id=execution.id)
Loading

0 comments on commit ee4d21f

Please sign in to comment.