From e341fb1a3d68b1652693ff7ea393c558a62c119a Mon Sep 17 00:00:00 2001 From: Vedant Sahai Date: Fri, 18 Oct 2024 20:27:03 -0400 Subject: [PATCH] D/cookbookfix: cookbooks bugs fixed for 5,10,11. And files renamed according to naming convention (#707) > [!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`. > > This description was created by [Ellipsis](https://www.ellipsis.dev?ref=julep-ai%2Fjulep&utm_source=github&utm_medium=referral) for 7cdfd86ffe7c8e43509bbfca5c0373345b99236f. It will automatically update as commits are pushed. --------- Co-authored-by: Vedantsahai18 --- ...05-Basic_Agent_Creation_and_Interaction.py | 11 +-- .../10-Document_Management_and_Search.py | 25 +++---- cookbooks/11-Advanced_Chat_Interactions.py | 74 +++++++++---------- ...tomated_Webinar_Scheduling_Workflow.ipynb} | 0 ...-Automated_Webinar_Scheduling_Workflow.py} | 0 ...pynb => 15-Personal_Finance_Tracker.ipynb} | 0 ...cker.py => 15-Personal_Finance_Tracker.py} | 0 ..._commerce_Order_Processing_Workflow.ipynb} | 0 ...6-E_commerce_Order_Processing_Workflow.py} | 0 9 files changed, 52 insertions(+), 58 deletions(-) rename cookbooks/{14_Automated_Webinar_Scheduling_Workflow.ipynb => 14-Automated_Webinar_Scheduling_Workflow.ipynb} (100%) rename cookbooks/{14_automated_webinar_scheduling_workflow.py => 14-Automated_Webinar_Scheduling_Workflow.py} (100%) rename cookbooks/{15_Personal_Finance_Tracker.ipynb => 15-Personal_Finance_Tracker.ipynb} (100%) rename cookbooks/{15_personal_finance_tracker.py => 15-Personal_Finance_Tracker.py} (100%) rename cookbooks/{E_commerce_Order_Processing_Workflow.ipynb => 16-E_commerce_Order_Processing_Workflow.ipynb} (100%) rename cookbooks/{e_commerce_order_processing_workflow.py => 16-E_commerce_Order_Processing_Workflow.py} (100%) diff --git a/cookbooks/05-Basic_Agent_Creation_and_Interaction.py b/cookbooks/05-Basic_Agent_Creation_and_Interaction.py index 05b16f7bd..e57a38560 100644 --- a/cookbooks/05-Basic_Agent_Creation_and_Interaction.py +++ b/cookbooks/05-Basic_Agent_Creation_and_Interaction.py @@ -1,4 +1,4 @@ -# UNDER CONSTRUCTION - NOT WORKING YET +# BASIC AGENT CREATION AND INTERACTION import uuid from julep import Client @@ -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}") @@ -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], @@ -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}") \ No newline at end of file +print(history) \ No newline at end of file diff --git a/cookbooks/10-Document_Management_and_Search.py b/cookbooks/10-Document_Management_and_Search.py index 10f44117d..2df493f8b 100644 --- a/cookbooks/10-Document_Management_and_Search.py +++ b/cookbooks/10-Document_Management_and_Search.py @@ -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 @@ -93,8 +91,6 @@ properties: query: type: string - filters: - type: object tools: - name: document_search @@ -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 @@ -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" } ) @@ -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) \ No newline at end of file diff --git a/cookbooks/11-Advanced_Chat_Interactions.py b/cookbooks/11-Advanced_Chat_Interactions.py index 1a6b13026..1cfa71555 100644 --- a/cookbooks/11-Advanced_Chat_Interactions.py +++ b/cookbooks/11-Advanced_Chat_Interactions.py @@ -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 @@ -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 @@ -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': @@ -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) diff --git a/cookbooks/14_Automated_Webinar_Scheduling_Workflow.ipynb b/cookbooks/14-Automated_Webinar_Scheduling_Workflow.ipynb similarity index 100% rename from cookbooks/14_Automated_Webinar_Scheduling_Workflow.ipynb rename to cookbooks/14-Automated_Webinar_Scheduling_Workflow.ipynb diff --git a/cookbooks/14_automated_webinar_scheduling_workflow.py b/cookbooks/14-Automated_Webinar_Scheduling_Workflow.py similarity index 100% rename from cookbooks/14_automated_webinar_scheduling_workflow.py rename to cookbooks/14-Automated_Webinar_Scheduling_Workflow.py diff --git a/cookbooks/15_Personal_Finance_Tracker.ipynb b/cookbooks/15-Personal_Finance_Tracker.ipynb similarity index 100% rename from cookbooks/15_Personal_Finance_Tracker.ipynb rename to cookbooks/15-Personal_Finance_Tracker.ipynb diff --git a/cookbooks/15_personal_finance_tracker.py b/cookbooks/15-Personal_Finance_Tracker.py similarity index 100% rename from cookbooks/15_personal_finance_tracker.py rename to cookbooks/15-Personal_Finance_Tracker.py diff --git a/cookbooks/E_commerce_Order_Processing_Workflow.ipynb b/cookbooks/16-E_commerce_Order_Processing_Workflow.ipynb similarity index 100% rename from cookbooks/E_commerce_Order_Processing_Workflow.ipynb rename to cookbooks/16-E_commerce_Order_Processing_Workflow.ipynb diff --git a/cookbooks/e_commerce_order_processing_workflow.py b/cookbooks/16-E_commerce_Order_Processing_Workflow.py similarity index 100% rename from cookbooks/e_commerce_order_processing_workflow.py rename to cookbooks/16-E_commerce_Order_Processing_Workflow.py