Download the PHP package hiddenhatpress/openai-assistants without Composer

On this page you can find all versions of the php package hiddenhatpress/openai-assistants. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package openai-assistants

openai-assistants

A quick and dirty client for OpenAI's assistants API.

NOTE

Although this package is still maintained for now (I'm using it in Shelley), the Assistants API is now included in the full OpenAI Client at orhanerday/open-ai. You might want to use that for a much wider feature set. This library plugged a gap that has now been filled. That said, read on for a worked example of file retrieval with the OpenAI Assistants API.

OpenAI API docs

Installation

The easiest way to get this code is via Composer:

Overview

The Assistants class is really only a factory for objects which provide thin client access to the assistant, thread. messages and runs APIs.

Quick start

The basic workflow for the Assistants API is:

  1. Create an assistant
  2. Optionally add files to the assistant
  3. Create a thread (so that different users can use the assistant through your interface)
  4. Create a message representing a user's query and add it to thread
  5. Run the thread
  6. Poll the status of the the run until its status is completed
  7. Get the latest message (the system's response) from the thread and return to the user
  8. Repeat from step 4 as needed

We're going to create an assistant to help us read the letters of Pliny the Younger.

Access assistants

First, let's check that we haven't already created an assistant named pliny-assistant:

NOTE because the list endpoint returns 20 elements by default, this approach would not scale if you had more than 20 asssistants. In a robust system you'd likely have stored an assistant id. If you wanted to create a reliable version of this dynamic name-based logic you'd need to page through the data. list() supports limit -- up to 100 -- as well as before and after fields.

Create an assistant and upload a file

For a first run, we'll need to actually create the assistant and upload a source file (the text version of Pliny's letters saved as pliny.txt).

The arguments to create() are a name, a set of instructions, and a list of tool types. These can be code_interpreter, retrieval, or function. We are creating a retrieval assistant -- that is, an assistant specialised in working with texts we provide. We're giving it a historical text -- but the assistant would likely come into its own interpreting files that the model has not already been trained on -- a novel-in-progress perhaps, or corporate documents.

The AssistantFile class accesses the file aspect of the assistants API and the File API. So createAndAssignAssistantFile() uploads a given file and then associates it with an assistant.

Now we have an assistant with access to the text we are interested in. Let's try asking it a question.

Setting up a message for running

In order to send a message we need to create a thread and add a message to it.

Running the thread to send the message

Next, we need to tell the API to run the thread. We use the runs API for this.

Because the service does not block, we need to poll it until it the run status is completed.

Accessing the latest message from the thread

We can list the messages using the messages API.

By default, messages are returned in descending order, so the first element will be the latest.

Some output

Let's run the code and get some ancient fish news.

Pliny the Younger mentioned fish in the context of his letters to highlight certain aspects or qualities of his environment or surroundings:

  1. He discusses the offerings of his local sea and expresses a somewhat limited pride in its bounty. He says, "I cannot boast that our sea is plentiful in choice fish" but then goes on to recognize that it does provide for "capital soles and prawns." This indicates a modest abundance of certain kinds of fish, and he contrasts this with the abundant provisions of other types, such as milk, which he proudly notes his villa's ability to excel in even when compared to inland places【7†source】.

...

Tidying up: unassign and delete assistant files

In real world code, we would not usually build an assistant only to tear it down again at the end of our process. We'd be more likely to establish an assistant and use it over time, creating new threads for new users. These threads might also persist for some time.

Here, however, we want to leave things as we found them. First, let's delete the file we uploaded.

We can get an assistant's file ids from the assistants API. In this example, we have access to this data already, but let's assume we only have an assistant id to hand.

AssistantFiles::listAssistantFiles() gives us an array of associated files. We can use the id field of each with unassignAndDeleteAssistantFile() to remove the association between assistant and file and then delete the file from the repository.

Tidying up: delete the assistant

Finally, we delete the assistant altogether.


All versions of openai-assistants with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hiddenhatpress/openai-assistants contains the following files

Loading the files please wait ....