Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate getLogs method from Ai binding #2044

Merged
merged 1 commit into from
Apr 25, 2024

Conversation

G4brym
Copy link
Member

@G4brym G4brym commented Apr 22, 2024

This was a testing method added to debug the Ai binding, and is now being deprecated.
It no longer returns any data from the server

@G4brym G4brym requested review from a team as code owners April 22, 2024 18:13
@@ -109,10 +94,6 @@ export class Ai {
return res.body;
}
}

public getLogs(): Array<string> {
Copy link
Contributor

@Cherry Cherry Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this safe to remove without potentially causing userland runtime issues? Although not officially documented, it's been listed, available, and accessible in the types via @cloudflare/ai for a while:
image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my point of view, end users don't get any benefit from what's being returned here
And this method is going to stop returning results from server side soon, so the client method will have nothing to show

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but returning an empty array likely won't break applications, whereas a method being removed that was previously there will cause a TypeError and potentially break userland code if called and expected to be present.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the new Ai binding is like 2 weeks old, so provably very few users have seen this method, and if they are calling it from the old @cloudflare/ai npm package, they can continue calling it, its just not going to show anything, but it will work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so provably very few users have seen this method

Are there any stats for this? This is a breaking change and should probably be behind a compat flag imo. Workers AI is GA.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @G4brym ,

what Information are you looking to get from the getLogs

The result before any postProcessing is executed, the raw output can be used as input for other models or could be a requirement when the customer wants to apply a different post-processing technique.

On an ideal scenario, we'd be able to "hook" intermediate activations and gradients, potentially allowing customers to use existing models for more advanced purposes (feature extraction with resnet and interpretation with llama + loras, for example).

Thank you for the follow-up!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will forward your feature suggestion internally 👍

Copy link
Member Author

@G4brym G4brym Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In another note, I've come to realize this getLogs method actually never worked when using the new binding, because the run method was throwing an error when parsing the logs from the server.
So for anyone to be using this method it's guaranteed that you are using the old npm package.
So in reality this is not a breaking change, because it never worked on the new binding.

With this in mind, in my opinion a good compromise resolution for this is to:
Merge this PR that removes this method as it never returned anything besides an empty array, and keep supporting the getLogs from the npm package for the foreseeable future
Please fell free to comment, I'm open for suggestions

Copy link
Contributor

@Cherry Cherry Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if it "never worked" as intended, it still returned an empty array. Code like this works in production today, using the new binding:

export default {
	async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
		const messages = [
			{ role: "system", content: "You are a friendly assistant" },
			{
				role: "user",
				content: "What is the origin of the phrase Hello, World",
			},
		];
		const response = await env.AI.run("@cf/meta/llama-2-7b-chat-fp16", { messages, debug: true });
		const logs = env.AI.getLogs();

		return Response.json({response, logs})
	},
};

Even with logs being an empty array, it's not breaking anything in my code, after migrating from the old @cloudflare/ai package. With the change in this PR, that code won't work anymore with no change of my own, as getLogs will now throw an error in my code, potentially breaking my application.

I would suggest if wanting to remove this, it's done so gracefully by just return [], and mark as deprecated. Or, gate the entire method removal behind a compat flag.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just updated the pr to deprecate the getLogs, instead of removing it completely 👍

@G4brym G4brym changed the title Remove getLogs method from Ai binding Deprecate getLogs method from Ai binding Apr 23, 2024
@fhanau fhanau merged commit 50ef78d into cloudflare:main Apr 25, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants