-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (providers): support custom fetch implementations (#1955)
- Loading branch information
Showing
24 changed files
with
276 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
'@ai-sdk/provider-utils': patch | ||
'@ai-sdk/anthropic': patch | ||
'@ai-sdk/mistral': patch | ||
'@ai-sdk/google': patch | ||
'@ai-sdk/openai': patch | ||
'@ai-sdk/azure': patch | ||
--- | ||
|
||
feat (providers): support custom fetch implementations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
examples/ai-core/src/generate-text/anthropic-custom-fetch.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createAnthropic } from '@ai-sdk/anthropic'; | ||
import { generateText } from 'ai'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
const anthropic = createAnthropic({ | ||
// example fetch wrapper that logs the URL: | ||
fetch: async (url, options) => { | ||
console.log(`Fetching ${url}`); | ||
const result = await fetch(url, options); | ||
console.log(`Fetched ${url}`); | ||
console.log(); | ||
return result; | ||
}, | ||
}); | ||
|
||
async function main() { | ||
const result = await generateText({ | ||
model: anthropic('claude-3-haiku-20240307'), | ||
prompt: 'Invent a new holiday and describe its traditions.', | ||
}); | ||
|
||
console.log(result.text); | ||
} | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createAzure } from '@ai-sdk/azure'; | ||
import { generateText } from 'ai'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
const azure = createAzure({ | ||
// example fetch wrapper that logs the URL: | ||
fetch: async (url, options) => { | ||
console.log(`Fetching ${url}`); | ||
const result = await fetch(url, options); | ||
console.log(`Fetched ${url}`); | ||
console.log(); | ||
return result; | ||
}, | ||
}); | ||
|
||
async function main() { | ||
const result = await generateText({ | ||
model: azure('v0-gpt-35-turbo'), // use your own deployment | ||
prompt: 'Invent a new holiday and describe its traditions.', | ||
}); | ||
|
||
console.log(result.text); | ||
} | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createGoogleGenerativeAI } from '@ai-sdk/google'; | ||
import { generateText } from 'ai'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
const google = createGoogleGenerativeAI({ | ||
// example fetch wrapper that logs the URL: | ||
fetch: async (url, options) => { | ||
console.log(`Fetching ${url}`); | ||
const result = await fetch(url, options); | ||
console.log(`Fetched ${url}`); | ||
console.log(); | ||
return result; | ||
}, | ||
}); | ||
|
||
async function main() { | ||
const result = await generateText({ | ||
model: google('models/gemini-pro'), | ||
prompt: 'Invent a new holiday and describe its traditions.', | ||
}); | ||
|
||
console.log(result.text); | ||
} | ||
|
||
main().catch(console.error); |
27 changes: 27 additions & 0 deletions
27
examples/ai-core/src/generate-text/mistral-custom-fetch.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createMistral } from '@ai-sdk/mistral'; | ||
import { generateText } from 'ai'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
const mistral = createMistral({ | ||
// example fetch wrapper that logs the URL: | ||
fetch: async (url, options) => { | ||
console.log(`Fetching ${url}`); | ||
const result = await fetch(url, options); | ||
console.log(`Fetched ${url}`); | ||
console.log(); | ||
return result; | ||
}, | ||
}); | ||
|
||
async function main() { | ||
const result = await generateText({ | ||
model: mistral('open-mistral-7b'), | ||
prompt: 'Invent a new holiday and describe its traditions.', | ||
}); | ||
|
||
console.log(result.text); | ||
} | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createOpenAI } from '@ai-sdk/openai'; | ||
import { generateText } from 'ai'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
const openai = createOpenAI({ | ||
// example fetch wrapper that logs the URL: | ||
fetch: async (url, options) => { | ||
console.log(`Fetching ${url}`); | ||
const result = await fetch(url, options); | ||
console.log(`Fetched ${url}`); | ||
console.log(); | ||
return result; | ||
}, | ||
}); | ||
|
||
async function main() { | ||
const result = await generateText({ | ||
model: openai('gpt-3.5-turbo'), | ||
prompt: 'Invent a new holiday and describe its traditions.', | ||
}); | ||
|
||
console.log(result.text); | ||
} | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.