-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from fractalego/index-cache
Index cache
- Loading branch information
Showing
51 changed files
with
490 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Modify the original prompt | ||
========================== | ||
|
||
The prompt is stored in the file "main.prompt" in the project's root directory. | ||
The name of the file can be changed in the `config.json` file. | ||
The default is: | ||
|
||
|
||
.. code-block:: text | ||
A user is chatting with a bot. The chat is happening through a web interface. The user is typing the messages and the bot is replying. | ||
This is summary of the bot's knowledge: | ||
{facts} | ||
The rules that *must* be followed are: | ||
{rules} | ||
Create a plausible dialogue based on the aforementioned summary and rules. | ||
Do not repeat yourself. Be friendly but not too servile. | ||
Follow the rules if present and they apply to the dialogue. Do not improvise if rules are present. | ||
The variables `{facts}` and `{rules}` are replaced by the actual facts and rules when the prompt is generated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
paths: | ||
- files_to_index/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
A user is chatting with a bot. The chat is happening through a web interface. The user is typing the messages and the bot is replying. | ||
|
||
This is summary of the bot's knowledge: | ||
{facts} | ||
|
||
The rules that *must* be followed are: | ||
{rules} | ||
|
||
Create a plausible dialogue based on the aforementioned summary and rules. | ||
Do not repeat yourself. Be friendly but not too servile. | ||
Follow the rules if present and they apply to the dialogue. Do not improvise if rules are present. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import asyncio | ||
import os | ||
import yaml | ||
|
||
from unittest import TestCase | ||
|
||
from wafl.config import Configuration | ||
from wafl.dataclasses.dataclasses import Query | ||
from wafl.knowledge.indexing_implementation import add_to_index, load_knowledge | ||
|
||
_path = os.path.dirname(__file__) | ||
|
||
|
||
class TestIndexing(TestCase): | ||
def test__path_can_be_added_to_index(self): | ||
data = _load_index() | ||
prior_count = len(data["paths"]) | ||
add_to_index("files_to_index2") | ||
|
||
data = _load_index() | ||
current_count = len(data["paths"]) | ||
self.assertEqual(current_count, prior_count + 1) | ||
|
||
data["paths"].remove("files_to_index2") | ||
with open("indices.yaml", "w") as file: | ||
file.write(yaml.dump(data)) | ||
|
||
def test__indexed_files_can_be_retrieved(self): | ||
config = Configuration.load_local_config() | ||
knowledge = asyncio.run(load_knowledge(config)) | ||
results = asyncio.run( | ||
knowledge.ask_for_facts(Query.create_from_text("How do I start WAFL")) | ||
) | ||
expected = "WAFL" | ||
self.assertIn(expected, results[0].text) | ||
|
||
def test__pdf_can_be_read(self): | ||
config = Configuration.load_local_config() | ||
knowledge = asyncio.run(load_knowledge(config)) | ||
results = asyncio.run( | ||
knowledge.ask_for_facts(Query.create_from_text("What color is the sky?")) | ||
) | ||
expected = "green" | ||
self.assertIn(expected, results[0].text) | ||
|
||
|
||
def _load_index(): | ||
with open("indices.yaml", "r") as file: | ||
return yaml.safe_load(file.read()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.