Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Ai Ml Integration

ASecurity

AI/ML APIs, LLM integration, and intelligent application patterns

3 stars
0 votes
0 copies
1 views
Added 9/7/2026
ai-agentstypescriptgoapidatabasefrontendbackendperformance

Works with

cliapi

Security Analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned 9/7/2026

$npx -y skills add levalencia/agent-god-mode --skill ai-ml-integration --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ai Ml Integration?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Ai Ml Integration
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/levalencia-ai-ml-integration/badge)](https://www.skillsdirectory.com/skills/levalencia-ai-ml-integration)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: ai-ml-integration
description: AI/ML APIs, LLM integration, and intelligent application patterns
domain: development-stacks
version: 1.0.0
tags: [openai, anthropic, langchain, embeddings, rag, vector-db]
triggers:
  keywords:
    primary: [ai, ml, llm, openai, anthropic, langchain, embedding, rag]
    secondary: [vector database, pinecone, chromadb, prompt engineering, agent, gpt]
  context_boost: [intelligent, chatbot, nlp, machine learning]
  context_penalty: [frontend, css, ui, database]
  priority: high
---

# AI/ML Integration

## Overview

Integrating AI and machine learning capabilities into applications, including LLM APIs, embeddings, and RAG patterns.

---

## LLM Integration

### OpenAI API

```typescript
import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

// Chat completion
async function chat(messages: Array<{ role: string; content: string }>) {
  const response = await openai.chat.completions.create({
    model: 'gpt-4o',
    messages,
    temperature: 0.7,
    max_tokens: 1000,
  });

  return response.choices[0].message.content;
}

// Streaming response
async function* streamChat(prompt: string) {
  const stream = await openai.chat.completions.create({
    model: 'gpt-4o',
    messages: [{ role: 'user', content: prompt }],
    stream: true,
  });

  for await (const chunk of stream) {
    const content = chunk.choices[0]?.delta?.content;
    if (content) {
      yield content;
    }
  }
}

// Function calling
async function chatWithTools(message: string) {
  const tools = [
    {
      type: 'function' as const,
      function: {
        name: 'get_weather',
        description: 'Get current weather for a location',
        parameters: {
          type: 'object',
          properties: {
            location: { type: 'string', description: 'City name' },
            unit: { type: 'string', enum: ['celsius', 'fahrenheit'] },
          },
          required: ['location'],
        },
      },
    },
  ];

  const response = await openai.chat.completions.create({
    model: 'gpt-4o',
    messages: [{ role: 'user', content: message }],
    tools,
    tool_choice: 'auto',
  });

  const toolCall = response.choices[0].message.tool_calls?.[0];
  if (toolCall) {
    const args = JSON.parse(toolCall.function.arguments);
    // Execute the function
    const result = await executeFunction(toolCall.function.name, args);

    // Continue conversation with function result
    return openai.chat.completions.create({
      model: 'gpt-4o',
      messages: [
        { role: 'user', content: message },
        response.choices[0].message,
        {
          role: 'tool',
          tool_call_id: toolCall.id,
          content: JSON.stringify(result),
        },
      ],
    });
  }

  return response;
}
```

### Anthropic Claude

```typescript
import Anthropic from '@anthropic-ai/sdk';

const anthropic = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

// Basic message
async function chat(prompt: string) {
  const message = await anthropic.messages.create({
    model: 'claude-sonnet-4-20250514',
    max_tokens: 1024,
    messages: [{ role: 'user', content: prompt }],
  });

  return message.content[0].type === 'text' ? message.content[0].text : '';
}

// With system prompt
async function chatWithSystem(system: string, prompt: string) {
  const message = await anthropic.messages.create({
    model: 'claude-sonnet-4-20250514',
    max_tokens: 1024,
    system,
    messages: [{ role: 'user', content: prompt }],
  });

  return message.content[0];
}

// Streaming
async function* streamChat(prompt: string) {
  const stream = anthropic.messages.stream({
    model: 'claude-sonnet-4-20250514',
    max_tokens: 1024,
    messages: [{ role: 'user', content: prompt }],
  });

  for await (const event of stream) {
    if (event.type === 'content_block_delta' && event.delta.type === 'text_delta') {
      yield event.delta.text;
    }
  }
}

// Tool use
async function chatWithTools(prompt: string) {
  const response = await anthropic.messages.create({
    model: 'claude-sonnet-4-20250514',
    max_tokens: 1024,
    tools: [
      {
        name: 'search_database',
        description: 'Search the database for relevant information',
        input_schema: {
          type: 'object',
          properties: {
            query: { type: 'string', description: 'Search query' },
            limit: { type: 'number', description: 'Max results' },
          },
          required: ['query'],
        },
      },
    ],
    messages: [{ role: 'user', content: prompt }],
  });

  // Handle tool use blocks
  for (const block of response.content) {
    if (block.type === 'tool_use') {
      const result = await executeSearch(block.input);
      // Continue with tool result...
    }
  }
}
```

---

## Embeddings

### Text Embeddings

```typescript
import OpenAI from 'openai';

const openai = new OpenAI();

// Generate embeddings
async function getEmbedding(text: string): Promise<number[]> {
  const response = await openai.embeddings.create({
    model: 'text-embedding-3-small',
    input: text,
  });

  return response.data[0].embedding;
}

// Batch embeddings
async function getEmbeddings(texts: string[]): Promise<number[][]> {
  const response = await openai.embeddings.create({
    model: 'text-embedding-3-small',
    input: texts,
  });

  return response.data.map(d => d.embedding);
}

// Cosine similarity
function cosineSimilarity(a: number[], b: number[]): number {
  let dotProduct = 0;
  let normA = 0;
  let normB = 0;

  for (let i = 0; i < a.length; i++) {
    dotProduct += a[i] * b[i];
    normA += a[i] * a[i];
    normB += b[i] * b[i];
  }

  return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
}

// Find similar items
async function findSimilar(query: string, items: Array<{ text: string; embedding: number[] }>, topK = 5) {
  const queryEmbedding = await getEmbedding(query);

  const scored = items.map(item => ({
    ...item,
    score: cosineSimilarity(queryEmbedding, item.embedding),
  }));

  return scored
    .sort((a, b) => b.score - a.score)
    .slice(0, topK);
}
```

### Vector Database (Pinecone)

```typescript
import { Pinecone } from '@pinecone-database/pinecone';

const pinecone = new Pinecone({
  apiKey: process.env.PINECONE_API_KEY,
});

const index = pinecone.index('my-index');

// Upsert vectors
async function upsertDocuments(documents: Document[]) {
  const vectors = await Promise.all(
    documents.map(async (doc) => ({
      id: doc.id,
      values: await getEmbedding(doc.content),
      metadata: {
        title: doc.title,
        source: doc.source,
        content: doc.content.slice(0, 1000), // Store truncated for retrieval
      },
    }))
  );

  await index.upsert(vectors);
}

// Query similar vectors
async function querySimilar(query: string, topK = 5, filter?: object) {
  const queryEmbedding = await getEmbedding(query);

  const results = await index.query({
    vector: queryEmbedding,
    topK,
    includeMetadata: true,
    filter,
  });

  return results.matches.map(match => ({
    id: match.id,
    score: match.score,
    ...match.metadata,
  }));
}
```

---

## RAG (Retrieval-Augmented Generation)

### Basic RAG Pipeline

```typescript
class RAGPipeline {
  constructor(
    private vectorStore: VectorStore,
    private llm: LLM,
    private embeddings: EmbeddingModel
  ) {}

  async query(question: string): Promise<string> {
    // 1. Retrieve relevant documents
    const relevantDocs = await this.retrieve(question);

    // 2. Build context
    const context = this.buildContext(relevantDocs);

    // 3. Generate response with context
    return this.generate(question, context);
  }

  private async retrieve(query: string, topK = 5) {
    const queryEmbedding = await this.embeddings.embed(query);

    return this.vectorStore.similaritySearch(queryEmbedding, topK);
  }

  private buildContext(docs: Document[]): string {
    return docs
      .map((doc, i) => `[Document ${i + 1}]\n${doc.content}`)
      .join('\n\n');
  }

  private async generate(question: string, context: string): Promise<string> {
    const prompt = `Answer the question based on the following context.
If the answer is not in the context, say "I don't have enough information."

Context:
${context}

Question: ${question}

Answer:`;

    return this.llm.generate(prompt);
  }
}
```

### Advanced RAG with Reranking

```typescript
import { CohereClient } from 'cohere-ai';

const cohere = new CohereClient({ token: process.env.COHERE_API_KEY });

class AdvancedRAG {
  async query(question: string): Promise<string> {
    // 1. Initial retrieval (over-fetch)
    const candidates = await this.vectorStore.similaritySearch(question, 20);

    // 2. Rerank with cross-encoder
    const reranked = await this.rerank(question, candidates, 5);

    // 3. Generate with reranked context
    return this.generate(question, reranked);
  }

  private async rerank(query: string, documents: Document[], topK: number) {
    const response = await cohere.rerank({
      model: 'rerank-english-v2.0',
      query,
      documents: documents.map(d => d.content),
      topN: topK,
    });

    return response.results.map(r => documents[r.index]);
  }

  private async generate(question: string, context: Document[]) {
    const systemPrompt = `You are a helpful assistant. Answer questions based on the provided context.
Cite your sources using [1], [2], etc.`;

    const contextText = context
      .map((doc, i) => `[${i + 1}] ${doc.content}`)
      .join('\n\n');

    const response = await openai.chat.completions.create({
      model: 'gpt-4o',
      messages: [
        { role: 'system', content: systemPrompt },
        { role: 'user', content: `Context:\n${contextText}\n\nQuestion: ${question}` },
      ],
    });

    return response.choices[0].message.content;
  }
}
```

---

## LangChain

### Chain Composition

```typescript
import { ChatOpenAI } from '@langchain/openai';
import { StringOutputParser } from '@langchain/core/output_parsers';
import { ChatPromptTemplate } from '@langchain/core/prompts';
import { RunnableSequence } from '@langchain/core/runnables';

const model = new ChatOpenAI({ model: 'gpt-4o' });

// Simple chain
const prompt = ChatPromptTemplate.fromTemplate(
  'Summarize the following text in {style} style:\n\n{text}'
);

const chain = prompt.pipe(model).pipe(new StringOutputParser());

const result = await chain.invoke({
  style: 'professional',
  text: 'Long text to summarize...',
});

// Chain with multiple steps
const analysisChain = RunnableSequence.from([
  ChatPromptTemplate.fromTemplate('Extract key points from:\n{text}'),
  model,
  new StringOutputParser(),
  (keyPoints: string) => ({ keyPoints }),
  ChatPromptTemplate.fromTemplate('Create a summary from these key points:\n{keyPoints}'),
  model,
  new StringOutputParser(),
]);

// Branching chain
const routerChain = RunnableSequence.from([
  ChatPromptTemplate.fromTemplate(
    'Classify this query as either "technical" or "general":\n{query}'
  ),
  model,
  new StringOutputParser(),
  async (classification: string) => {
    if (classification.includes('technical')) {
      return technicalChain.invoke({ query });
    }
    return generalChain.invoke({ query });
  },
]);
```

### Document Loading and Splitting

```typescript
import { PDFLoader } from 'langchain/document_loaders/fs/pdf';
import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter';
import { OpenAIEmbeddings } from '@langchain/openai';
import { PineconeStore } from '@langchain/pinecone';

// Load documents
const loader = new PDFLoader('document.pdf');
const docs = await loader.load();

// Split into chunks
const splitter = new RecursiveCharacterTextSplitter({
  chunkSize: 1000,
  chunkOverlap: 200,
  separators: ['\n\n', '\n', ' ', ''],
});

const chunks = await splitter.splitDocuments(docs);

// Create vector store
const vectorStore = await PineconeStore.fromDocuments(
  chunks,
  new OpenAIEmbeddings(),
  {
    pineconeIndex: index,
    namespace: 'documents',
  }
);

// Create retriever
const retriever = vectorStore.asRetriever({
  k: 5,
  filter: { type: 'technical' },
});
```

---

## Structured Output

```typescript
import { z } from 'zod';
import OpenAI from 'openai';
import { zodResponseFormat } from 'openai/helpers/zod';

const PersonSchema = z.object({
  name: z.string(),
  age: z.number(),
  occupation: z.string(),
  skills: z.array(z.string()),
});

async function extractPerson(text: string) {
  const response = await openai.beta.chat.completions.parse({
    model: 'gpt-4o',
    messages: [
      {
        role: 'system',
        content: 'Extract person information from the text.',
      },
      { role: 'user', content: text },
    ],
    response_format: zodResponseFormat(PersonSchema, 'person'),
  });

  return response.choices[0].message.parsed;
}

// With function calling for complex extraction
const extractionTools = [
  {
    type: 'function' as const,
    function: {
      name: 'extract_entities',
      description: 'Extract named entities from text',
      parameters: {
        type: 'object',
        properties: {
          people: {
            type: 'array',
            items: {
              type: 'object',
              properties: {
                name: { type: 'string' },
                role: { type: 'string' },
              },
            },
          },
          organizations: {
            type: 'array',
            items: { type: 'string' },
          },
          dates: {
            type: 'array',
            items: { type: 'string' },
          },
        },
      },
    },
  },
];
```

---

## Related Skills

- [[system-design]] - AI system architecture
- [[performance-optimization]] - ML inference optimization
- [[backend]] - API integration patterns

Attribution

levalencialevalencia
View sourceSee grades on GitHubMore from levalencia →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman

Terse caveman voice: answer first, fluff gone, every technical fact kept. Use for /caveman, "caveman mode", "talk like caveman", "be brief", "less tokens". Stays on until "stop caveman" or "normal mode".

1100021 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

698461 votes

Writing Skills

Create and manage Claude Code skills in HASH repository following Anthropic best practices. Use when creating new skills, modifying skill-rules.json, understanding trigger patterns, working with hooks, debugging skill activation, or implementing progressive disclosure. Covers skill structure, YAML frontmatter, trigger types (keywords, intent patterns), UserPromptSubmit hook, and the 500-line rule. Includes validation and debugging with SKILL_DEBUG. Examples include rust-error-stack, cargo-dep...

3931 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3421 votes

catchup

Recovers the conversation and failed tool calls of a previous Codex, Amp, Claude Code, Antigravity, Cline, Copilot CLI, Cursor, DeepSeek Harness, Grok Build, Kimi, OpenCode, Pi Agent, or ZCode session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", asks to recover/summarize a previous session before continuing, or asks to diagnose or report a catchup failure. Do NOT use for the current conversation, git history, or any non-agent log.

741 votes
View all in ai-agents →