UNPKG

@sap-ai-sdk/langchain

Version:

SAP Cloud SDK for AI is the official Software Development Kit (SDK) for **SAP AI Core**, **SAP Generative AI Hub**, and **Orchestration Service**.

42 lines 1.62 kB
import { AzureOpenAiChatClient as AzureOpenAiChatClientBase } from '@sap-ai-sdk/foundation-models'; import { BaseChatModel } from '@langchain/core/language_models/chat_models'; import { mapLangchainToAiClient, mapOutputToChatResult } from './util.js'; /** * LangChain chat client for Azure OpenAI consumption on SAP BTP. */ export class AzureOpenAiChatClient extends BaseChatModel { temperature; top_p; logit_bias; user; presence_penalty; frequency_penalty; stop; max_tokens; openAiChatClient; constructor(fields, destination) { super(fields); this.openAiChatClient = new AzureOpenAiChatClientBase(fields, destination); this.temperature = fields.temperature; this.top_p = fields.top_p; this.logit_bias = fields.logit_bias; this.user = fields.user; this.stop = fields.stop; this.presence_penalty = fields.presence_penalty; this.frequency_penalty = fields.frequency_penalty; this.max_tokens = fields.max_tokens; } _llmType() { return 'azure_openai'; } async _generate(messages, options, runManager) { const res = await this.caller.callWithOptions({ signal: options.signal }, () => this.openAiChatClient.run(mapLangchainToAiClient(this, messages, options), options.requestConfig)); const content = res.getContent(); // we currently do not support streaming await runManager?.handleLLMNewToken(typeof content === 'string' ? content : ''); return mapOutputToChatResult(res.data); } } //# sourceMappingURL=chat.js.map