Giter VIP home page Giter VIP logo

openai-assistant's Introduction

Document Information Retrieval Assistant using OpenAI GPT-3

This Python script enables interaction with the OpenAI GPT-3 assistant via the OpenAI API to retrieve information from uploaded documents using a vector store.

Prerequisites

Before running the script, ensure you have the following installed:

  • Python 3.x
  • Required Python packages (openai, python-dotenv): Install using pip install openai python-dotenv

Setup

  1. Obtain OpenAI API Key:

    • Sign up for OpenAI and obtain your API key.
    • Set your OpenAI API key in the environment variable OPENAI_API_TOKEN.
  2. Assistant and Vector Store IDs:

    • Replace assistant_id and vs_ID in the script with your specific OpenAI assistant ID and vector store ID.
    • Setup Vector Store:
      • Create or use an existing vector store on OpenAI.
      • Upload documents containing information you want the assistant to retrieve into the vector store.

Usage

  1. Run the Script:

    • Execute the script by running python main.py in your terminal or IDE.
  2. Start Conversation:

    • Upon running, the script will prompt you to enter a message.
    • Type you and press Enter to send it to the OpenAI assistant.
  3. Exit Conversation:

    • To exit the conversation, type exit and press Enter.

Script Details

  • load_openai_assistant(assistant_id, vs_ID): Initializes the OpenAI assistant and creates a new thread for interaction.
  • wait_on_run(run, thread): Waits for the assistant run to complete or progress to the next stage.
  • get_assistant_response(thread, assistant_id, user_input): Sends user input to the assistant and retrieves the response.

Error Handling

  • The script handles API-related errors such as APIError, APIConnectionError, and RateLimitError gracefully.

OpenAI API Documentation

For more details about the OpenAI API and assistants, refer to the OpenAI API Documentation.

Example

$ python your_script_name.py
Welcome! Let's start a conversation with the OpenAI assistant.

You: Hello
Assistant: Hi there! How can I assist you today?

You: Retrieve information from document
Assistant: Please provide specific details or keywords from the document you need information about.

You: exit
Exiting...

openai-assistant's People

Contributors

rp42dev avatar

Watchers

Kostas Georgiou avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.