Repository: directus-labs/extensions
Pull request #199: Update AI Writer Model Options
Author: login: LZylstra
Created: 2025-05-12T18:33:32Z | Merged: 2025-05-29T20:17:41Z

Updated to add newer model support


Diff:
diff --git a/packages/ai-writer-operation/package.json b/packages/ai-writer-operation/package.json
index 890621da..eea4575b 100644
--- a/packages/ai-writer-operation/package.json
+++ b/packages/ai-writer-operation/package.json
@@ -1,7 +1,7 @@
 {
 	"name": "@directus-labs/ai-writer-operation",
 	"type": "module",
-	"version": "1.4.0",
+	"version": "1.4.1",
 	"description": "Use OpenAI, Claude, Meta and Mistral Text Generation APIs to generate text.",
 	"author": "Directus Labs",
 	"contributors": [
diff --git a/packages/ai-writer-operation/src/Provider/Anthropic.ts b/packages/ai-writer-operation/src/Provider/Anthropic.ts
index 7350acda..f52d6d85 100644
--- a/packages/ai-writer-operation/src/Provider/Anthropic.ts
+++ b/packages/ai-writer-operation/src/Provider/Anthropic.ts
@@ -27,7 +27,7 @@ export class Anthropic extends Provider {
 			headers: {
 				'x-api-key': this.apiKey,
 				'Content-Type': 'application/json',
-				'anthropic-version': '2023-06-01',
+				'anthropic-version': '2023-10-01',
 			},
 			body: JSON.stringify(requestBody),
 		});
diff --git a/packages/ai-writer-operation/src/Provider/Replicate.ts b/packages/ai-writer-operation/src/Provider/Replicate.ts
index a63fef93..ad4958dd 100644
--- a/packages/ai-writer-operation/src/Provider/Replicate.ts
+++ b/packages/ai-writer-operation/src/Provider/Replicate.ts
@@ -10,17 +10,19 @@ export class Replicate extends Provider {
 			throw new InvalidPayloadError({ reason: 'Replicate API Key is missing' });
 		}
 
-		if (options.model === 'meta-llama-3.1-405b-instruct') {
-			super(options, 'https://api.replicate.com/v1/models/meta/meta-llama-3.1-405b-instruct/predictions', options.apiKeyReplicate);
-		}
+		const modelMap: Record<string, string> = {
+			'meta-llama-3.1-405b-instruct': 'meta/meta-llama-3.1-405b-instruct',
+			'llama-3-8b-instruct': 'meta/llama-3-8b-instruct',
+			'mistral-7b-v0.1': 'mistralai/mistral-7b-v0.1',
+		};
 
-		else if (options.model === 'mistral-7b-v0.1') {
-			super(options, 'https://api.replicate.com/v1/models/mistralai/mistral-7b-v0.1/predictions', options.apiKeyReplicate);
-		}
+		const path = modelMap[options.model!];
 
-		else {
+		if (!path) {
 			throw new InvalidPayloadError({ reason: `Model ${options.model} not supported` });
 		}
+
+		super(options, `https://api.replicate.com/v1/models/${path}/predictions`, options.apiKeyReplicate);
 	}
 
 	public async messageRequest(): Promise<string> {
@@ -56,7 +58,7 @@ export class Replicate extends Provider {
 		let hasFinished = false;
 		let message = '';
 
-		while (hasFinished === false) {
+		while (!hasFinished) {
 			await sleep(1000);
 			const fetchedMessage = await this.fetchMessage(data.urls.get);
 			message = fetchedMessage || '';
diff --git a/packages/ai-writer-operation/src/app.ts b/packages/ai-writer-operation/src/app.ts
index a15cdaac..9a910656 100644
--- a/packages/ai-writer-operation/src/app.ts
+++ b/packages/ai-writer-operation/src/app.ts
@@ -22,68 +22,39 @@ export default defineOperationApp({
 	],
 	options: (context) => {
 		const anthropicModels = [
-			{
-				text: 'Claude 3.5 Sonnet',
-				value: 'claude-3-5-sonnet-latest',
-			},
-			{
-				text: 'Claude 3.5 Haiku',
-				value: 'claude-3-5-haiku-latest',
-			},
-			{
-				text: 'Claude 3 Opus',
-				value: 'claude-3-opus-latest',
-			},
-			{
-				text: 'Claude 3 Sonnet',
-				value: 'claude-3-sonnet-20240229',
-			},
-			{
-				text: 'Claude 3 Haiku',
-				value: 'claude-3-haiku-20240307',
-			},
+			{ text: 'Claude 3.7 Sonnet', value: 'claude-3-7-sonnet-latest' },
+			{ text: 'Claude 3.5 Sonnet', value: 'claude-3-5-sonnet-latest' },
+			{ text: 'Claude 3.5 Haiku', value: 'claude-3-5-haiku-latest' },
+			{ text: 'Claude 3.5 Opus', value: 'claude-3-5-opus-latest' },
+			{ text: 'Claude 3 Opus', value: 'claude-3-opus-latest' },
+			{ text: 'Claude 3 Sonnet', value: 'claude-3-sonnet-20240229' },
+			{ text: 'Claude 3 Haiku', value: 'claude-3-haiku-20240307' },
 		];
 
 		const openAiModels = [
-			{
-				text: 'GPT-4o',
-				value: 'gpt-4o',
-			},
-			{
-				text: 'GPT-4o mini',
-				value: 'gpt-4o-mini',
-			},
-			{
-				text: 'GPT-4 Turbo',
-				value: 'gpt-4-turbo',
-			},
-			{
-				text: 'GPT-4',
-				value: 'gpt-4',
-			},
-			{
-				text: 'GPT-3.5 Turbo',
-				value: 'gpt-3.5-turbo',
-			},
-			{
-				text: 'o1',
-				value: 'o1',
-			},
-			{
-				text: 'o1-mini',
-				value: 'o1-mini',
-			},
+			{ text: 'GPT-4.1', value: 'gpt-4.1-2025-04-14' },
+			{ text: 'GPT-4.1 Mini', value: 'gpt-4.1-mini-2025-04-14' },
+			{ text: 'GPT-4.1 Nano', value: 'gpt-4.1-nano-2025-04-14' },
+			{ text: 'GPT-4.5 Preview', value: 'gpt-4.5-preview-2025-02-27' },
+			{ text: 'GPT-4o', value: 'gpt-4o-2024-08-06' },
+			{ text: 'GPT-4o Mini', value: 'gpt-4o-mini-2024-07-18' },
+			{ text: 'O1', value: 'o1-2024-12-17' },
+			{ text: 'O1 Pro', value: 'o1-pro-2025-03-19' },
+			{ text: 'O1 Mini', value: 'o1-mini-2024-09-12' },
+			{ text: 'O3', value: 'o3-2025-04-16' },
+			{ text: 'O3 Mini', value: 'o3-mini-2025-01-31' },
+			{ text: 'O4 Mini', value: 'o4-mini-2025-04-16' },
+			{ text: 'GPT-4 Turbo', value: 'gpt-4-turbo' },
+			{ text: 'GPT-4', value: 'gpt-4' },
+			{ text: 'GPT-3.5 Turbo', value: 'gpt-3.5-turbo' },
+			{ text: 'O1 (legacy)', value: 'o1' },
+			{ text: 'O1 Mini (legacy)', value: 'o1-mini' },
 		];
 
 		const replicateModels = [
-			{
-				text: 'Meta Llama 3.1-405b-instruct',
-				value: 'meta-llama-3.1-405b-instruct',
-			},
-			{
-				text: 'Mistral-7B-v0.1',
-				value: 'mistral-7b-v0.1',
-			},
+			{ text: 'Meta Llama 3.1 405B Instruct', value: 'meta-llama-3.1-405b-instruct' },
+			{ text: 'Meta Llama 3 8B Instruct', value: 'llama-3-8b-instruct' },
+			{ text: 'Mistral 7B v0.1', value: 'mistral-7b-v0.1' },
 		];
 
 		const getModels = (provider: string) => {
@@ -118,7 +89,7 @@ export default defineOperationApp({
 								value: 'anthropic',
 							},
 							{
-								text: 'Open Ai',
+								text: 'Open AI',
 								value: 'openai',
 							},
 							{


Reviews:
user: login: bryantgillespie
body: Looks good - just a few changes and notes.
state: CHANGES_REQUESTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-20T01:44:14Z
user: login: bryantgillespie
body: LGTM - we'll track the improvements for the error handler in a separate PR
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-05-29T20:17:36Z

Review comments:
path: packages/ai-writer-operation/src/Provider/Replicate.ts
user: login: bryantgillespie
body: Would it make more sense to do this with a mapping object instead of a switch so we don't have to keep adding cases to the switch statement if we add or change models?
created_at: 2025-05-20T01:40:56Z
author_association: CONTRIBUTOR
diff_hunk: @@ -22,68 +22,38 @@ export default defineOperationApp({
 	],
 	options: (context) => {
 		const anthropicModels = [
-			{
-				text: 'Claude 3.5 Sonnet',
-				value: 'claude-3-5-sonnet-latest',
-			},
-			{
-				text: 'Claude 3.5 Haiku',
-				value: 'claude-3-5-haiku-latest',
-			},
-			{
-				text: 'Claude 3 Opus',
-				value: 'claude-3-opus-latest',
-			},
-			{
-				text: 'Claude 3 Sonnet',
-				value: 'claude-3-sonnet-20240229',
-			},
-			{
-				text: 'Claude 3 Haiku',
-				value: 'claude-3-haiku-20240307',
-			},
+			{ text: 'Claude 3.5 Sonnet', value: 'claude-3-5-sonnet-latest' },
path: packages/ai-writer-operation/src/app.ts
user: login: bryantgillespie
body: We're missing Claude Sonnet 3.7 I think
https://docs.anthropic.com/en/docs/about-claude/models/overview
created_at: 2025-05-20T01:43:01Z
author_association: CONTRIBUTOR

PR comments:
user: login: bryantgillespie
created_at: 2025-05-20T01:41:45Z
body: Can you make sure the Anthropic models are updated as well?
https://docs.anthropic.com/en/docs/about-claude/models/overview
author_association: CONTRIBUTOR
user: login: bryantgillespie
created_at: 2025-05-20T01:45:58Z
body: Don't forget to bump the package version number and update the readme (if needed)
author_association: CONTRIBUTOR