pinecone-io / pinecone-python-client

The Pinecone Python client
https://www.pinecone.io/docs
Apache License 2.0
284 stars 78 forks source link

REST code generation for 2024-07 prerelease #361

Closed jhamon closed 2 months ago

jhamon commented 2 months ago

Problem

We need to generate code off of the openapi specs stored in our apis repo. We'll need to massage the output a bit in order to avoid having a lot of confusing duplication of generated exception classes and other utils.

Solution

The script does the following:

The surgery to extract shared code is more than just a cosmetic change, as without it you can end up with a lot of confusion in the areas of configuration and error handling due to there being multiple objects that despite being identical in name and functionality remain distinct from the perspective of language utils such as isinstance, .__class__ and except.

When the script is done running, the generated outputs have this structure:

pinecone/core
└── openapi
    ├── control
    │   ├── api
    │   │   ├── inference_api.py
    │   │   └── manage_indexes_api.py
    │   └── model
    │       ├── __init__.py
    │       ├── create_index_request.py
    │       ├── index_model.py
    │       └── ...etc
    ├── data
    │   ├── api
    │   │   └── data_plane_api.py
    │   └── model
    │       ├── __init__.py
    │       ├── upsert_request.py
    │       ├── vector.py
    │       └── ...etc
    └── shared
        ├── api_client.py
        ├── configuration.py
        ├── exceptions.py
        ├── model_utils.py
        └── rest.py

What actually changed in here?

It seems the main substantive change is in how the spec info is expected to be passed when creating an index. So I had to write some additional tests and make some modifications to the create_index method.

Also, inference-related stuff is currently generated. But for now, all the wrapper implementations for that functionality are only available by installing a separate plugin, pinecone-plugin-inference.

Type of Change

Test Plan

To run the script, run make generate-oas. Before pushing, I ran tests locally with make test-unit and PINECONE_API_KEY='key' make test-integration. This helped me catch a lot of small issues related to the sed rewrite of import paths.

Want to see tests passing even though I changed quite a bit about how the generated code is structured.