Update langgraph_agent_simple notebook: Adjust execution counts and refine AVAP tool description
- Changed execution counts for several code cells to maintain proper order. - Updated system message to specify the role of the agent in responding to AVAP-related queries. - Modified user input example to inquire about reserved words in AVAP. - Enhanced AI response to include detailed information about AVAP reserved words and provided a code example demonstrating their usage.
This commit is contained in:
parent
1c34771685
commit
b662b9a4fa
File diff suppressed because one or more lines are too long
|
|
@ -34,7 +34,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 22,
|
||||
"id": "30edcecc",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
|
@ -104,7 +104,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 5,
|
||||
"id": "f0a21230",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
|
@ -114,7 +114,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 6,
|
||||
"id": "f9359747",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
|
@ -145,7 +145,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": 7,
|
||||
"id": "e5247ab9",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
|
@ -160,7 +160,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"execution_count": 8,
|
||||
"id": "a644f6fa",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
|
@ -180,7 +180,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"execution_count": 9,
|
||||
"id": "36d0f54e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
|
@ -190,8 +190,11 @@
|
|||
"\n",
|
||||
" system = SystemMessage(\n",
|
||||
" content=(\n",
|
||||
" \"You are a helpful assistant. You MUST ALWAYS use the tools provided to respond.\\n\"\n",
|
||||
" \"If you don't have enough info, ask a precise follow-up question.\"\n",
|
||||
" \"\"\" \n",
|
||||
" You are a specialized agent whose job is to respond questions about a new language code called AVAP, which is a language designed to build APIs.\n",
|
||||
" To responde to the user's question, you have access to a tool called \"retrieve\" that allows you to retrieve relevant documents about AVAP from a vector store.\n",
|
||||
"\n",
|
||||
" \"\"\"\n",
|
||||
" )\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
|
|
@ -211,7 +214,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"execution_count": 10,
|
||||
"id": "fae46a58",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
|
@ -229,7 +232,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"execution_count": 11,
|
||||
"id": "2fec3fdb",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
|
|
@ -261,17 +264,17 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"execution_count": 18,
|
||||
"id": "a7f4fbf6",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"user_input = \"What does vertical farming proposes?\""
|
||||
"user_input = \"What reserved words does AVAP have? Use your tool\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"execution_count": 19,
|
||||
"id": "8569cf39",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
|
@ -292,7 +295,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"execution_count": 21,
|
||||
"id": "53b89690",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
|
|
@ -302,12 +305,69 @@
|
|||
"text": [
|
||||
"================================\u001b[1m Human Message \u001b[0m=================================\n",
|
||||
"\n",
|
||||
"What does vertical farming proposes?\n",
|
||||
"What reserved words does AVAP have? Use your tool\n",
|
||||
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
||||
"Tool Calls:\n",
|
||||
" retrieve (1046519e-448e-44cc-877b-22a77ca13d9a)\n",
|
||||
" Call ID: 1046519e-448e-44cc-877b-22a77ca13d9a\n",
|
||||
" Args:\n",
|
||||
" query: reserved words for AVAP\n",
|
||||
"=================================\u001b[1m Tool Message \u001b[0m=================================\n",
|
||||
"Name: retrieve\n",
|
||||
"\n",
|
||||
"[1] id=chunk-1 title=10_Execution_model_in_avap\n",
|
||||
" terminate when i equals 5, and \"Loop ended\" will be printed. The numbers 0 through 4 will be printed before the loop is exited. Break Statement The break statement in AVAP is used to terminate the closest enclosing loop. Here is an overview of its behavior: Usage Context: The break statement can only occur within a for or while loop. It cannot be nested within a function or class definition inside that loop. Loop Termination: It terminates the closest enclosing loop and skips the optional else clause if the loop has one. Loop Control Target: If a for loop is terminated by break, the loop control target retains its current value. Interaction with try-finally: When break is executed within a try statement with a finally clause, the finally clause is executed before actually exiting the loop. The break statement is essential for controlling loop execution, allowing for early exit from loops and proper handling of loop cleanup. Continue Statement In AVAP, the continue statement is used to proceed with the next iteration of the closest enclosing loop. The syntax for the continue statement is as follows: continue The continue statement can only syntactically occur nested within a for or while loop, but not within a function or class definition inside that loop. When continue is used within a loop that is also handling exceptions with a try statement containing a finally clause, the finally clause is executed before the next iteration of the loop begins. for i in range(10): try: if i % 2 == 0: continue print(i) finally: print(\"In finally clause\") print(\"Loop ended\") In this example, the continue statement will skip the current iteration when i is even, but before moving to the next iteration, the finally clause will print \"In finally clause.\" For odd numbers, the loop will print the number and then \"In finally clause.\" After the loop finishes, \"Loop ended\" will be printed. Import Statement In AVAP, the import statement is used to import an entire code file and define names in the local namespace. The syntax for the import statement is as follows: import file.avap The import statement in AVAP imports an entire code file and makes it available in the local namespace. No alias is assigned to the imported file; the file is simply referred to by its name. For example: # In the 'module.avap' file example_variable = 10 # In the main file import module.avap print(module.avap.example_variable) # Will print 1\n",
|
||||
"\n",
|
||||
"[2] id=chunk-2 title=16_Appendix\n",
|
||||
"01 to 31) %H: Hour in 24-hour format (00 to 23) %M: Minutes (00 to 59) %S: Seconds (00 to 59) For example, the format \"%Y-%m-%d %H:%M:%S\" will present the date and time as 2024-08-25 14:30:00. It can be a direct value or a variable containing the desired format. TimeDelta Type: var Description: An optional value representing a time adjustment (positive or negative) applied to the current date and time before conversion. This value can be provided directly or through a variable and is expressed in seconds. TimeZone Type: var Description: The time zone to which the date and time should be converted. This value can be a time zone identifier provided directly or through a variable. Some common time zones include: \"UTC\": Coordinated Universal Time \"America/New_York\": U.S. Eastern Time (EST/EDT) \"America/Los_Angeles\": U.S. Pacific Time (PST/PDT) \"Europe/London\": London Time (GMT/BST) \"Europe/Madrid\": Madrid Time (CET/CEST) \"Asia/Tokyo\": Tokyo Time (JST) \"Australia/Sydney\": Sydney Time (AEST/AEDT) You can use any time zone recognized by the pytz library in Python, which includes most time zones worldwide. TargetVariable Type: var Description: The variable in which the resulting date and time from the operation will be stored. Unlike the other parameters, this must be a variable and not a direct value. Usage Example // Direct call with values: getDateTime('%Y-%m-%d %H:%M:%S', 3600, 'UTC', currentTime) // Call using variables: format = '%Y-%m-%d %H:%M:%S' adjustment = 3600 timeZone = 'America/New_York' getDateTime(format, adjustment, timeZone, currentDateTime) In the first example, the current date and time are retrieved, adjusted by 3600 seconds (1 hour), converted to UTC, and stored in the variable currentTime. In the second example, variables are used to define the format, time adjustment, and time zone, with the result stored in the currentDateTime variable. encodeMD\n",
|
||||
"\n",
|
||||
"[3] id=chunk-3 title=5_Data_Model\n",
|
||||
"Introduction The data model in AVAP™ defines how data is organized and manipulated within the language. Similar to Python, AVAP™ uses a flexible and dynamic data model that allows for working with a wide variety of data types and data structures. Data Types In AVAP™, just like in Python, data types are categories that represent different kinds of values that can be stored and manipulated in a program. Some of the most common data types in AVAP™ include: Integers (int): Represent whole numbers, positive or negative, without a fractional part. Floating-point numbers (float): Represent numbers with both integer and fractional parts. Strings (str): Represent sequences of Unicode characters. Booleans (bool): Represent truth values, either True or False. Lists (list): Ordered and mutable collections of elements. Tuples (tuple): Ordered and immutable collections of elements. Dictionaries (dict): Unordered collections of key-value pairs. Sets (set): Unordered collections of unique elements. Data Structures In addition to individual data types, AVAP™ provides various data structures that allow for more complex organization and manipulation of data: Lists: Created using square brackets [ ] and can contain any data type, including other lists. Tuples: Created using parentheses ( ) and are immutable, meaning they cannot be modified once created. Dictionaries: Created using curly braces and store key-value pairs, where each key is unique within the dictionary. Sets: Created using curly braces and contain unique elements, meaning there are no duplicates in a set. Data Structures In addition to individual data types, AVAP™ provides various data structures that allow for more complex organization and manipulation of data: Lists: Created using square brackets [ ] and can contain any data type, including other lists. Tuples: Created using parentheses ( ) and are immutable, meaning they cannot be modified once created. Dictionaries: Created using curly braces and store key-value pairs, where each key is unique within the dictionary. Sets: Created using curly braces and contain unique elements, meaning there are no duplicates in a set. Practical Example Below is a practical example that illustrates the use of the data model in AVAP™: # Definition of a list example_list = [1, 2, 3, 4, 5] # Accessing individual elements print(example_list[0]) # Output: 1 # Slicing to get a sublist sublist = example_list[2:4] print(sublist) # Output: [3, 4\n",
|
||||
"\n",
|
||||
"[4] id=chunk-4 title=10_Execution_model_in_avap\n",
|
||||
" might use wildcard patterns in AVAP: match value: case _: print(\"Matched any value\") In this example: case _: matches any value and does not bind it to a name. The pattern always succeeds, and the code within this case will be executed regardless of the value. Wildcard patterns are particularly useful when you need to handle a broad range of possibilities and are only interested in whether a value fits a general condition, not in the value itself. Value Patterns In AVAP, value patterns are used to match specific values. The syntax for a value pattern is: value_pattern ::= attr Value patterns only succeed if the subject's value matches the specified value. They are useful when you want to perform actions based on an exact value. Here’s how you might use value patterns in AVAP: match value: case 42: print(\"Matched the value 42\") case \"hello\": print(\"Matched the string 'hello'\") case _: print(\"Matched something else\") In this example: case 42: matches the value 42 specifically. case \"hello\": matches the string \"hello\" specifically. case _: matches any other value not covered by the previous cases. Value patterns are ideal for scenarios where you need to check for specific values and respond accordingly. They provide precise control over the matching process. Group Patterns In AVAP, group patterns are used to group multiple patterns together. The syntax for a group pattern is: group_pattern ::= \"(\" pattern \")\" Group patterns are useful when you want to combine patterns or when patterns need to be evaluated together. They have the same effect as the pattern they contain but allow for more complex pattern structures. Here’s an example of how to use group patterns in AVAP: match value: case (42 | 43): print(\"Matched either 42 or 43\") case (name, age) if age > 18: print(f\" is an adult\") case _: print(\"Matched something else\") In this example: case (42 | 43): uses a group pattern to match either the value 42 or 43. case (name, age) if age > 18: uses a group pattern to match a tuple and includes an additional condition on the age. case _: matches any other value not covered by the previous cases. Group patterns are ideal for creating more complex matching scenarios where patterns need to be combined or grouped together. Sequence Patterns\n",
|
||||
"\n",
|
||||
"[5] id=chunk-5 title=10_Execution_model_in_avap\n",
|
||||
" previous cases. Group patterns are ideal for creating more complex matching scenarios where patterns need to be combined or grouped together. Sequence Patterns In AVAP, sequence patterns are used to match elements within sequences like lists or tuples. The syntax for sequence patterns is: sequence_pattern ::= \"[\" [maybe_sequence_pattern] \"]\" | \"(\" [open_sequence_pattern] \")\" Sequence patterns can match elements of sequences based on specific rules. Here’s how they work: List Patterns: Use square brackets [ ] to match lists. You can include patterns for the elements within the list. case [a, b, c]: print(\"Matched a list with three elements\") Tuple Patterns: Use parentheses ( ) to match tuples. Similarly, you can specify patterns for the tuple elements. case (x, y): print(\"Matched a tuple with two elements\") Sequence patterns allow for flexible and powerful matching of sequence types. They can match sequences of various lengths and structures by defining the pattern for each element. Here’s an example of using sequence patterns in a match statement: match value: case [1, 2, 3]: print(\"Matched a list with elements 1, 2, 3\") case (a, b, c) if a + b == c: print(\"Matched a tuple where a + b equals c\") case _: print(\"Matched something else\") In this example: case [1, 2, 3]: matches a list with exactly the elements 1, 2, and 3. case (a, b, c) if a + b == c: matches a tuple and includes a condition to check if a + b equals c. case _: matches any other value not covered by the previous cases. Mapping Patterns In AVAP, mapping patterns are used to match mapping elements, such as dictionaries. Here is the syntax and behavior of mapping patterns: mapping_pattern ::= { [items_pattern] } Mapping Patterns are designed to match elements within mappings, such as dictionaries. They use specific rules to determine if a pattern matches the given mapping. Syntax: Mapping patterns are enclosed in curly braces { ... }. The items_pattern specifies the pattern for the mapping items. Matching Rules: The rules for matching mapping patterns include checking for key-value pairs in the mapping and ensuring they align with the specified pattern. Usage: Mapping patterns are useful for destructuring dictionaries and other mapping types in a concise manner. Mapping patterns enhance pattern matching capabilities by allowing for specific and flexible matching of dictionary elements\n",
|
||||
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
||||
"\n",
|
||||
"Vertical farming proposes growing food in multi-level urban structures. This technique aims to reduce transportation dependency and optimize space usage in densely populated cities. Through hydroponic systems and automated nutrient control, plants can grow without traditional soil. Distributed sensors monitor humidity, temperature, and nutrient levels in real time. Moreover, integration with renewable energy allows these facilities to operate more sustainably.\n",
|
||||
"AVAP has several reserved words that are essential for building APIs, such as \"Endpoint,\" \"Method,\" \"Parameters,\" \"Headers,\" \"Body,\" \"Response Status Codes,\" and others. These keywords provide a standardized language to define the structure and behavior of APIs, making it easier to create, understand, and document them effectively.\n",
|
||||
"\n",
|
||||
"Some cases, agricultural buildings are architecturally designed to integrate seamlessly into the urban environment. Although it still faces economic challenges, vertical farming represents a potential solution for food security in megacities.\n"
|
||||
"Here is an example of using some of these reserved words in AVAP:\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"# Example API endpoint with parameters\n",
|
||||
"endpoint = \"/api/v1/search\"\n",
|
||||
"\n",
|
||||
"parameters = {\n",
|
||||
" \"query\": \"keyword\",\n",
|
||||
" \"sort_by\": \"relevance\"\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"headers = {\n",
|
||||
" \"Authorization\": \"Bearer YOUR_ACCESS_TOKEN\"\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"response_status_code = 200\n",
|
||||
"\n",
|
||||
"body = {}\n",
|
||||
"\n",
|
||||
"try:\n",
|
||||
" # Making a POST request to the API endpoint\n",
|
||||
" response = requests.post(endpoint, params=parameters, headers=headers)\n",
|
||||
" \n",
|
||||
"except Exception as e:\n",
|
||||
" print(f\"An error occurred: {e}\")\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"In this example:\n",
|
||||
"\n",
|
||||
"- `Endpoint` is used for defining the specific URL or path where an API can be accessed.\n",
|
||||
"- `Parameters` contain inputs sent along with a request. These parameters are key-value pairs that specify what data needs to be included in the request body.\n",
|
||||
"- `Headers` include additional information about a message beyond its body content, such as authentication tokens or other metadata needed for authorization.\n",
|
||||
"- `Body` is the actual data being processed in an API call.\n",
|
||||
"\n",
|
||||
"By using these reserved words and their specific meanings within AVAP, developers can ensure that their APIs are both structured correctly and documented comprehensively. This makes it easier for users to interact with the API endpoints as intended, and ensures that any potential errors or issues can be quickly identified and resolved.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue