I started getting this error today with a function that invokes another function. The function is in a separate class. IE Class B invokes function in Class A. Both functions are decorated with a query function decorator.
SafeError: Attempted to execute a Query that was not declared as used. Annotate your Function with the `@Uses` decorator from `@foundry/functions-api`.
However @Uses is not in my version of the @foundry/functions-api package. It appears you have once again made changes to a backend service that is not compatible with previous versions of functions. If this is the case I implore you to stop making breaking changes! Implement a builder pattern in your service backends so the correct version of services and their behaviors are mapped to the appropriate version of functions. If this is not the case, I apologize for the frustrated comment.
Regardless, is the path here to upgrade my repo and use the @Uses decorator for all functions that invoke another function?
This error has always been thrown if our static analysis of your code misses the usage of a given query (note: this is only applied to queries called via the Queries syntax, not to functions called within the same repository). We recently updated the message to provide instructions to remediate. However, that remediation (the @Uses decorator you mentioned) was released in @foundry/functions-api:0.110.0. Are you able to upgrade to that version of the @foundry/functions-api package by upgrading your repository?
When you want to consume a read-only Function from another repository, you can import it from the sidebar as a Query. The documentation on this feature can be found here. The error you are encountering occurs when our static analysis of queries that your function calls is inaccurate.
My previous answer might’ve been confusing because I did not mention that language models are also Queries, though they are presented as a separate section in the UI.
You must annotate the entry-point published Function (not any local helper functions it invokes) with the @Uses decorator if this occurs. The declared usage in both the decorator and our static analysis are then combined to form a set of queries which can be invoked at runtime, and we enforce this provenance is accurate.
I think the following example may most closely approximate your usage:
import { Function, Uses } from "@foundry/functions-api";
import { LanguageModels } from "@foundry/models-api";
@Function()
@Uses({ queries: [LanguageModels.TextEmbeddingAda_002.createEmbeddings] })
public async fooA(): string {
const res = await fooB();
return res;
}
private async fooB(): string {
// invoke and return data from LanguageModels.TextEmbeddingAda_002.createEmbeddings
}
Documentation for this new decorator will be released very soon.
I’d be happy to provide a more specific answer for your use case if you could provide some rough pseudo-code, especially including where language models and/or queries are called from the TypeScript code.
And the error goes away. TY! But why do I have to do this in the first place? Ideally all annotations go away. Thanks for your help and have a great weekend Jett.