fix: add runpod id to resource configs after deploy or fetch from state#89
fix: add runpod id to resource configs after deploy or fetch from state#89
Conversation
deanq
left a comment
There was a problem hiding this comment.
This becomes an anti-pattern. Under ServerlessResource class, you'll see that the @property decorated functions check for a self.id before proceeding. The pattern is to make sure the endpoints are either deployed or known to be existing per its id. I saw in your example that what you really needed was a way to generate the open_ai URL for the endpoint via gpu_server_url = f"https://api.runpod.ai/v2/{gpu_serverless_endpoint.id}/openai/v1"
Here's my suggestion then. Under ServerlessResource class, create this property function...
# self.url is already taken for Console URL
@property
def endpoint_url(self) -> str:
base_url = self.endpoint.rp_client.endpoint_url_base
return f"{base_url}/{self.id}"
This could be done cleanly from the SDK itself, but we'll do that when we address the SDK overhaul in the near future.
You can then refer to it by gpu_serverless_endpoint.endpoint_url as
gpu_server_url = f"{gpu_serverless_endpoint.endpoint_url}/openai/v1"
...I'll address your example PR at that repo
|
@deanq I think I misunderstood your original comment. Part of the motivation for this is that the ids (including urls) for resources aren't available via the config objects at runtime. I think that suggestion (and all of those properties) will still throw an error. This happens because the deploy methods for config objects return an endpoint and store it, but don't actually assign any of the endpoint information back to the config object. So even after creating a config object and deploying resources from it we can't access any of the deployed resources from the returned config object. I think what's happening is that in a serverless endpoint we create the runtime endpoint object from the GraphQL client here and then the resource manager stores the object here. But at no point do we assign the example: this will always fail @remote(cpu_live_serverless)
def foo():
return "bar"
await foo()
print(cpu_live_serverless.url) |
This PR makes a small change to
ServerlessEndpointresources and theResourceManagerclasses.Currently, after a resource is created, the class that defines it does not have a persistent identifier for its associated entity in Runpod. For example: