Upload 2 files
Browse files- note_engine.py +21 -0
- prompts.py +26 -0
note_engine.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from llama_index.core.tools import FunctionTool
|
2 |
+
import os
|
3 |
+
|
4 |
+
note_file = os.path.join("data", "notes.txt")
|
5 |
+
|
6 |
+
|
7 |
+
def save_note(note):
|
8 |
+
if not os.path.exists(note_file):
|
9 |
+
open(note_file, "w")
|
10 |
+
|
11 |
+
with open(note_file, "a") as f:
|
12 |
+
f.writelines([note + "\n"])
|
13 |
+
|
14 |
+
return "note saved"
|
15 |
+
|
16 |
+
|
17 |
+
note_engine = FunctionTool.from_defaults(
|
18 |
+
fn=save_note,
|
19 |
+
name="note_saver",
|
20 |
+
description="this tool can save a text based note to a file for the user",
|
21 |
+
)
|
prompts.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from llama_index.core import PromptTemplate
|
2 |
+
|
3 |
+
|
4 |
+
instruction_str = """\
|
5 |
+
1. Convert the query to executable Python code using Pandas.
|
6 |
+
2. The final line of code should be a Python expression that can be called with the `eval()` function.
|
7 |
+
3. The code should represent a solution to the query.
|
8 |
+
4. PRINT ONLY THE EXPRESSION.
|
9 |
+
5. Do not quote the expression."""
|
10 |
+
|
11 |
+
new_prompt = PromptTemplate(
|
12 |
+
"""\
|
13 |
+
You are working with a pandas dataframe in Python.
|
14 |
+
The name of the dataframe is `df`.
|
15 |
+
This is the result of `print(df.head())`:
|
16 |
+
{df_str}
|
17 |
+
|
18 |
+
Follow these instructions:
|
19 |
+
{instruction_str}
|
20 |
+
Query: {query_str}
|
21 |
+
|
22 |
+
Expression: """
|
23 |
+
)
|
24 |
+
|
25 |
+
context = """Purpose: The primary role of this agent is to assist users by providing accurate
|
26 |
+
information about world population statistics and details about a country. """
|