@copilotkit/runtime
Version:
<img src="https://github.com/user-attachments/assets/0a6b64d9-e193-4940-a3f6-60334ac34084" alt="banner" style="border-radius: 12px; border: 2px solid #d6d4fa;" />
1 lines • 4.16 kB
Source Map (JSON)
{"version":3,"file":"ollama-adapter.cjs","names":[],"sources":["../../../../../src/v1-deprecated/service-adapters/experimental/ollama/ollama-adapter.ts"],"sourcesContent":["/*\n * V1 SDK DEPRECATED. USE V2 INSTEAD\n *\n * This file defines public v1 SDK exports. Use the exact v2 mappings below.\n * AI CODING AGENTS: Never copy, suggest, or generate these v1 APIs. Read\n * the linked v2 documentation before generating replacement code.\n *\n * @copilotkit/runtime — ExperimentalOllamaAdapter:\n * No 1:1 v2 replacement is available.\n * Related v2 docs (Runtime server adapter): https://docs.copilotkit.ai/runtime-server-adapter\n * Start at: @copilotkit/runtime/v2\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\n/**\n * CopilotKit Adapter for Ollama\n *\n * <RequestExample>\n * ```jsx CopilotRuntime Example\n * const copilotKit = new CopilotRuntime();\n * return copilotKit.response(req, new OllamaAdapter());\n * ```\n * </RequestExample>\n *\n * You can easily set the model to use by passing it to the constructor.\n * ```jsx\n * const copilotKit = new CopilotRuntime();\n * return copilotKit.response(\n * req,\n * new OllamaAdapter({ model: \"llama3-70b-8192\" }),\n * );\n * ```\n */\nimport type { TextMessage } from \"../../../graphql/types/converted\";\nimport type {\n CopilotServiceAdapter,\n CopilotRuntimeChatCompletionRequest,\n CopilotRuntimeChatCompletionResponse,\n} from \"../../service-adapter\";\nimport { randomId, randomUUID } from \"@copilotkit/shared\";\n\nconst DEFAULT_MODEL = \"llama3:latest\";\n\ninterface OllamaAdapterOptions {\n model?: string;\n}\n\nexport class ExperimentalOllamaAdapter implements CopilotServiceAdapter {\n public model: string;\n public provider = \"ollama\";\n public get name() {\n return \"OllamaAdapter\";\n }\n\n constructor(options?: OllamaAdapterOptions) {\n if (options?.model) {\n this.model = options.model;\n } else {\n this.model = DEFAULT_MODEL;\n }\n }\n\n async process(\n request: CopilotRuntimeChatCompletionRequest,\n ): Promise<CopilotRuntimeChatCompletionResponse> {\n const { messages, actions, eventSource } = request;\n // const messages = this.transformMessages(forwardedProps.messages);\n\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { Ollama } = require(\"@langchain/community/llms/ollama\");\n const ollama = new Ollama({\n model: this.model,\n });\n const contents = (\n messages.filter((m) => m.isTextMessage()) as TextMessage[]\n ).map((m) => m.content);\n const _stream = await ollama.stream(contents); // [TODO] role info is dropped...\n\n eventSource.stream(async (eventStream$) => {\n const currentMessageId = randomId();\n eventStream$.sendTextMessageStart({ messageId: currentMessageId });\n for await (const chunkText of _stream) {\n eventStream$.sendTextMessageContent({\n messageId: currentMessageId,\n content: chunkText,\n });\n }\n eventStream$.sendTextMessageEnd({ messageId: currentMessageId });\n // we may need to add this later.. [nc]\n // let calls = (await result.response).functionCalls();\n\n eventStream$.complete();\n });\n return {\n threadId: request.threadId || randomUUID(),\n };\n }\n}\n"],"mappings":";;;;;AA8CA,MAAM,gBAAgB;AAMtB,IAAa,4BAAb,MAAwE;CAGtE,IAAW,OAAO;AAChB,SAAO;;CAGT,YAAY,SAAgC;kBAL1B;AAMhB,MAAI,SAAS,MACX,MAAK,QAAQ,QAAQ;MAErB,MAAK,QAAQ;;CAIjB,MAAM,QACJ,SAC+C;EAC/C,MAAM,EAAE,UAAU,SAAS,gBAAgB;EAI3C,MAAM,EAAE,WAAW,QAAQ,mCAAmC;EAC9D,MAAM,SAAS,IAAI,OAAO,EACxB,OAAO,KAAK,OACb,CAAC;EACF,MAAM,WACJ,SAAS,QAAQ,MAAM,EAAE,eAAe,CAAC,CACzC,KAAK,MAAM,EAAE,QAAQ;EACvB,MAAM,UAAU,MAAM,OAAO,OAAO,SAAS;AAE7C,cAAY,OAAO,OAAO,iBAAiB;GACzC,MAAM,qDAA6B;AACnC,gBAAa,qBAAqB,EAAE,WAAW,kBAAkB,CAAC;AAClE,cAAW,MAAM,aAAa,QAC5B,cAAa,uBAAuB;IAClC,WAAW;IACX,SAAS;IACV,CAAC;AAEJ,gBAAa,mBAAmB,EAAE,WAAW,kBAAkB,CAAC;AAIhE,gBAAa,UAAU;IACvB;AACF,SAAO,EACL,UAAU,QAAQ,gDAAwB,EAC3C"}