Skip to content

picahq/ai-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pica AI SDK

Pica AI SDK is a TypeScript library that allows you to integrate with Pica's AI platform.

Installation

npm install @picahq/ai

Setup

  1. Create a new Pica account at Pica
  2. Create a Pica API key at Pica
  3. Set the API key as an environment variable: PICA_SECRET_KEY=<your-api-key>
  4. Set the OpenAI API key as an environment variable: OPENAI_API_KEY=<your-openai-api-key>

Usage

Here's a basic example of how to use the SDK:

import { openai } from "@ai-sdk/openai";
import { convertToCoreMessages, streamText } from "ai";
import { Pica } from "@picahq/ai";

export async function POST(request: Request) {
  const { messages } = await request.json();

  const pica = new Pica(process.env.PICA_SECRET_KEY as string);

  const systemPrompt = await pica.generateSystemPrompt();

  const stream = streamText({
    model: openai("gpt-4"),
    system: systemPrompt,
    tools: { ...pica.oneTool },
    messages: convertToCoreMessages(messages),
    maxSteps: 5,
  });

  return (await stream).toDataStreamResponse();
}