Skip to content

Commit

Permalink
build: support cohere v2 api
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Oct 31, 2024
1 parent 5ff2ee1 commit 62b8147
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 55 deletions.
2 changes: 1 addition & 1 deletion dist/buildinfo.json

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

27 changes: 2 additions & 25 deletions 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 dist/timestamp

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

29 changes: 1 addition & 28 deletions src/agent/cohere.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { AgentUserConfig } from '../config/env';
import type { SseChatCompatibleOptions } from './request';
import type { SSEMessage, SSEParserResult } from './stream';
import type { ChatAgent, ChatStreamTextHandler, HistoryItem, LLMChatParams } from './types';
import type { ChatAgent, ChatStreamTextHandler, LLMChatParams } from './types';
import { requestChatCompletions } from './request';
import { Stream } from './stream';

export class Cohere implements ChatAgent {
readonly name = 'cohere';
Expand All @@ -17,31 +15,6 @@ export class Cohere implements ChatAgent {
return ctx.COHERE_CHAT_MODEL;
};

private render = (item: HistoryItem): any => {
return {
role: item.role,
message: item.content,
};
};

static parser(sse: SSEMessage): SSEParserResult {
switch (sse.event) {
case 'content-delta':
try {
return { data: JSON.parse(sse.data || '') };
} catch (e) {
console.error(e, sse.data);
return {};
}
case 'stream-start':
return {};
case '[DONE]':
return { finish: true };
default:
return {};
}
}

readonly request = async (params: LLMChatParams, context: AgentUserConfig, onStream: ChatStreamTextHandler | null): Promise<string> => {
const { message, prompt, history } = params;
const url = `${context.COHERE_API_BASE}/chat`;
Expand Down

0 comments on commit 62b8147

Please sign in to comment.