Skip to content

Commit

Permalink
0.31 (#62)
Browse files Browse the repository at this point in the history
* build system improvemts

* default parameters working

* cleanup dependencies

* cleanup stuff

* add search ui

* cleanup github sites

* read stdin working

* apply black

* cleanup entry generator

* cleanups

* selection of running item worked

* ui did the job

* use lazy evaluation

* improvements

* add desert theme

* improvements

* foo

* theme improvements

* test

* wip

* test

* cleanup code

* lazy bm25 working

* cleanups

* foo

* remove unsued code

* add cleanup script

* ui improvements

* improvments

* replace

* add poetry

* fix poetry

* poetry
  • Loading branch information
jeanCarloMachado authored Feb 24, 2024
1 parent 9f0b783 commit 57a1e7e
Show file tree
Hide file tree
Showing 85 changed files with 673 additions and 985 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN_NEW }}
run: |
pip install poetry
curl -sSL https://install.python-poetry.org | python3 -
poetry config virtualenvs.create false
poetry build
echo "Publishing now..."
Expand Down
41 changes: 0 additions & 41 deletions .github/workflows/static.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: |
sudo apt update -y
sudo apt install gnome-keyring curl
curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.4.2 python3 -
curl -sSL https://install.python-poetry.org | python3 -
poetry --version
poetry config --local virtualenvs.create true
poetry install
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.31 - 2024-01-27

- Replce fzf with a python native logic.
- Cleanup github sites.
- Cleanup tons of files

## 0.28 - 2023-11-02

- Performance improvements
Expand Down
8 changes: 8 additions & 0 deletions cleanup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os


os.system("rm -rf dist/*")
os.system("rm -rf __pycache__")
os.system("rm -rf .mypy_cache")

os.system("black . ")
27 changes: 0 additions & 27 deletions container/setup.sh

This file was deleted.

2 changes: 0 additions & 2 deletions end2endtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@


class End2End:
""" """

def run(self):
self.cleanup()
self._run_shell(
Expand Down
30 changes: 29 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "python-search"
version = "0.30.0"
version = "0.31"
description = "Build your knowledge database in python and retrieve it efficiently"
authors = ["Jean Carlo Machado <[email protected]>"]

Expand All @@ -26,6 +26,7 @@ openai = {version=">=0.27.0"}
python-dateutil = "^2.8.2"
chardet = "^5.1.0"
colorful = "^0.5.5"
openapi = "^1.1.0"

[tool.poetry.dev-dependencies]
pytest = "^7.1.2"
Expand Down Expand Up @@ -69,6 +70,7 @@ aps_webapi = 'python_search.sdk.web_api_sdk:main'
wrap_log_command = {reference = "wrap_log_command.sh", type = "file", extras = []}
events_etl = 'python_search.events.events_etl:main'
chat_gpt = 'python_search.chat_gpt:main'
term_ui = 'python_search.search_ui.terminal_ui:main'
entry_builder = 'python_search.entry_capture.entry_inserter_gui.entry_inserter_gui:main'
prompt_editor = 'python_search.apps.prompt_editor:main'
entry_embeddings = 'python_search.next_item_predictor.features.entry_embeddings:main'
Expand Down
Binary file modified python_search/.DS_Store
Binary file not shown.
10 changes: 10 additions & 0 deletions python_search/PythonSearch.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"folders": [
{
"path": ".."
},
{
"path": "../../PySearchEntries"
}
]
}
20 changes: 10 additions & 10 deletions python_search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
os.environ["NUMEXPR_MAX_THREADS"] = "10"
os.environ["PYTORCH_MPS_HIGH_WATERMARK_RATIO"] = "0.0"

os.environ['DD_SERVICE'] = 'python-search'
os.environ['DD_ENV'] = 'local'
os.environ['DD_LOGS_INJECTION'] = 'true'
os.environ['DD_PROFILING_ENABLED'] = 'true'
#os.environ['DD_TRACE_DEBUG'] = 'true'
os.environ["DD_SERVICE"] = "python-search"
os.environ["DD_ENV"] = "local"
os.environ["DD_LOGS_INJECTION"] = "true"
os.environ["DD_PROFILING_ENABLED"] = "true"
# os.environ['DD_TRACE_DEBUG'] = 'true'

