A openai api agent module with semantic DB, SQL, and web scraping tools.
Project description
Usage: noahs_openai_agent
This library wraps interactions with a local Ollama server and provides tools for:
- Maintaining a conversation history
- Calling a local LLM via the Ollama REST API
- Performing semantic text splitting and search
- Running local SQL-style lookups
- Extracting and analyzing URLs from text
Getting Started
First, install the library:
pip install noahs_openai_agent
from noahs_openai_agent import ChatAgent
# 1. initialize agent
OPENAI_API_KEY = "YOUR_OPENAI_API_KEY_HERE"
agent = ChatAgent(name="Tomatio", api_key=OPENAI_API_KEY)
# 2. (optional) purge semantic database for fresh start
agent.semantic_db.purge_collection();
# 3. upload txt document of your choosing in chunks of 5 sentences to the semantic database
doc_name = "docs/AliceInWonderland.txt"
agent.upload_document(doc_name, max_sentences_per_chunk=5)
# 4. do a semantic search for 5 relevent passages to a semantic_query and add it to the context window of the agent
semantic_query = "Interactions between Alice and the Mad Hatter"
semantic_contextualize_prompt = f"These are some passages from {doc_name} that should be considered"
agent.discuss_document(semantic_query, doc_name="AliceInWonderland.txt", semantic_top_k=5, semantic_contextualize_prompt=semantic_contextualize_prompt)
# 5. start the chat with a question about the uploaded content.
message = "Tell me about the relationship between Alice and the Mad Hatter. Use examples from the provided passages"
response_stream = agent.chat(message)
print("\n")
print(f"You: {message}")
print(agent.name, end=": ")
agent.print_stream(response_stream)
print("\n")
print("Continue to basic chat...")
print("\n")
while message not in ["bye","goodbye","exit","quit"]:
message = input("You: ")
response_stream = agent.chat(message)
print(agent.name, end=": ")
agent.print_stream(response_stream)
print("\n")
Check out Source Code
https://github.com/jonesnoah45010/openai_agent
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
noahs_openai_agent-0.1.1.tar.gz
(13.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file noahs_openai_agent-0.1.1.tar.gz.
File metadata
- Download URL: noahs_openai_agent-0.1.1.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
869cfc36a11e81112f2cd9419c868932c9bd0f9408219cd73237f0171fad8f98
|
|
| MD5 |
bca0f9148a3f98b509d1d36b5e2254ed
|
|
| BLAKE2b-256 |
6942f2c1ea5b7509b98c8f9fc4c10fbb0b8d2bed5b0c15068a2dd705b66f5cfb
|
File details
Details for the file noahs_openai_agent-0.1.1-py3-none-any.whl.
File metadata
- Download URL: noahs_openai_agent-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0e78d5ba779f42908cefd2847f9e4b5dd4fd7a297f1e7cf08ba6ea25bea627b
|
|
| MD5 |
0c2aa4c4b4cea9a171ecaf06fe42da91
|
|
| BLAKE2b-256 |
3e66beef82166e5e5a6cb887ed2ef61f5b003181be9d14360236d048692257e5
|