Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
isnolan committed May 6, 2024
1 parent d88c86e commit c9471e8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
10 changes: 7 additions & 3 deletions packages/bodhi-adapter/src/provider/google/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class GoogleGeminiAPI extends ChatBaseAPI {
protected async convertParams(opts: types.chat.SendOptions): Promise<gemini.Request> {
return {
contents: await this.corvertContents(opts),
// systemInstruction: await this.corvertSystemContent(opts),
tools: this.corvertTools(opts),
safety_settings: [
// { category: 'BLOCK_NONE', threshold: 'HARM_CATEGORY_UNSPECIFIED' },
Expand All @@ -107,18 +108,21 @@ export class GoogleGeminiAPI extends ChatBaseAPI {
// filter system role
const rows = await Promise.all(
opts.messages
.filter((item) => item.role !== 'system')
.filter((item) => ['user', 'assistant'].includes(item.role))
.map(async (item) => {
const parts: gemini.Part[] = [];
await Promise.all(
item.parts.map(async (part: types.chat.Part) => {
if (part.type === 'text') {
parts.push({ text: part.text });
}
// if (part.type === 'document') {
// parts.push({ document: { url: part.url } });
// }
if (['image', 'video'].includes(part.type)) {
try {
const inline_data = await this.fetchFile((part as types.chat.FilePart).url);
parts.push({ inline_data });
const inlineData = await this.fetchFile((part as types.chat.FilePart).url);
parts.push({ inlineData });
} catch (err) {}
}
if (part.type === 'function_call') {
Expand Down
3 changes: 2 additions & 1 deletion packages/bodhi-adapter/src/provider/google/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export namespace gemini {
*/
export type Request = {
contents: Content[];
systemInstruction?: Content;
tools: Tools[];
safety_settings: safetyRating[];
generationConfig: {
Expand All @@ -27,7 +28,7 @@ export namespace gemini {

export type Part = TextPart | FilePart | ToolPart;
export type TextPart = { text: string };
export type FilePart = { inline_data: { mime_type: string; data: string } };
export type FilePart = { inlineData: { mimeType: string; data: string } };
export type ToolPart = { functionCall: { name: string; args: any } };

export type Tools = { functionDeclarations: types.chat.Function[] };
Expand Down
2 changes: 1 addition & 1 deletion packages/bodhi-adapter/src/provider/google/vertex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class GoogleVertexAPI extends GoogleGeminiAPI {
const model = hasMedia ? 'gemini-pro-vision' : opts.model || 'gemini-pro';
const url = `${this.baseURL}/publishers/google/models/${model}:streamGenerateContent?alt=sse`;
const params: gemini.Request = await this.convertParams(options);
// console.log(`[fetch]params`, url, JSON.stringify(params, null, 2));
console.log(`[fetch]params`, url, JSON.stringify(params, null, 2));

const res = await fetchSSE(url, {
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
Expand Down
15 changes: 4 additions & 11 deletions packages/bodhi-adapter/test/google-vertex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,18 @@ describe('chat', () => {
const res = await api.sendMessage({
model: 'gemini-pro',
messages: [
{
role: 'system',
parts: [
{
type: 'text',
text: 'You are a very professional document summarization specialist. Please summarize the given document.',
},
],
},
{
role: 'user',
parts: [
{
type: 'document',
url: 'gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf',
// url: 'gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf',
url: 'gs://bodhi-storage/uploads/202405/0db16ca633824283d07cf3774f886cef/0.pdf',
// url: 'https://s.chatonce.cn/bodhi/uploads/202405/0db16ca633824283d07cf3774f886cef/0.pdf',
},
{
type: 'text',
text: '这里都讲了什么?',
text: '这个文档都讲了什么呢?',
},
],
},
Expand Down

0 comments on commit c9471e8

Please sign in to comment.