Skip to content

Commit

Permalink
cookbook: 11 bug fixed (dynamic weather not imp)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vedantsahai18 committed Oct 16, 2024
1 parent 2131c0c commit 3dc2f2b
Showing 1 changed file with 27 additions and 34 deletions.
61 changes: 27 additions & 34 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 @@ -78,46 +78,39 @@
api_key: "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[-10:])
prompt:
- role: system
content: >-
You are an advanced chat assistant. Here's a summary of the recent conversation:
{{outputs[1].summarized_history}}
Now, respond to the user's latest input: {{inputs[0].user_input}}
unwrap: true
summarized_history: str(inputs[0].chat_history[-5:])
else:
prompt:
- role: system
content: >-
You are an advanced chat assistant. Here's the conversation history:
{{inputs[0].chat_history}}
Now, respond to the user's latest input: {{inputs[0].user_input}}
unwrap: true
evaluate:
summarized_history: str(inputs[0].chat_history)
- if: "'weather' in inputs[0].user_input.lower()"
- if: "search_regex('weather', inputs[0].user_input)"
then:
tool: weather_api
arguments:
location: inputs[0].user_input.lower.split('weather')[1].strip()
location: "NEW YORK"
prompt:
- role: system
content: >-
The user mentioned weather. Here's the current weather information for {{inputs[0].user_input.lower.split('weather')[1].strip()}}
content: >-
You are an advanced chat assistant. Here's a summary of the recent conversation:
{{outputs[0].summarized_history}}
The user mentioned weather. Here's the current weather information for NEW YORK
Incorporate this information into your response.
unwrap: true
- return:
summary: _
{{outputs[1]}}
Now, respond to the user's latest input: {{inputs[0].user_input}}
else:
prompt:
- role: system
content: >-
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}}
""")

# Creating the chat task
Expand Down Expand Up @@ -158,17 +151,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

0 comments on commit 3dc2f2b

Please sign in to comment.