write-language 0.1.20 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +255 -255
- package/dist/write-language.cjs.js.map +1 -1
- package/dist/write-language.es.js.map +1 -1
- package/package.json +1 -1
- package/src/generate-response.ts +196 -196
- package/src/generation-types.ts +90 -90
- package/src/index.ts +40 -40
- package/src/language-model-families.ts +139 -139
- package/src/language-model-registry.ts +1336 -1336
- package/src/prompt-templates.ts +651 -651
- package/src/provider-factory.ts +98 -98
package/src/provider-factory.ts
CHANGED
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Provider factory for Vercel AI SDK v5 language model instances.
|
|
3
|
-
* Supports OpenAI, Anthropic, Groq, Google, xAI, Amazon Bedrock, OpenRouter, and OpenAI-compatible endpoints.
|
|
4
|
-
*/
|
|
5
|
-
import { createOpenAI } from "@ai-sdk/openai";
|
|
6
|
-
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
7
|
-
import { createGroq } from "@ai-sdk/groq";
|
|
8
|
-
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
|
9
|
-
import { createVertex } from "@ai-sdk/google-vertex";
|
|
10
|
-
import { createXai } from "@ai-sdk/xai";
|
|
11
|
-
import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock";
|
|
12
|
-
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
|
|
13
|
-
import type { LanguageModel } from "ai";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Instantiates the appropriate Vercel AI SDK language model for the given provider.
|
|
17
|
-
*
|
|
18
|
-
* @param provider - Normalised (lowercase) provider name
|
|
19
|
-
* @param apiKey - Provider API key
|
|
20
|
-
* @param model - Model ID to use
|
|
21
|
-
* @param _temperature - Unused here; temperature is passed to generateText at call time
|
|
22
|
-
* @returns A LanguageModel instance, or `null` for an unrecognised provider
|
|
23
|
-
*/
|
|
24
|
-
export function createLLMProvider(
|
|
25
|
-
provider: string,
|
|
26
|
-
apiKey: string,
|
|
27
|
-
model: string,
|
|
28
|
-
_temperature: number,
|
|
29
|
-
): LanguageModel | null {
|
|
30
|
-
switch (provider) {
|
|
31
|
-
case "groq":
|
|
32
|
-
return createGroq({ apiKey })(model);
|
|
33
|
-
|
|
34
|
-
case "togetherai":
|
|
35
|
-
return createOpenAI({
|
|
36
|
-
apiKey,
|
|
37
|
-
baseURL: "https://api.together.xyz/v1",
|
|
38
|
-
})(model);
|
|
39
|
-
|
|
40
|
-
case "openai":
|
|
41
|
-
return createOpenAI({ apiKey })(model);
|
|
42
|
-
|
|
43
|
-
case "anthropic":
|
|
44
|
-
return createAnthropic({ apiKey })(model);
|
|
45
|
-
|
|
46
|
-
case "xai":
|
|
47
|
-
return createXai({ apiKey })(model);
|
|
48
|
-
|
|
49
|
-
case "google":
|
|
50
|
-
return createGoogleGenerativeAI({ apiKey })(model);
|
|
51
|
-
|
|
52
|
-
case "vertex": {
|
|
53
|
-
const [projectId, location = "us-central1"] = apiKey.split(":");
|
|
54
|
-
return createVertex({ project: projectId, location, googleAuthOptions: {} })(model);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
case "cloudflare": {
|
|
58
|
-
const [cfApiToken, accountId] = apiKey.split(":");
|
|
59
|
-
return createOpenAI({
|
|
60
|
-
apiKey: cfApiToken,
|
|
61
|
-
baseURL: `https://api.cloudflare.com/client/v4/accounts/${accountId}/ai/v1`,
|
|
62
|
-
})(model);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
case "nvidia":
|
|
66
|
-
return createOpenAI({
|
|
67
|
-
apiKey,
|
|
68
|
-
baseURL: "https://integrate.api.nvidia.com/v1",
|
|
69
|
-
})(model);
|
|
70
|
-
|
|
71
|
-
case "openrouter":
|
|
72
|
-
return createOpenRouter({ apiKey }).chat(model);
|
|
73
|
-
|
|
74
|
-
case "perplexity":
|
|
75
|
-
return createOpenAI({
|
|
76
|
-
apiKey,
|
|
77
|
-
baseURL: "https://api.perplexity.ai",
|
|
78
|
-
})(model);
|
|
79
|
-
|
|
80
|
-
case "amazon":
|
|
81
|
-
case "bedrock": {
|
|
82
|
-
// Support both AWS_aBEARER_TOKEN_BEDROCK and AWS credential chain
|
|
83
|
-
// apiKey can be either the bearer token or "region:accessKey:secretKey"
|
|
84
|
-
const parts = apiKey.split(":");
|
|
85
|
-
// Format: region:accessKeyId:secretAccessKey
|
|
86
|
-
const [region, accessKeyId, secretAccessKey] = parts;
|
|
87
|
-
return createAmazonBedrock({
|
|
88
|
-
region,
|
|
89
|
-
accessKeyId,
|
|
90
|
-
secretAccessKey,
|
|
91
|
-
})(model);
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
default:
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Provider factory for Vercel AI SDK v5 language model instances.
|
|
3
|
+
* Supports OpenAI, Anthropic, Groq, Google, xAI, Amazon Bedrock, OpenRouter, and OpenAI-compatible endpoints.
|
|
4
|
+
*/
|
|
5
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
6
|
+
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
7
|
+
import { createGroq } from "@ai-sdk/groq";
|
|
8
|
+
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
|
9
|
+
import { createVertex } from "@ai-sdk/google-vertex";
|
|
10
|
+
import { createXai } from "@ai-sdk/xai";
|
|
11
|
+
import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock";
|
|
12
|
+
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
|
|
13
|
+
import type { LanguageModel } from "ai";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Instantiates the appropriate Vercel AI SDK language model for the given provider.
|
|
17
|
+
*
|
|
18
|
+
* @param provider - Normalised (lowercase) provider name
|
|
19
|
+
* @param apiKey - Provider API key
|
|
20
|
+
* @param model - Model ID to use
|
|
21
|
+
* @param _temperature - Unused here; temperature is passed to generateText at call time
|
|
22
|
+
* @returns A LanguageModel instance, or `null` for an unrecognised provider
|
|
23
|
+
*/
|
|
24
|
+
export function createLLMProvider(
|
|
25
|
+
provider: string,
|
|
26
|
+
apiKey: string,
|
|
27
|
+
model: string,
|
|
28
|
+
_temperature: number,
|
|
29
|
+
): LanguageModel | null {
|
|
30
|
+
switch (provider) {
|
|
31
|
+
case "groq":
|
|
32
|
+
return createGroq({ apiKey })(model);
|
|
33
|
+
|
|
34
|
+
case "togetherai":
|
|
35
|
+
return createOpenAI({
|
|
36
|
+
apiKey,
|
|
37
|
+
baseURL: "https://api.together.xyz/v1",
|
|
38
|
+
})(model);
|
|
39
|
+
|
|
40
|
+
case "openai":
|
|
41
|
+
return createOpenAI({ apiKey })(model);
|
|
42
|
+
|
|
43
|
+
case "anthropic":
|
|
44
|
+
return createAnthropic({ apiKey })(model);
|
|
45
|
+
|
|
46
|
+
case "xai":
|
|
47
|
+
return createXai({ apiKey })(model);
|
|
48
|
+
|
|
49
|
+
case "google":
|
|
50
|
+
return createGoogleGenerativeAI({ apiKey })(model);
|
|
51
|
+
|
|
52
|
+
case "vertex": {
|
|
53
|
+
const [projectId, location = "us-central1"] = apiKey.split(":");
|
|
54
|
+
return createVertex({ project: projectId, location, googleAuthOptions: {} })(model);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
case "cloudflare": {
|
|
58
|
+
const [cfApiToken, accountId] = apiKey.split(":");
|
|
59
|
+
return createOpenAI({
|
|
60
|
+
apiKey: cfApiToken,
|
|
61
|
+
baseURL: `https://api.cloudflare.com/client/v4/accounts/${accountId}/ai/v1`,
|
|
62
|
+
})(model);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
case "nvidia":
|
|
66
|
+
return createOpenAI({
|
|
67
|
+
apiKey,
|
|
68
|
+
baseURL: "https://integrate.api.nvidia.com/v1",
|
|
69
|
+
})(model);
|
|
70
|
+
|
|
71
|
+
case "openrouter":
|
|
72
|
+
return createOpenRouter({ apiKey }).chat(model);
|
|
73
|
+
|
|
74
|
+
case "perplexity":
|
|
75
|
+
return createOpenAI({
|
|
76
|
+
apiKey,
|
|
77
|
+
baseURL: "https://api.perplexity.ai",
|
|
78
|
+
})(model);
|
|
79
|
+
|
|
80
|
+
case "amazon":
|
|
81
|
+
case "bedrock": {
|
|
82
|
+
// Support both AWS_aBEARER_TOKEN_BEDROCK and AWS credential chain
|
|
83
|
+
// apiKey can be either the bearer token or "region:accessKey:secretKey"
|
|
84
|
+
const parts = apiKey.split(":");
|
|
85
|
+
// Format: region:accessKeyId:secretAccessKey
|
|
86
|
+
const [region, accessKeyId, secretAccessKey] = parts;
|
|
87
|
+
return createAmazonBedrock({
|
|
88
|
+
region,
|
|
89
|
+
accessKeyId,
|
|
90
|
+
secretAccessKey,
|
|
91
|
+
})(model);
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
default:
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|