#from ddtrace.profiling import Profiler
#import sys
#prof = Profiler(
# from ddtrace.profiling import Profiler
# import sys
# prof = Profiler(
# env="local", # if not specified, falls back to environment variable DD_ENV
# service="python_search", # if not specified, falls back to environment variable DD_SERVICE
# version=str(sys.argv[0]), # if not specified, falls back to environment variable DD_VERSION
# tags={'entrypoint': sys.argv[0]},
#)
#prof.start()
# )
# prof.start()
8 changes: 4 additions & 4 deletions python_search/apps/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from python_search.apps.notification_ui import send_notification



class Browser:
"""
Abstracts the browser features cross-platform
Expand Down Expand Up @@ -40,7 +39,9 @@ def open(
focus_title: to focus on a window that behaves like an app
"""
cmd_to_run = self.open_shell_cmd(url, app_mode, incognito, browser, focus_title=focus_title)
cmd_to_run = self.open_shell_cmd(
url, app_mode, incognito, browser, focus_title=focus_title
)
print("Command to run:", cmd_to_run)
self.system_func(cmd_to_run)

Expand All @@ -56,13 +57,12 @@ def open_shell_cmd(
Returns the shell command to open the browser
"""


self._focus_title = focus_title
self._app_mode = app_mode


if self._focus_title:
from python_search.host_system.windows_focus import Focus

if Focus().focus_window("Google Chrome", self._focus_title):
print("Chrome window focused instead of opening new")
sys.exit(0)
Expand Down
1 change: 1 addition & 0 deletions python_search/apps/notification_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def send_notification(message: str):
cmd = f"""osascript -e 'display notification "{clean}"'"""

from subprocess import Popen

Popen(cmd, shell=True, stdin=None, stdout=None, stderr=None, close_fds=True)


Expand Down
8 changes: 0 additions & 8 deletions python_search/apps/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,3 @@ def wrap_cmd_into_terminal(
final_cmd = f'{get_kitty_cmd()} {hold} {Terminal.GENERIC_TERMINAL_PARAMS} -T "{title}" {cmd} '

return final_cmd

def get_background_color(self):

if self.configuration.get_fzf_theme() in ["dracula", "dark"]:
return " -o background=#282a36 -o foreground=#ffffff "

theme = self.configuration.get_theme_object()
return f" -o background={theme.background} -o foreground={theme.foreground} "
1 change: 0 additions & 1 deletion python_search/apps/window_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ def hide_window(self, title):
return 0 == os.system(f"xdotool search --name '{title}' windowminimize")

raise Exception("Window manager not supported")

35 changes: 5 additions & 30 deletions python_search/chat_gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ def answer(self, prompt: str, debug=False, max_tokens=500, model=None) -> str:
return PythonSearchChatGPTAPI().prompt(prompt)

import openai
from openai import OpenAI

client = OpenAI(api_key=os.environ["OPENAI_KEY"])

openai.api_key = os.environ["OPENAI_KEY"]
# Set the maximum number of tokens to generate in the response

if debug:
Expand All @@ -92,7 +94,7 @@ def answer(self, prompt: str, debug=False, max_tokens=500, model=None) -> str:
try:
# print("Open AI Key used: ", openai.api_key)
# Generate a response
completion = openai.Completion.create(
completion = client.completions.create(
model=model,
engine=engine,
prompt=prompt,
Expand All @@ -103,7 +105,7 @@ def answer(self, prompt: str, debug=False, max_tokens=500, model=None) -> str:
presence_penalty=0,
)
return completion.choices[0].text.strip()
except openai.error.RateLimitError as e:
except openai.RateLimitError as e:
print(str(e))
from python_search.apps.notification_ui import send_notification

Expand All @@ -117,33 +119,6 @@ def print_answer(self, prompt):
print(self.answer(prompt))


class PythonSearchChatGPTAPI:
def prompt(self, text) -> str:
import openai

openai.api_key = os.environ["OPENAI_KEY"]
# print("Open AI Key used: ", openai.api_key)

try:
result = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": text},
],
)
return result.choices[0].message.content

except openai.error.RateLimitError as e:
print(str(e))
from python_search.apps.notification_ui import send_notification

send_notification(str(e))
return ""

return ""


def main():
import fire

Expand Down
Loading

0 comments on commit 57a1e7e

Please sign in to comment.