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

support for gemini thinking model #856

Merged
26 changes: 24 additions & 2 deletions src/providers/google-vertex-ai/chatComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,11 +640,26 @@ export const GoogleChatCompleteResponseTransform: (
provider: GOOGLE_VERTEX_AI,
choices:
response.candidates?.map((generation, index) => {
const containsChainOfThoughtMessage =
generation.content?.parts.length > 1;
let message: Message = { role: 'assistant', content: '' };
if (generation.content?.parts[0]?.text) {
let content: string = generation.content.parts[0]?.text;
if (
containsChainOfThoughtMessage &&
generation.content.parts[1]?.text
) {
if (strictOpenAiCompliance)
content = generation.content.parts[1]?.text;
else
content =
generation.content.parts[0]?.text +
'\r\n\r\n' +
generation.content.parts[1]?.text;
}
message = {
role: 'assistant',
content: generation.content.parts[0]?.text,
content,
};
} else if (generation.content?.parts[0]?.functionCall) {
message = {
Expand Down Expand Up @@ -780,9 +795,16 @@ export const GoogleChatCompleteStreamChunkTransform: (
parsedChunk.candidates?.map((generation, index) => {
let message: Message = { role: 'assistant', content: '' };
if (generation.content?.parts[0]?.text) {
let content: string = generation.content.parts[0]?.text;
if (generation.content.parts[1]?.text) {
content =
generation.content.parts[0]?.text +
' ' +
narengogi marked this conversation as resolved.
Show resolved Hide resolved
generation.content.parts[1]?.text;
}
message = {
role: 'assistant',
content: generation.content.parts[0]?.text,
content,
};
} else if (generation.content?.parts[0]?.functionCall) {
message = {
Expand Down
30 changes: 27 additions & 3 deletions src/providers/google/chatComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export const transformOpenAIRoleToGoogleRole = (
return 'model';
case 'tool':
return 'function';
case 'developer':
return 'system';
default:
return role;
}
Expand Down Expand Up @@ -476,11 +478,26 @@ export const GoogleChatCompleteResponseTransform: (
provider: 'google',
choices:
response.candidates?.map((generation, idx) => {
const containsChainOfThoughtMessage =
generation.content?.parts.length > 1;
let message: Message = { role: 'assistant', content: '' };
if (generation.content?.parts[0]?.text) {
let content: string = generation.content.parts[0]?.text;
if (
containsChainOfThoughtMessage &&
generation.content.parts[1]?.text
) {
if (strictOpenAiCompliance)
content = generation.content.parts[1]?.text;
else
content =
generation.content.parts[0]?.text +
'\r\n\r\n' +
generation.content.parts[1]?.text;
}
message = {
role: 'assistant',
content: generation.content.parts[0]?.text,
content,
};
} else if (generation.content?.parts[0]?.functionCall) {
message = {
Expand Down Expand Up @@ -559,10 +576,17 @@ export const GoogleChatCompleteStreamChunkTransform: (
choices:
parsedChunk.candidates?.map((generation, index) => {
let message: Message = { role: 'assistant', content: '' };
if (generation.content.parts[0]?.text) {
if (generation.content?.parts[0]?.text) {
let content: string = generation.content.parts[0]?.text;
if (generation.content.parts[1]?.text) {
content =
generation.content.parts[0]?.text +
' ' +
generation.content.parts[1]?.text;
}
message = {
role: 'assistant',
content: generation.content.parts[0]?.text,
content,
};
} else if (generation.content.parts[0]?.functionCall) {
message = {
Expand Down
Loading