Skip to content
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 (provider/togetherai): Add TogetherAI provider. #3781

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

shaper
Copy link
Contributor

@shaper shaper commented Nov 19, 2024

Built on top of a new openai-compatible package for better code sharing as we add more top level providers that follow this pattern.

Comment on lines +9 to +24
export function mapOpenAICompatibleCompletionLogProbs(
logprobs: OpenAICompatibleCompletionLogProps | null | undefined,
): LanguageModelV1LogProbs | undefined {
return logprobs?.tokens.map((token, index) => ({
token,
logprob: logprobs.token_logprobs[index],
topLogprobs: logprobs.top_logprobs
? Object.entries(logprobs.top_logprobs[index]).map(
([token, logprob]) => ({
token,
logprob,
}),
)
: [],
}));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove logprobs from the compatible provider. I'm leaning towards moving it into a provider extension since it's rarely supported.

Comment on lines +18 to +19
// TODO(shaper): This is really model-specific, move to config or elsewhere?
defaultObjectGenerationMode?: 'json' | 'tool' | undefined;
Copy link
Collaborator

@lgrammel lgrammel Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make it a constructor parameter (in the options) for the model that is then defined in the providers? (which would have that knowledge)

Comment on lines +148 to +151
// TODO(shaper): Review vs. OpenAI impl here.
throw new UnsupportedFunctionalityError({
functionality: 'object-json mode',
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy what openai has including schemas

constructor(
modelId: OpenAICompatibleChatModelId,
settings: OpenAICompatibleChatSettings,
config: OpenAICompatibleChatConfig,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include the default object generation mode in config

completionTokens: response.usage.completion_tokens,
},
finishReason: mapOpenAICompatibleFinishReason(choice.finish_reason),
logprobs: mapOpenAICompatibleCompletionLogProbs(choice.logprobs),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm logbprobs

Comment on lines +343 to +349
logprobs: z
.object({
tokens: z.array(z.string()),
token_logprobs: z.array(z.number()),
top_logprobs: z.array(z.record(z.string(), z.number())).nullable(),
})
.nullish(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm logprobs

Comment on lines +370 to +376
logprobs: z
.object({
tokens: z.array(z.string()),
token_logprobs: z.array(z.number()),
top_logprobs: z.array(z.record(z.string(), z.number())).nullable(),
})
.nullish(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Comment on lines +132 to +133
// 'openai-organization': 'test-organization',
// 'openai-project': 'test-project',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm

Comment on lines +111 to +112
// organization: 'test-organization',
// project: 'test-project',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm

Comment on lines +9 to +12
/**
Override the parallelism of embedding calls.
*/
supportsParallelCalls?: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to config?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(first 2 options)

Comment on lines +4 to +19
// TODO(shaper): Reconcile this with openai-error.ts. We derived from `xai`.

export const openAICompatibleErrorDataSchema = z.object({
code: z.string(),
error: z.string(),
});

export type OpenAICompatibleErrorData = z.infer<
typeof openAICompatibleErrorDataSchema
>;

export const openAICompatibleFailedResponseHandler =
createJsonErrorResponseHandler({
errorSchema: openAICompatibleErrorDataSchema,
errorToMessage: data => data.error,
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make provider-specific. different providers have different structures. have default that matches openai

Comment on lines +19 to +21
L extends string = string,
C extends string = string,
E extends string = string,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer full words for generic in upper case, e.g. CONTEXT

Comment on lines +94 to +96
// TODO(shaper):
// - consider throwing if baseUrl, name, sufficient api key info not available
// - force only 'compatible' -- look into whether we can remove some 'strict' logic/configs entirely
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - goal is that this works w/ compatible mode but is more flexible. then eventually openai provider should only be strict mode and we can simplify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants