Skip to main content

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


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.2.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

noahs_openai_agent-0.1.2-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file noahs_openai_agent-0.1.2.tar.gz.

File metadata

  • Download URL: noahs_openai_agent-0.1.2.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for noahs_openai_agent-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6578dd9cd996e36743f5b73a3457dc140dc93a2fcf70c23e4871d14511a9bc11
MD5 93346b5fcbead2af319499d522c34ed6
BLAKE2b-256 ea33a98168ede6875fd71acac53e25917f4e6aced78dd4da252de63ccc1208a4

See more details on using hashes here.

File details

Details for the file noahs_openai_agent-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for noahs_openai_agent-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4f4eb44bc0cf86b650a51c7b2ebb4d61ebaf2013ccb960c7e5b79c61589108a2
MD5 396a1c263c7187ceda4769d582ed79df
BLAKE2b-256 f61bf82e0d8d17e9c0a906ea3fc2ce1bf425d8ed99ba044895b096df6af961da

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page