Skip to content

Commit

Permalink
chore: 删除requestChatCompletions废弃参数
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Nov 12, 2024
1 parent e1a0489 commit 4d75571
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 32 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.

20 changes: 7 additions & 13 deletions dist/index.js

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

8 changes: 3 additions & 5 deletions src/adapter/next/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ import { createOpenAI } from '@ai-sdk/openai';
import { generateText, streamText } from 'ai';
import { streamHandler } from '../../agent/request';

export async function requestChatCompletionsV2(params: { model: LanguageModelV1; prompt?: string; messages: HistoryItem[] }, onStream: ChatStreamTextHandler | null, onResult: ChatStreamTextHandler | null = null): Promise<ChatAgentResponse> {
export async function requestChatCompletionsV2(params: { model: LanguageModelV1; prompt?: string; messages: HistoryItem[] }, onStream: ChatStreamTextHandler | null): Promise<ChatAgentResponse> {
if (onStream !== null) {
const stream = await streamText({
model: params.model,
prompt: params.prompt,
messages: params.messages,
});
const contentFull = await streamHandler(stream.textStream, t => t, onStream);
onResult?.(contentFull);
await streamHandler(stream.textStream, t => t, onStream);
return {
text: contentFull,
text: await stream.text,
responses: (await stream.response).messages,
};
} else {
Expand All @@ -30,7 +29,6 @@ export async function requestChatCompletionsV2(params: { model: LanguageModelV1;
prompt: params.prompt,
messages: params.messages,
});
onResult?.(result.text);
return {
text: result.text,
responses: result.response.messages,
Expand Down
2 changes: 1 addition & 1 deletion src/agent/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class Anthropic implements ChatAgent {
options.errorExtractor = function (data: any) {
return data?.error?.message;
};
return convertStringToResponseMessages(requestChatCompletions(url, header, body, onStream, null, options));
return convertStringToResponseMessages(requestChatCompletions(url, header, body, onStream, options));
};

readonly modelList = async (context: AgentUserConfig): Promise<string[]> => {
Expand Down
2 changes: 1 addition & 1 deletion src/agent/cohere.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Cohere implements ChatAgent {
options.errorExtractor = function (data: any) {
return data?.message;
};
return convertStringToResponseMessages(requestChatCompletions(url, header, body, onStream, null, options));
return convertStringToResponseMessages(requestChatCompletions(url, header, body, onStream, options));
};

readonly modelList = async (context: AgentUserConfig): Promise<string[]> => {
Expand Down
10 changes: 2 additions & 8 deletions src/agent/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function streamHandler<T>(stream: AsyncIterable<T>, contentExtracto
return contentFull;
}

export async function requestChatCompletions(url: string, header: Record<string, string>, body: any, onStream: ChatStreamTextHandler | null, onResult: ChatStreamTextHandler | null = null, options: SseChatCompatibleOptions | null = null): Promise<string> {
export async function requestChatCompletions(url: string, header: Record<string, string>, body: any, onStream: ChatStreamTextHandler | null, options: SseChatCompatibleOptions | null = null): Promise<string> {
const controller = new AbortController();
const { signal } = controller;

Expand Down Expand Up @@ -112,11 +112,5 @@ export async function requestChatCompletions(url: string, header: Record<string,
throw new Error(options.errorExtractor?.(result) || 'Unknown error');
}

try {
await onResult?.(result);
return options.fullContentExtractor?.(result) || '';
} catch (e) {
console.error(e);
throw new Error(JSON.stringify(result));
}
return options.fullContentExtractor?.(result) || '';
}
2 changes: 1 addition & 1 deletion src/agent/workersai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class WorkersChat extends WorkerBase implements ChatAgent {
options.errorExtractor = function (data: any) {
return data?.errors?.at(0)?.message;
};
return convertStringToResponseMessages(requestChatCompletions(url, header, body, onStream, null, options));
return convertStringToResponseMessages(requestChatCompletions(url, header, body, onStream, options));
};

readonly modelList = async (context: AgentUserConfig): Promise<string[]> => {
Expand Down
4 changes: 2 additions & 2 deletions src/config/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const BUILD_TIMESTAMP = 1731399467;
export const BUILD_VERSION = '926f2b5';
export const BUILD_TIMESTAMP = 1731402552;
export const BUILD_VERSION = 'e1a0489';

0 comments on commit 4d75571

Please sign in to comment.