@langchain/community
Version:
Third-party integrations for LangChain.js
1 lines • 2.6 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","names":["BaseWebSocketStream","WebSocket","BaseChatIflytekXinghuo"],"sources":["../../../src/chat_models/iflytek_xinghuo/index.ts"],"sourcesContent":["import WebSocket from \"ws\";\nimport { BaseChatIflytekXinghuo } from \"./common.js\";\nimport {\n BaseWebSocketStream,\n WebSocketStreamOptions,\n} from \"../../utils/iflytek_websocket_stream.js\";\n\nclass WebSocketStream extends BaseWebSocketStream {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n openWebSocket(url: string, options: WebSocketStreamOptions): WebSocket {\n return new WebSocket(url, options.protocols ?? []);\n }\n}\n\n/**\n * @example\n * ```typescript\n * const model = new ChatIflytekXinghuo();\n * const response = await model.invoke([new HumanMessage(\"Nice to meet you!\")]);\n * console.log(response);\n * ```\n */\nexport class ChatIflytekXinghuo extends BaseChatIflytekXinghuo {\n async openWebSocketStream<WebSocketStream>(\n options: WebSocketStreamOptions\n ): Promise<WebSocketStream> {\n const host = \"spark-api.xf-yun.com\";\n const date = new Date().toUTCString();\n const url = `GET /${this.version}/chat HTTP/1.1`;\n const { createHmac } = await import(\"node:crypto\");\n const hash = createHmac(\"sha256\", this.iflytekApiSecret)\n .update(`host: ${host}\\ndate: ${date}\\n${url}`)\n .digest(\"base64\");\n const authorization_origin = `api_key=\"${this.iflytekApiKey}\", algorithm=\"hmac-sha256\", headers=\"host date request-line\", signature=\"${hash}\"`;\n const authorization = Buffer.from(authorization_origin).toString(\"base64\");\n let authWebSocketUrl = this.apiUrl;\n authWebSocketUrl += `?authorization=${authorization}`;\n authWebSocketUrl += `&host=${encodeURIComponent(host)}`;\n authWebSocketUrl += `&date=${encodeURIComponent(date)}`;\n return new WebSocketStream(authWebSocketUrl, options) as WebSocketStream;\n }\n}\n"],"mappings":";;;;;;;;AAOA,IAAM,kBAAN,cAA8BA,iCAAAA,oBAAoB;CAGhD,cAAc,KAAa,SAA4C;AACrE,SAAO,IAAIC,GAAAA,QAAU,KAAK,QAAQ,aAAa,EAAE,CAAC;;;;;;;;;;;AAYtD,IAAa,qBAAb,cAAwCC,eAAAA,uBAAuB;CAC7D,MAAM,oBACJ,SAC0B;EAC1B,MAAM,OAAO;EACb,MAAM,wBAAO,IAAI,MAAM,EAAC,aAAa;EACrC,MAAM,MAAM,QAAQ,KAAK,QAAQ;EACjC,MAAM,EAAE,eAAe,MAAM,OAAO;EACpC,MAAM,OAAO,WAAW,UAAU,KAAK,iBAAiB,CACrD,OAAO,SAAS,KAAK,UAAU,KAAK,IAAI,MAAM,CAC9C,OAAO,SAAS;EACnB,MAAM,uBAAuB,YAAY,KAAK,cAAc,2EAA2E,KAAK;EAC5I,MAAM,gBAAgB,OAAO,KAAK,qBAAqB,CAAC,SAAS,SAAS;EAC1E,IAAI,mBAAmB,KAAK;AAC5B,sBAAoB,kBAAkB;AACtC,sBAAoB,SAAS,mBAAmB,KAAK;AACrD,sBAAoB,SAAS,mBAAmB,KAAK;AACrD,SAAO,IAAI,gBAAgB,kBAAkB,QAAQ"}