Skip to content

Commit

Permalink
D/cookbookfix: cookbooks bugs fixed for 5,10,11. And files renamed ac…
Browse files Browse the repository at this point in the history
…cording to naming convention (#707)

<!-- ELLIPSIS_HIDDEN -->



> [!IMPORTANT]
> Fix bugs in cookbooks 5, 10, 11 and rename files for consistency.
> 
>   - **Behavior**:
> - `05-Basic_Agent_Creation_and_Interaction.py`: Fix session creation
by removing `context_overflow` parameter and correct chat history
retrieval.
> - `10-Document_Management_and_Search.py`: Remove `filters` from search
input and fix document search output handling.
> - `11-Advanced_Chat_Interactions.py`: Adjust chat logic for weather
information and improve context management.
>   - **Renames**:
> - Rename `14_automated_webinar_scheduling_workflow.py` to
`14-Automated_Webinar_Scheduling_Workflow.py`.
> - Rename `15_personal_finance_tracker.py` to
`15-Personal_Finance_Tracker.py`.
> - Rename `e_commerce_order_processing_workflow.py` to
`16-E_commerce_Order_Processing_Workflow.py`.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=julep-ai%2Fjulep&utm_source=github&utm_medium=referral)<sup>
for 7cdfd86. It will automatically
update as commits are pushed.</sup>

<!-- ELLIPSIS_HIDDEN -->

---------

Co-authored-by: Vedantsahai18 <Vedantsahai18@users.noreply.github.com>
  • Loading branch information
Vedantsahai18 and Vedantsahai18 authored Oct 19, 2024
1 parent 3669ca5 commit e341fb1
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 58 deletions.
11 changes: 4 additions & 7 deletions cookbooks/05-Basic_Agent_Creation_and_Interaction.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# UNDER CONSTRUCTION - NOT WORKING YET
# BASIC AGENT CREATION AND INTERACTION

import uuid
from julep import Client
Expand Down Expand Up @@ -35,8 +35,7 @@

# Create a session for interaction
session = client.sessions.create(
agent=agent.id,
context_overflow="adaptive"
agent=agent.id
)

