Get chat gpt messages

From UBot Studio
(Difference between revisions)
Jump to: navigation, search
(Return Value)
(Example)
 
Line 16: Line 16:
  
 
<pre>
 
<pre>
 +
ui console view
 
config openai("your api key here")
 
config openai("your api key here")
create chat gpt agent("FoodBot", "You are FoodBot, an AI designed to offer food and nutrition advice.", "gpt-4")
+
set(#first prompt,"Hey, I have some questions about tacos. Can I ask them?","Local")
add user message("What should I eat for dinner?", "FoodBot")
+
set(#first response,$chat gpt response(#first prompt,"ChatGPT"),"Local")
set(#agent messages, $get chat gpt messages("FoodBot"), "Global")
+
set(#second prompt,"What\'s the best salsa to use?","Local")
ui text box(#agent messages)
+
set(#second response,$chat gpt response(#second prompt,"ChatGPT"),"Local")
 +
log($get chat gpt messages("ChatGPT"))
 
</pre>
 
</pre>
  
 
Remember to swap "your api key here" with your actual API key.
 
Remember to swap "your api key here" with your actual API key.
  
This script first creates a chat bot named "FoodBot" who offers food and nutrition advice, then adds a user message querying about dinner options. Then, it retrieves the messages from the FoodBot agent and displays them in a textbox. The returned messages will be either empty or include the added user message, depending on whether any other messages have been added to the conversation.
+
This script will simulate a conversation with ChatGPT. It will not log the conversation as it happens, but at the end, it will log the entire conversation returned by '''$get chat gpt messages'''
 +
 
 +
The responses from ChatGPT will look different every time, but the output of this script might look something like this:
 +
<pre>
 +
- role: 'system'
 +
  content: 'You are a helpful assistant.'
 +
- role: 'user'
 +
  content: 'Hey, I have some questions about tacos. Can I ask them?'
 +
- role: 'assistant'
 +
  content: 'Of course! I''d be happy to help answer your questions about tacos. What would you like to know?'
 +
- role: 'user'
 +
  content: 'What''s the best salsa to use?'
 +
- role: 'assistant'
 +
  content: "The best salsa to use can vary depending on personal taste preferences. Some popular options include red salsa (salsa roja), green salsa (salsa verde), and pico de gallo. \n'\n'Red salsa is typically made with tomatoes, chili peppers, onions, and garlic. It can range from mild to spicy, depending on the type and amount of chili peppers used.\n'\n'Green salsa is made with tomatillos, chili peppers, onions, cilantro, and sometimes garlic. It has a tangy and slightly tart flavor.\n'\n'Pico de gallo is a chunky salsa made with tomatoes, onions, cilantro, chili peppers, and lime juice. It is known for its fresh and vibrant taste.\n'\n'Ultimately, the best salsa for you will depend on your personal preference and the type of tacos you are making. Feel free to explore different varieties and adjust the spiciness level to suit your taste buds."
 +
</pre>

Latest revision as of 16:09, 2 July 2023

$get chat gpt messages is a function that returns the messages associated with the specified agent.

This function enables users to retrieve and view the conversation history of a specified chat GPT agent. It shows both bot and user messages in chronological order.

[edit] Parameters

Agent: (optional) The name of the agent from which to retrieve the messages. Default is "ChatGPT".

[edit] Return Value

This function returns an object in yaml format, with a list of the messages associated with the specified agent.

Messages returned by $get chat gpt messages will include both user and bot prompts, all in the order they were added.

[edit] Example

ui console view
config openai("your api key here")
set(#first prompt,"Hey, I have some questions about tacos. Can I ask them?","Local")
set(#first response,$chat gpt response(#first prompt,"ChatGPT"),"Local")
set(#second prompt,"What\'s the best salsa to use?","Local")
set(#second response,$chat gpt response(#second prompt,"ChatGPT"),"Local")
log($get chat gpt messages("ChatGPT"))

Remember to swap "your api key here" with your actual API key.

This script will simulate a conversation with ChatGPT. It will not log the conversation as it happens, but at the end, it will log the entire conversation returned by $get chat gpt messages

The responses from ChatGPT will look different every time, but the output of this script might look something like this:

- role: 'system'
  content: 'You are a helpful assistant.'
- role: 'user'
  content: 'Hey, I have some questions about tacos. Can I ask them?'
- role: 'assistant'
  content: 'Of course! I''d be happy to help answer your questions about tacos. What would you like to know?'
- role: 'user'
  content: 'What''s the best salsa to use?'
- role: 'assistant'
  content: "The best salsa to use can vary depending on personal taste preferences. Some popular options include red salsa (salsa roja), green salsa (salsa verde), and pico de gallo. \n'\n'Red salsa is typically made with tomatoes, chili peppers, onions, and garlic. It can range from mild to spicy, depending on the type and amount of chili peppers used.\n'\n'Green salsa is made with tomatillos, chili peppers, onions, cilantro, and sometimes garlic. It has a tangy and slightly tart flavor.\n'\n'Pico de gallo is a chunky salsa made with tomatoes, onions, cilantro, chili peppers, and lime juice. It is known for its fresh and vibrant taste.\n'\n'Ultimately, the best salsa for you will depend on your personal preference and the type of tacos you are making. Feel free to explore different varieties and adjust the spiciness level to suit your taste buds."
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox