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.0.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.0.tar.gz.
File metadata
- Download URL: noahs_openai_agent-0.1.0.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 |
e7fea449ef976d3cc76f44d99f704e422d06fc618c460af6a7ed51b5b4d09660
|
|
| MD5 |
1925121aa4ce2663d14b0c51d64f154a
|
|
| BLAKE2b-256 |
161d1041491f7c9fe28c1227e8eef087a05192e7326a9ec6c149ecbe01dbd0b1
|
File details
Details for the file noahs_openai_agent-0.1.0-py3-none-any.whl.
File metadata
- Download URL: noahs_openai_agent-0.1.0-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 |
4f0f8bc5d5f529d8d90af0ecafe94fbba80cdbddaff7eaa28b5fa629d7a934e7
|
|
| MD5 |
7992701394794f75f955908faa6a3878
|
|
| BLAKE2b-256 |
7a7e121eab424e45b2a6039251d3d60b5a75936511a24fc1bb541914a65da3ac
|