Skip to content

Commit 8c49166

Browse files
lgrammeliteratetograceness
andauthoredJun 14, 2024··
chore (core): rename model registry to provider registry (#1956)
Co-authored-by: Grace Yun <74513600+iteratetograceness@users.noreply.github.com>
1 parent 6a3bbcb commit 8c49166

File tree

9 files changed

+58
-37
lines changed

9 files changed

+58
-37
lines changed
 

‎.changeset/tasty-planets-mate.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'ai': patch
3+
---
4+
5+
chore (core): rename experimental_createModelRegistry to experimental_createProviderRegistry

‎content/docs/03-ai-sdk-core/40-model-management.mdx ‎content/docs/03-ai-sdk-core/40-provider-management.mdx

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
---
2-
title: Model Management
3-
description: Learn how to work with multiple providers and models
2+
title: Provider Management
3+
description: Learn how to work with multiple providers
44
---
55

6-
# Model Management
6+
# Provider Management
77

8-
<Note>Model management is an experimental feature.</Note>
8+
<Note>Provider management is an experimental feature.</Note>
99

1010
When you work with multiple providers and models, it is often desirable to manage them in a central place
1111
and access the models through simple string ids.
1212

13-
The Vercel AI SDK provides a [`ModelRegistry`](/docs/reference/ai-sdk-core/model-registry) for this purpose.
13+
The Vercel AI SDK provides a [`ProviderRegistry`](/docs/reference/ai-sdk-core/provider-registry) for this purpose.
1414
You can register multiple providers. The provider id will become the prefix of the model id:
1515
`providerId:modelId`.
1616

1717
### Setup (Example)
1818

19-
You can create a registry with multiple providers and models using `experimental_createModelRegistry`.
19+
You can create a registry with multiple providers and models using `experimental_createProviderRegistry`.
2020

2121
<Note>
2222
It is common to keep the registry setup in a separate file and import it where
@@ -26,9 +26,9 @@ You can create a registry with multiple providers and models using `experimental
2626
```ts filename={"registry.ts"}
2727
import { anthropic } from '@ai-sdk/anthropic';
2828
import { createOpenAI } from '@ai-sdk/openai';
29-
import { experimental_createModelRegistry as createModelRegistry } from 'ai';
29+
import { experimental_createProviderRegistry as createProviderRegistry } from 'ai';
3030

31-
export const registry = createModelRegistry({
31+
export const registry = createProviderRegistry({
3232
// register provider with prefix and default setup:
3333
anthropic,
3434

‎content/docs/03-ai-sdk-core/index.mdx

+5
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@ description: Learn about the Vercel AI SDK Core.
3939
description: 'Learn how to use embeddings with the Vercel AI SDK Core.',
4040
href: '/docs/ai-sdk-core/embeddings',
4141
},
42+
{
43+
title: 'Provider Management',
44+
description: 'Learn how to work with multiple providers.',
45+
href: '/docs/ai-sdk-core/provider-management',
46+
},
4247
]}
4348
/>

‎content/docs/07-reference/ai-sdk-core/40-model-registry.mdx ‎content/docs/07-reference/ai-sdk-core/40-provider-registry.mdx

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
---
2-
title: experimental_createModelRegistry
2+
title: experimental_createProviderRegistry
33
description: Registry for managing multiple providers and models (API Reference)
44
---
55

6-
# `experimental_createModelRegistry()`
6+
# `experimental_createProviderRegistry()`
77

8-
<Note>Model management is an experimental feature.</Note>
8+
<Note>Provider management is an experimental feature.</Note>
99

1010
When you work with multiple providers and models, it is often desirable to manage them
1111
in a central place and access the models through simple string ids.
1212

13-
`createModelRegistry` lets you create a registry with multiple providers that you
13+
`createProviderRegistry` lets you create a registry with multiple providers that you
1414
can access by their ids.
1515

1616
### Setup (Example)
1717

18-
You can create a registry with multiple providers and models using `createModelRegistry`.
18+
You can create a registry with multiple providers and models using `createProviderRegistry`.
1919

2020
```ts
2121
import { anthropic } from '@ai-sdk/anthropic';
2222
import { createOpenAI } from '@ai-sdk/openai';
23-
import { experimental_createModelRegistry as createModelRegistry } from 'ai';
23+
import { experimental_createProviderRegistry as createProviderRegistry } from 'ai';
2424

25-
export const registry = createModelRegistry({
25+
export const registry = createProviderRegistry({
2626
// register provider with prefix and default setup:
2727
anthropic,
2828

@@ -50,7 +50,7 @@ const { text } = await generateText({
5050
## Import
5151

5252
<Snippet
53-
text={`import { experimental_createModelRegistry as createModelRegistry } from "ai"`}
53+
text={`import { experimental_createProviderRegistry as createProviderRegistry } from "ai"`}
5454
prompt={false}
5555
/>
5656

@@ -72,7 +72,7 @@ Registers a language model provider with a given id.
7272

7373
### Returns
7474

75-
The `experimental_createModelRegistry` function returns a `experimental_ModelRegistry` instance. It has the following methods:
75+
The `experimental_createProviderRegistry` function returns a `experimental_ProviderRegistry` instance. It has the following methods:
7676

7777
<PropertiesTable
7878
content={[

‎content/docs/07-reference/ai-sdk-core/index.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ It also contains the following helper functions:
5858
href: '/docs/reference/ai-sdk-core/tool',
5959
},
6060
{
61-
title: 'createModelRegistry()',
61+
title: 'createProviderRegistry()',
6262
description:
6363
'Creates a registry for using models from multiple providers.',
64-
href: '/docs/reference/ai-sdk-core/model-registry',
64+
href: '/docs/reference/ai-sdk-core/provider-registry',
6565
},
6666
{
6767
title: 'cosineSimilarity()',

‎examples/ai-core/src/registry/setup-registry.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { anthropic } from '@ai-sdk/anthropic';
22
import { createOpenAI } from '@ai-sdk/openai';
3-
import { experimental_createModelRegistry as createModelRegistry } from 'ai';
3+
import { experimental_createProviderRegistry as createProviderRegistry } from 'ai';
44
import dotenv from 'dotenv';
55

66
dotenv.config();
77

8-
export const registry = createModelRegistry({
8+
export const registry = createProviderRegistry({
99
// register provider with prefix and default setup:
1010
anthropic,
1111

‎packages/core/core/registry/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from './model-registry';
1+
export * from './invalid-model-id-error';
22
export * from './no-such-model-error';
33
export * from './no-such-provider-error';
4-
export * from './invalid-model-id-error';
4+
export * from './provider-registry';
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { MockLanguageModelV1 } from '../test/mock-language-model-v1';
22
import { InvalidModelIdError } from './invalid-model-id-error';
3-
import { experimental_createModelRegistry } from './model-registry';
43
import { NoSuchModelError } from './no-such-model-error';
54
import { NoSuchProviderError } from './no-such-provider-error';
5+
import { experimental_createProviderRegistry } from './provider-registry';
66

77
it('should return language model from provider', () => {
88
const model = new MockLanguageModelV1();
99

10-
const modelRegistry = experimental_createModelRegistry({
10+
const modelRegistry = experimental_createProviderRegistry({
1111
provider: id => {
1212
expect(id).toEqual('model');
1313
return model;
@@ -18,27 +18,27 @@ it('should return language model from provider', () => {
1818
});
1919

2020
it('should throw NoSuchProviderError if provider does not exist', () => {
21-
const modelRegistry = experimental_createModelRegistry({});
21+
const registry = experimental_createProviderRegistry({});
2222

23-
expect(() => modelRegistry.languageModel('provider:model')).toThrowError(
23+
expect(() => registry.languageModel('provider:model')).toThrowError(
2424
NoSuchProviderError,
2525
);
2626
});
2727

2828
it('should throw NoSuchModelError if provider does not return a model', () => {
29-
const modelRegistry = experimental_createModelRegistry({
29+
const registry = experimental_createProviderRegistry({
3030
provider: () => null as any,
3131
});
3232

33-
expect(() => modelRegistry.languageModel('provider:model')).toThrowError(
33+
expect(() => registry.languageModel('provider:model')).toThrowError(
3434
NoSuchModelError,
3535
);
3636
});
3737

3838
it("should throw InvalidModelIdError if model id doesn't contain a colon", () => {
39-
const modelRegistry = experimental_createModelRegistry({});
39+
const registry = experimental_createProviderRegistry({});
4040

41-
expect(() => modelRegistry.languageModel('model')).toThrowError(
41+
expect(() => registry.languageModel('model')).toThrowError(
4242
InvalidModelIdError,
4343
);
4444
});

‎packages/core/core/registry/model-registry.ts ‎packages/core/core/registry/provider-registry.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { NoSuchProviderError } from './no-such-provider-error';
66
/**
77
Registry for managing models. It enables getting a model with a string id.
88
*/
9-
export type experimental_ModelRegistry = {
9+
export type experimental_ProviderRegistry = {
1010
/**
1111
Returns the language model with the given id in the format `providerId:modelId`.
1212
The model id is then passed to the provider function to get the model.
@@ -22,12 +22,17 @@ The model id is then passed to the provider function to get the model.
2222
};
2323

2424
/**
25-
* Creates a model registry for the given providers.
25+
* @deprecated Use `experimental_ProviderRegistry` instead.
2626
*/
27-
export function experimental_createModelRegistry(
27+
export type experimental_ModelRegistry = experimental_ProviderRegistry;
28+
29+
/**
30+
* Creates a registry for the given providers.
31+
*/
32+
export function experimental_createProviderRegistry(
2833
providers: Record<string, (id: string) => LanguageModel>,
29-
): experimental_ModelRegistry {
30-
const registry = new DefaultModelRegistry();
34+
): experimental_ProviderRegistry {
35+
const registry = new DefaultProviderRegistry();
3136

3237
for (const [id, provider] of Object.entries(providers)) {
3338
registry.registerLanguageModelProvider({ id, provider });
@@ -36,7 +41,7 @@ export function experimental_createModelRegistry(
3641
return registry;
3742
}
3843

39-
class DefaultModelRegistry implements experimental_ModelRegistry {
44+
class DefaultProviderRegistry implements experimental_ProviderRegistry {
4045
// Mapping of provider id to provider
4146
private providers: Record<string, (id: string) => LanguageModel> = {};
4247

@@ -91,3 +96,9 @@ The model id is then passed to the provider function to get the model.
9196
return model;
9297
}
9398
}
99+
100+
/**
101+
* @deprecated Use `experimental_createProviderRegistry` instead.
102+
*/
103+
export const experimental_createModelRegistry =
104+
experimental_createProviderRegistry;

0 commit comments

Comments
 (0)
Please sign in to comment.