File upload and acting on it in an assistant (v2) conversation

The only reason you wouldn’t get back an uploaded file in the list is if you had more than 10000 already uploaded. Or the changing implementation of projects and their effects on endpoints. You’d know if over 10k because of how long your code took.

I suspect you can go the opposite direction for scoping:

  • reuse the same openai client for every API interaction
  • do not set parameters on the client instantiation - let it use it’s own grabbing of environment variables.
  • Set all environment variables with project matching API key project:
    Client automatically infers the following arguments from their corresponding environment variables if they are not provided:
    - api_key from OPENAI_API_KEY
    - organization from OPENAI_ORG_ID
    - project from OPENAI_PROJECT_ID

I was typing this up to show the nesting needed for turning on code interpreter along with other tools in the same object for tools, then got annoyed…


Create assistant

POST https://api.openai.com/v1/assistants

Create an assistant with a model and instructions.

Request body

  • model - string [required] - ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them.
  • name - string or null [optional] - The name of the assistant. The maximum length is 256 characters.
  • description - string or null [optional] - The description of the assistant. The maximum length is 512 characters.
  • instructions - string or null [optional] - The system instructions that the assistant uses. The maximum length is 256,000 characters.
  • tools - array [optional] - A list of tools enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types code_interpreter, file_search, or function.
    • type - string [required] - The type of tool being defined: code_interpreter.
    • type - string [required] - The type of tool being defined: file_search.
    • file_search - object [optional] - Overrides for the file search tool.
      • max_num_results - integer [optional] - The maximum number of results the file search tool should output. The default is 20 for gpt-4* models and 5 for gpt-3.5-turbo. This number should be between 1 and 50 inclusive.
    • type - string [required] - The type of tool being defined: file_search.
    • function - object [required]
      • description - string [optional] - A description of what the function does, used by the model to choose when and how to call the function.
      • name - string [required] - The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
      • parameters - object [optional] - The parameters the functions accepts, described as a JSON Schema object. See the guide for examples, and the JSON Schema reference for documentation about the format.
  • tool_resources - object or null [optional] - A set of resources that are used by the assistant’s tools. The resources are specific to the type of tool.
    • code_interpreter - object [optional]
      • file_ids - array [optional] - A list of file IDs made available to the code_interpreter tool. There can be a maximum of 20 files associated with the tool.
    • file_search - object [optional]
      • vector_store_ids - array [optional] - The vector store attached to this assistant. There can be a maximum of 1 vector store attached to the assistant.
      • vector_stores - array [optional] - A helper to create a vector store with file_ids and attach it to this assistant. There can be a maximum of 1 vector store attached to the assistant.
        • file_ids - array [optional] - A list of file IDs to add to the vector store. There can be a maximum of 10000 files in a vector store.
        • chunking_strategy - object [optional] - The chunking strategy used to chunk the file(s). If not set, will use the auto strategy.
          • type - string [required] - Always auto. OR
          • type - string [required] - Always static.
            • static - object [required]
              • max_chunk_size_tokens - integer [required] - The maximum number of tokens in each chunk. The default value is 800. The minimum value is 100 and the maximum value is 4096.
              • chunk_overlap_tokens - integer [required] - The number of tokens that overlap between chunks. The default value is 400. Note that the overlap must not exceed half of max_chunk_size_tokens.
        • metadata - map [optional] - Set of 16 key-value pairs that can be attached to a vector store. This can be useful for storing additional information about the vector store in a structured format. Keys can be a maximum of 64 characters long and values can be a maximum of 512 characters long.