TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Auto-debugging Python code with GPT4

3 pointsby andybar007about 2 years ago

2 comments

andybar007about 2 years ago
AutoDebug Python is an open-source tool that leverages the power of GPT-4 to automatically debug and fix Python scripts.<p>Just put in your API Key and the url of your .py and you’re ready to go.<p>Would love to get your feedback as I can’t code and built this with the help of GPT4.<p>Thanks everyone! :)
check35about 2 years ago
#%%<p>&quot;&quot;&quot;imports&quot;&quot;&quot;<p>&quot;&quot;&quot;Load html from files, clean up, split, ingest into Weaviate.&quot;&quot;&quot; import pickle import sys<p>from langchain.embeddings import OpenAIEmbeddings from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain.vectorstores.faiss import FAISS from langchain.document_loaders.html import UnstructuredHTMLLoader<p>&quot;&quot;&quot;end of imports&quot;&quot;&quot; # %%<p>def ingest_current_page(input_file):<p><pre><code> &quot;&quot;&quot;Get documents from web pages.&quot;&quot;&quot; try: # Load the path to the current_page.html from pathlib import Path doc_path = Path(input_file).absolute() loader = UnstructuredHTMLLoader(doc_path) raw_page = loader.load() print (f&#x27;You have {len(raw_page)} document from the current job application page HTML&#x27;) print (f&#x27;There are {len(raw_page[0].page_content)} characters in your document HTML&#x27;) &quot;&quot;&quot;&quot;text splitting&quot;&quot;&quot; text_splitter = RecursiveCharacterTextSplitter( chunk_size=100, chunk_overlap=0, ) try: if not all(isinstance(doc.page_content, str) for doc in raw_page): raise TypeError(&quot;Error: Input data must be a list of strings&quot;) documents = text_splitter.split_documents(raw_page) texts = text_splitter.split_documents(raw_page) except TypeError as e: print(e) sys.exit(1) print (&#x27;Splitting current page HTML into chunks&#x27;) print (f&#x27;Now you have {len(texts)} HTML chunk documents for current page.&#x27;) embeddings = OpenAIEmbeddings() try: vectorstore = FAISS.from_documents(documents, embeddings) except Exception as e: print(f&quot;Error: Failed to vectorize documents. {e}&quot;) sys.exit(1) print (&#x27;Saving current job application page HTML chunk documents to the vectorstore.pkl file&#x27;) &quot;&quot;&quot;saving vectorstore file&quot;&quot;&quot; # Save vectorstore with open(&quot;vectorstore.pkl&quot;, &quot;wb&quot;) as f: pickle.dump(vectorstore, f) #print that the HTML chunk documents have been saved to the vectorstore print(&quot;HTML chunk documents have been saved to &#x27;vectorstore.pkl&#x27;&quot;) return vectorstore </code></pre> &quot;&quot;&quot;error handling&quot;&quot;&quot;<p><pre><code> except FileNotFoundError: print(f&quot;Error: Could not find file &#x27;{input_file}&#x27;&quot;) sys.exit(1) </code></pre> # %%<p>&quot;&quot;&quot;code execution&quot;&quot;&quot;<p>if __name__ == &quot;__main__&quot;: ingest_current_page()