neue version
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.env
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import openai
|
from openai import OpenAI
|
||||||
from tkinter import simpledialog, Tk, Label, Entry, Button, Text, filedialog
|
from tkinter import simpledialog, Tk, Label, Entry, Button, Text, filedialog
|
||||||
|
from dotenv import load_dotenv
|
||||||
# Set your OpenAI API key here
|
|
||||||
openai.api_key = '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'
|
|
||||||
|
|
||||||
def get_user_input():
|
def get_user_input():
|
||||||
root = None # No parent window for simplicity
|
root = None # No parent window for simplicity
|
||||||
@@ -21,18 +19,20 @@ def list_files(directory):
|
|||||||
return files
|
return files
|
||||||
|
|
||||||
def compare_with_openai(content, search_query):
|
def compare_with_openai(content, search_query):
|
||||||
response = openai.Completion.create(
|
client = OpenAI(
|
||||||
engine="text-davinci-003",
|
api_key=os.environ.get("OPENAI_API_KEY")
|
||||||
prompt=f"Vergleiche den folgenden Text mit der Suchanfrage '{search_query}':\n\n{content[:1000]}...\n\nIst der Text relevant für die Suchanfrage?",
|
)
|
||||||
max_tokens=50,
|
chat_completion = client.chat.completions.create(
|
||||||
n=1,
|
messages=[
|
||||||
stop=None,
|
{
|
||||||
temperature=0.5,
|
"role": "user",
|
||||||
)
|
"content": f"Vergleiche den folgenden Text mit der Suchanfrage '{search_query}':\n\n{content[:1000]}...\n\nIst der Text relevant für die Suchanfrage?"},
|
||||||
return "ja" in response.choices[0].text.lower()
|
],
|
||||||
|
model="gpt-4o-mini",
|
||||||
|
)
|
||||||
|
return "ja" in chat_completion.choices[0].message.content.lower()
|
||||||
def search_files():
|
def search_files():
|
||||||
search_query = get_user_input()
|
search_query = query_entry.get() # Get the search query from the Entry widget
|
||||||
if not search_query:
|
if not search_query:
|
||||||
print("No search query provided.")
|
print("No search query provided.")
|
||||||
return
|
return
|
||||||
@@ -50,13 +50,13 @@ def search_files():
|
|||||||
found_files = []
|
found_files = []
|
||||||
|
|
||||||
for file_path in files:
|
for file_path in files:
|
||||||
try:
|
try:
|
||||||
with open(file_path, 'r', encoding='utf-8', errors='ignore') as file:
|
with open(file_path, 'r', encoding='utf-8', errors='ignore') as file:
|
||||||
file_content = file.read()
|
file_content = file.read()
|
||||||
if compare_with_openai(file_content, search_query):
|
if compare_with_openai(file_content, search_query):
|
||||||
found_files.append(file_path)
|
found_files.append(file_path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error reading {file_path}: {e}")
|
print(f"Error reading {file_path}: {e}")
|
||||||
|
|
||||||
result_text.delete(1.0, 'end')
|
result_text.delete(1.0, 'end')
|
||||||
if found_files:
|
if found_files:
|
||||||
|
|||||||
Reference in New Issue
Block a user