Skip to content

Commit

Permalink
Merge pull request #121 from mraniki/dev
Browse files Browse the repository at this point in the history
✨ Added chat export feature
  • Loading branch information
mraniki authored Sep 27, 2023
2 parents 01aa4d9 + f06191f commit fbd2186
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 30 deletions.
4 changes: 3 additions & 1 deletion examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ async def main():
time.sleep(10)
chat = await talky.chat("what is my name")
logger.info(chat)
# Your name is Jack, as you mentioned earlier.
# Your name is Jack, as you mentioned earlier

talky.conversation.export_messages()


app = FastAPI()
Expand Down
30 changes: 30 additions & 0 deletions history.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"role": "user",
"content": "You are a friendly AI, helping me with \ngeneral tasks.\n"
},
{
"role": "user",
"content": "My name is Jack"
},
{
"role": "ai",
"content": "Hello Jack, this is Bing. Nice to meet you. \ud83d\ude0a"
},
{
"role": "user",
"content": "tell me who is president of the united states?"
},
{
"role": "ai",
"content": "[1]: https://simple.wikipedia.org/wiki/President_of_the_United_States \"President of the United States - Simple English Wikipedia, the free ...\"\n[2]: https://www.history.com/topics/us-presidents/joe-biden \"Joe Biden: Age, Presidency, Family - HISTORY\"\n[3]: https://www.whitehouse.gov/about-the-white-house/presidents/barack-obama/ \"Barack Obama | The White House\"\n[4]: https://en.wikipedia.org/wiki/List_of_Presidents_of_the_United_States \"List of presidents of the United States - Wikipedia\"\n[5]: https://www.whitehouse.gov/about-the-white-house/presidents/ \"Presidents | The White House\"\n[6]: https://www.britannica.com/topic/Presidents-of-the-United-States-1846696 \"list of presidents of the United States - Encyclopedia Britannica\"\n\nThe current president of the United States is **Joe Biden**, who took office in January 2021[^1^][1] [^2^][2]. He is the 46th president of the United States[^3^][4] [^4^][5]. Do you want to know more about him or any other president?"
},
{
"role": "user",
"content": "what is my name"
},
{
"role": "ai",
"content": "You told me your name is Jack. Is that correct?"
}
]
27 changes: 2 additions & 25 deletions myllm/default_settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,9 @@ llm_ai_mode = false
# template prompt context
# not implemented
llm_template = """
You are a friendly AI, helping me with task
You are a friendly AI, helping me with
general tasks.
"""
# llm_template = """
# You operate within the following constraints:
# Your task is to devise up to 5 highly effective goals
# and an appropriate role-based name (_GPT)
# for an autonomous agent, ensuring that the goals
# are optimally aligned with the successful
# completion of its assigned task.

# The user will provide the task,
# you will provide only the output
# in the exact format specified below
# with no explanation or conversation.

# Example input:
# Help me with a trading monitoring for EURUSD

# Example output:
# - Query current trend via /trend
# - Access realtime data via /indicator
# - Query news via /news
# - Advise on a low timeframe and high timeframe trading positioning
# - Place an order if suitable and wait for user confirmation

# """

########################################
### END OF DEFAULT SETTINGS ###
Expand Down
7 changes: 6 additions & 1 deletion myllm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import importlib
import json
from time import sleep

from g4f import Provider
Expand Down Expand Up @@ -95,7 +96,7 @@ async def chat(self, prompt):
return f"{settings.llm_prefix} {response}"
except Exception as error:
logger.error("No response from the model {}", error)
return f"{settings.llm_prefix} No response from the model"
# return f"{settings.llm_prefix} No response from the model"

async def clear_chat_history(self):
"""
Expand Down Expand Up @@ -123,3 +124,7 @@ def add_message(self, role: str, content: str):

def get_messages(self):
return self.messages

def export_messages(self):
with open("history.json", "w") as f:
json.dump(self.messages, f, indent=4)
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,16 @@ omit = [
"docs/*",
"*/config.py"
]


[tool.semantic_release]
upload_to_vcs_release = true
version_variables = ["pyproject.toml:version","myllm/__init__.py:__version__"]
version_variables = ["myllm/__init__.py:__version__"]
build_command = "pip install poetry && poetry build"
commit_parser = "emoji"

version_toml = [
"pyproject.toml:tool.poetry.version",
]

[tool.semantic_release.commit_parser_options]
major_tags = [
Expand Down
6 changes: 6 additions & 0 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ async def test_get_myllm_info(talky):
assert "ℹ️" in result


@pytest.mark.asyncio
async def test_clear_chat_history(talky):
history = talky.conversation.export_messages()
assert history is not None


@pytest.mark.asyncio
async def test_clear_chat_history(talky):
await talky.clear_chat_history()
Expand Down

0 comments on commit fbd2186

Please sign in to comment.