-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feat (packages/openai-compatible): Base for OpenAI-compatible providers. #3812
base: main
Are you sure you want to change the base?
Conversation
d53c857
to
90b9c52
Compare
packages/openai-compatible/src/openai-compatible-completion-language-model.ts
Outdated
Show resolved
Hide resolved
90b9c52
to
e32f8db
Compare
e32f8db
to
2978847
Compare
import { createOpenAICompatible } from '@ai-sdk/openai-compatible'; | ||
``` | ||
|
||
## Example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a section on creating a custom provider leveraging this package. I'm planning to add that once we have the TogetherAI one done.
21e1cc0
to
c7ecf2f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to find a model on together.ai that supported image inputs after 30m of trying a few that seemed like they might. So I switched to OpenAI and validated it's operational. I will try with other companies/models later as we generalize the error schema and so forth to make it easier to test others.
c7ecf2f
to
83679e8
Compare
|
||
async function main() { | ||
const togetherai = createOpenAICompatible({ | ||
apiKeyEnvVarName: 'TOGETHER_AI_API_KEY', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's completely remove the concept of env variables for openai compatible. it's an unnecessary complexity in this special case, users can just pass the env property and we have less API surface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(it it only there for convenience to begin with, and here convenience becomes complexity)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should go even further and remove the api key completely. some providers don't need api keys, and other have different header settings. instead it should be possible to send in default headers.
|
||
const { text } = await generateText({ | ||
model: createOpenAICompatible({ | ||
apiKeyEnvVarName: 'EXAMPLE_API_KEY', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
directly pass env property instead
Description of the API key environment variable (for use in error messages). | ||
*/ | ||
apiKeyEnvVarDescription?: string; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets remove api key related code completely. instead users can provide the key via headers. reason being that some providers have no api keys and there are different ways to send it via headers
const getHeaders = () => ({ | ||
Authorization: `Bearer ${loadApiKey({ | ||
apiKey: options.apiKey, | ||
environmentVariableName: options.apiKeyEnvVarName ?? '', | ||
description: options.apiKeyEnvVarDescription ?? '', | ||
})}`, | ||
...options.headers, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can get rid of this and just use options.headers
Breakout from #3781. Follow-up items:
json_schema
andstructuredOutputs
inopenai-compatible-chat-language-model.ts
content
)