mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-11-10 17:48:43 -10:00
### Why / What / How
**Why:** `ReplicateModelBlock` marks `version` as optional, but it fails
for community models run without a version. With no version, it calls
Replicate's official-model endpoint, `POST
/v1/models/{owner}/{name}/predictions`. Replicate's API spec says that
endpoint is only for [official
models](https://replicate.com/changelog/2025-01-29-official-models), so
a community model such as `cuuupid/glm-4v-9b` gets a 404 "The requested
resource could not be found." The same model works once a version hash
is passed.
**What:** a run with no version still tries the official-model endpoint
first. When that returns 404, the block looks up the model's latest
version and runs that instead. If the model doesn't exist or has no
published version, the block raises a clear input error that names the
model.
**How:** when that endpoint returns 404, the block calls `GET
/v1/models/{owner}/{name}` (`client.models.async_get`). It then runs
`latest_version.id` through the version-based `POST /v1/predictions`.
Official models keep the endpoint they already use and make no extra
request, so their behaviour and billing are unchanged. Errors other than
404, such as a 401, are raised as before and don't trigger the lookup.
### Changes 🏗️
- `backend/blocks/replicate/_helper.py`: adds
`create_unpinned_prediction`, which tries the official-model endpoint
and on a 404 runs the latest version. It raises
`ReplicateModelNotRunnableError` for an unknown model or one with no
published version.
- `backend/blocks/replicate/replicate_block.py`: `run_model` uses the
helper for unpinned refs. `run` maps `ReplicateModelNotRunnableError` to
`BlockInputError`, so the user sees a message that names the model and
says what to do.
- The `version` field description now says what an empty value does:
official models run through Replicate's model endpoint, and community
models run their latest published version.
- `backend/blocks/replicate/replicate_block_version_test.py`: new tests.
They mock Replicate's HTTP with `httpx.MockTransport` and drive the real
Replicate SDK. They cover a community model with no version, an official
model with no version, a pinned version, an unknown model, a model with
no versions, and a non-404 error that must not trigger the lookup.
### Not tested live
No Replicate API key was available, so I could not run a real model. The
fix is verified with mocked HTTP shaped on Replicate's public OpenAPI
spec (`https://api.replicate.com/openapi.json`) and on the model's
public page. The spec says the model predictions endpoint is for
official models only, and that `GET /models/{owner}/{name}` returns
`latest_version` and `is_official`. The public page for
`cuuupid/glm-4v-9b` shows `is_official: false` and a
`latest_version.id`.
**Suggested reviewer check:** if you have a Replicate key, run
`ReplicateModelBlock` with `model_name` `cuuupid/glm-4v-9b` and no
`version`. On dev it returns 404; on this branch it should run the
latest version.
### Checklist 📋
#### For code changes:
- [x] I have clearly listed my changes in the PR description
- [x] I have made a test plan
- [x] I have tested my changes according to the test plan:
- [x] New tests run against dev's block code: 3 of 6 fail with the real
`status: 404 / The requested resource could not be found.` (community
model, unknown model, no versions). The official, pinned and non-404
cases pass on dev too.
- [x] On this branch: 21 of 21 pass for `backend/blocks/replicate/` plus
`test_available_blocks[ReplicateModelBlock]`
- [x] ruff, black, isort and pyright are clean on the changed files
- [ ] Live run of `cuuupid/glm-4v-9b` without a version (needs a
Replicate key, see above)
#### For configuration changes:
- [x] `.env.default` is updated or already compatible with my changes
- [x] `docker-compose.yml` is updated or already compatible with my
changes
- [x] I have included a list of my configuration changes in the PR
description (under **Changes**)
No configuration changes.