Skip to content

Commit

Permalink
fix: only mock the fetch function when necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
adolphnov committed Nov 10, 2024
1 parent 77a9802 commit f9960eb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 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.

13 changes: 7 additions & 6 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.

9 changes: 5 additions & 4 deletions src/agent/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ export class OpenAI extends OpenAIBase implements ChatAgent {
};

readonly request = async (params: LLMChatParams, context: AgentUserConfig, onStream: ChatStreamTextHandler | null): Promise<ResponseMessage[]> => {
const userMessage = params.messages.at(-1) as CoreUserMessage;
const originalModel = this.model(context, userMessage);
const transformedModel = this.transformModel(originalModel, context);
const provider = createOpenAI({
baseURL: context.OPENAI_API_BASE,
apiKey: this.apikey(context),
compatibility: 'strict',
fetch: this.fetch,
fetch: originalModel === transformedModel ? undefined : this.fetch,
});

const userMessage = params.messages.at(-1) as CoreUserMessage;
const originalModel = this.model(context, userMessage);
const languageModelV1 = provider.languageModel(this.transformModel(originalModel, context), undefined);
const languageModelV1 = provider.languageModel(transformedModel, undefined);
const { messages, onStream: newOnStream } = this.extraHandle(originalModel, params.messages, context, onStream);

return requestChatCompletionsV2(await warpLLMParams({
Expand Down
1 change: 0 additions & 1 deletion src/telegram/utils/md2tgmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export function escape(text: string): string {
}
const regexp = /^LOGSTART\s(.*?)LOGEND/s;
return result.join('\n')
// extra \n to avoid markdown render error
.replace(regexp, '**$1||')
.replace(new RegExp(Object.values(escapedChars).join('|'), 'g'), match => escapedCharsReverseMap.get(match) ?? match);
}
Expand Down

0 comments on commit f9960eb

Please sign in to comment.