06LLM DEEPSEEK_API_KEY

Chat

Call DeepSeek directly and inside a pipeline.

flowchart LR
  P([prompt]) -- prompt --> L[Deepseek] -- completion --> A([answer])

What it shows

  • run(text) returns text; chatCompletion(messages) returns an assistant message.
  • In a pipeline the model reads prompt or messages and writes completion or message.

The program

examples/chat/index.ts
import { Pipeline } from '@astack-tech/core';
import { ModelProvider } from '@astack-tech/integrations';

const apiKey = process.env['DEEPSEEK_API_KEY'];
if (!apiKey) {
  throw new Error('Set DEEPSEEK_API_KEY to run this example.');
}

const model = new ModelProvider.Deepseek({ apiKey, systemPrompt: 'Answer in one sentence.' });

// Standalone: a prompt in, text out.
console.log(await model.run('What is flow-based programming?'));

// Standalone: a conversation in, an assistant message out.
const reply = await model.chatCompletion([
  { role: 'user', content: 'Name one benefit of small components.' },
]);
console.log(reply.content);

// In a pipeline: the model reads `prompt` and writes `completion`.
const pipeline = new Pipeline();
pipeline.addComponent('llm', model);
console.log(await pipeline.run<string>('llm.prompt', 'What is a port?', 'llm.completion'));

Run it

pnpm install && pnpm build

export DEEPSEEK_API_KEY=sk-...
pnpm --filter @astack-examples/chat start
CONCEPTModel providersCall DeepSeek, and write a provider for any other model.View the folder on GitHub