print(f"Session created with ID: {session.id}")
Expand All @@ -47,7 +46,6 @@ def chat_with_agent(message):
"role": "user",
"content": message,
}
# TODO: message validation error
response = client.sessions.chat(
session_id=session.id,
messages=[message],
Expand All @@ -67,7 +65,6 @@ def chat_with_agent(message):
print(f"Agent: {response}")

# Optional: Retrieve chat history
history = client.sessions.messages.list(session_id=session.id)
history = client.sessions.get(session_id=session.id)
print("\nChat History:")
for message in history.items:
print(f"{message.role}: {message.content}")
print(history)
25 changes: 11 additions & 14 deletions cookbooks/10-Document_Management_and_Search.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
# 7. Execute the document search task
# 8. Display the search results

# UNDER CONSTRUCTION - YAML is working but the flow is not correct yet

import uuid
import yaml,time
from julep import Client
Expand Down Expand Up @@ -93,8 +91,6 @@
properties:
query:
type: string
filters:
type: object
tools:
- name: document_search
Expand All @@ -108,18 +104,16 @@
arguments:
agent_id: "'{agent.id}'"
text: inputs[0].query
metadata_filters: inputs[0].filters
- prompt:
- role: system
content: >-
Based on the search results, provide a summary of the most relevant documents found.
Search query: {{inputs[0].query}}
Search query: {{{{inputs[0].query}}}}
Number of results: {{len(outputs[0])}}
Results:
{{outputs[0]}}
unwrap: true
{{{{outputs[0]}}}}
""")

# Creating the search task
Expand Down Expand Up @@ -166,8 +160,7 @@
search_execution = client.executions.create(
task_id=SEARCH_TASK_UUID,
input={
"query": "impact of technology on society",
"filters": {"category": "technology"}
"query": "technology"
}
)

Expand All @@ -178,10 +171,14 @@
# Display the search results
print("\nSearch Results:")
for transition in client.executions.transitions.list(execution_id=search_execution.id).items:
if transition.type == "tool_call" and transition.tool == "document_search":
for doc in transition.output:
print(f"- {doc['content']} (Score: {doc['score']})")
if transition.type == "step" and transition.metadata['step_type'] == "ToolCallStep":
doc_output = transition.output['docs']
for doc in doc_output:
print(f"Owner: {doc['owner']}")
print(f"Title: {doc['title']}")
print(f"Distance: {doc['distance']}")
print(f"Content: {doc['snippets']}")

print("\nSearch Summary:")
search_response = client.executions.transitions.list(search_result.id).items[0].output
search_response = client.executions.transitions.list(search_result.id).items[0].output['choices'][0]['message']['content']
print(search_response)
74 changes: 37 additions & 37 deletions cookbooks/11-Advanced_Chat_Interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# d. Integrating external information during the conversation
# 6. Display the chat history and any relevant metrics

# UNDER CONSTRUCTION - YAML is working but the flow is not correct yet
# UNDER CONSTRUCTION - Dynamic weather integration is not yet implemented, rest of the code is functional

import uuid
import yaml
Expand Down Expand Up @@ -75,49 +75,51 @@
integration:
provider: weather
setup:
api_key: "API_KEY"
api_key: "YOUR_WEATHER_API_KEY"
main:
- evaluate:
context_length: len(inputs[0].chat_history)
- if: "_.context_length > '10'"
- if: "len(inputs[0].chat_history) > 5"
then:
evaluate:
summarized_history: str(inputs[0].chat_history[-5:])
else:
evaluate:
summarized_history: str(inputs[0].chat_history)
- if: "search_regex('weather', inputs[0].user_input)"
then:
tool: weather_api
arguments:
location: "'NEW YORK'"
else:
evaluate:
summarized_history: str(inputs[0].chat_history[-10:])
weather: "'No weather information requested'"
- evaluate:
weather: outputs[1]
- if: "search_regex('weather', inputs[0].user_input)"
then:
prompt:
- role: system
content: >-
content: >-
You are an advanced chat assistant. Here's a summary of the recent conversation:
{{outputs[1].summarized_history}}
{{outputs[0].summarized_history}}
The user mentioned weather. Here's the current weather information for NEW YORK
Incorporate this information into your response.
{{_.weather}}
Now, respond to the user's latest input: {{inputs[0].user_input}}
unwrap: true
else:
prompt:
- role: system
content: >-
You are an advanced chat assistant. Here's the conversation history:
{{inputs[0].chat_history}}
You are an advanced chat assistant. Here's a summary of the recent conversation:
{{outputs[0].summarized_history}}
Now, respond to the user's latest input: {{inputs[0].user_input}}
unwrap: true
- if: "'weather' in inputs[0].user_input.lower()"
then:
tool: weather_api
arguments:
location: inputs[0].user_input.lower.split('weather')[1].strip()
prompt:
- role: system
content: >-
The user mentioned weather. Here's the current weather information for {{inputs[0].user_input.lower.split('weather')[1].strip()}}
Incorporate this information into your response.
unwrap: true
- return:
summary: _
""")

# Creating the chat task
Expand All @@ -141,8 +143,6 @@ def run_chat_session():
chat_history = []
print("Starting advanced chat session. Type 'exit' to end the conversation.")

session = client.sessions.create(agent=AGENT_UUID)

while True:
user_input = get_user_input()
if user_input.lower() == 'exit':
Expand All @@ -158,17 +158,17 @@ def run_chat_session():
}
)
# Wait for the execution to complete
time.sleep(3)
time.sleep(5)
result = client.executions.get(execution.id)
print(client.executions.transitions.list(execution.id).items)
print(f"Execution result: {result.output}")
assistant_response = result.output
assistant_response = result.output['choices'][0]['message']['content']

chat_history.append({"role": "assistant", "content": assistant_response})
print(f"Assistant: {assistant_response}")
print(f"Assistant: { assistant_response}")

# Simulate a delay for a more natural conversation flow
time.sleep(1)
print("----------------------")

print("\nChat session ended. Here's the complete chat history:")
display_chat_history(chat_history)
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit e341fb1

Please sign in to comment.