Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
isnolan committed May 21, 2024
1 parent 33ff17e commit a0a2269
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 9 deletions.
9 changes: 7 additions & 2 deletions packages/bodhi-adapter/dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,9 @@ ${part.text}
choices.push({ index, role: 'assistant', parts, finish_reason: 'stop' });
});
} catch (err) {
console.log(`->candidates1`, JSON.stringify(candidates, null, 2));
console.warn(err);
console.log(`->candidates2`);
}
return choices;
}
Expand Down Expand Up @@ -584,7 +586,10 @@ var GoogleVertexAPI = class extends GoogleGeminiAPI {
const parser = (0, import_eventsource_parser3.createParser)((event) => {
if (event.type === 'event') {
const res2 = JSON.parse(event.data);
const choices = this.convertChoices(res2.candidates);
if (!res2.candidates) {
console.log(`[vertex]debug`, res2);
}
const choices = this.convertChoices(res2.candidates || []);
if (res2.usageMetadata) {
Object.assign(usage, {
prompt_tokens: res2.usageMetadata.promptTokenCount,
Expand Down Expand Up @@ -635,7 +640,7 @@ var GoogleClaudeAPI = class extends ChatBaseAPI {
return await auth.getAccessToken();
}
models() {
return ['claude-3-sonnet@20240229', 'claude-3-haiku@20240307'];
return ['claude-3-sonnet@20240229', 'claude-3-haiku@20240307', 'gemini-1.5-flash-preview-0514'];
}
/**
* Send message
Expand Down
2 changes: 1 addition & 1 deletion packages/bodhi-adapter/dist/index.cjs.map

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions packages/bodhi-adapter/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/bodhi-adapter/dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/bodhi-adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@isnolan/bodhi-adapter",
"version": "0.7.1",
"version": "0.7.5",
"description": "llms adapter api for bodhi",
"main": "index.js",
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions packages/bodhi-adapter/src/provider/google/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export class GoogleGeminiAPI extends ChatBaseAPI {

protected convertChoices(candidates: gemini.Candidate[]): types.chat.Choice[] {
const choices: types.chat.Choice[] = [];

try {
candidates.map(({ index, content, finishReason }: gemini.Candidate) => {
const parts: types.chat.Part[] = [];
Expand All @@ -192,7 +193,9 @@ export class GoogleGeminiAPI extends ChatBaseAPI {
choices.push({ index, role: 'assistant', parts, finish_reason: 'stop' });
});
} catch (err) {
console.log(`->candidates1`, JSON.stringify(candidates, null, 2));
console.warn(err);
console.log(`->candidates2`);
}
return choices;
}
Expand Down
6 changes: 5 additions & 1 deletion packages/bodhi-adapter/src/provider/google/vertex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ export class GoogleVertexAPI extends GoogleGeminiAPI {
const parser = createParser((event: ParseEvent | ReconnectInterval) => {
if (event.type === 'event') {
const res = JSON.parse(event.data);
const choices = this.convertChoices(res.candidates);
// TODO: res 可能为空
if (!res.candidates) {
console.log(`[vertex]debug`, res);
}
const choices = this.convertChoices(res.candidates || []);
if (res.usageMetadata) {
Object.assign(usage, {
prompt_tokens: res.usageMetadata.promptTokenCount,
Expand Down
17 changes: 16 additions & 1 deletion packages/bodhi-adapter/test/aliyun-qwen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('chat', () => {

it('text: streaming', async () => {
const res = await api.sendMessage({
model: 'qwen1.5-110b-chat', // qwen-turbo
model: 'qwen-turbo', // qwen-turbo
messages: [
// { role: 'system', content: 'You are a helpful assistant.' },
// { role: 'user', content: '你好,哪个公园距离我最近?' },
Expand Down Expand Up @@ -70,4 +70,19 @@ describe('chat', () => {
console.log(`[qwen]muliti`, JSON.stringify(res));
expect(res).toBeInstanceOf(Object);
}, 30000);

it('text: max', async () => {
const res = await api.sendMessage({
model: 'qwen-max', // qwen-turbo
messages: [{ role: 'user', parts: [{ type: 'text', text: '今天最新AI科技新闻是什么?' }] }],
top_k: 1.0,
// top_p
onProgress: (choices) => {
console.log(`[qwen]streaming`, JSON.stringify(choices));
expect(choices).toBeInstanceOf(Object);
},
});
console.log(`[qwen]`, JSON.stringify(res));
expect(res).toBeInstanceOf(Object);
}, 30000);
});

0 comments on commit a0a2269

Please sign in to comment.