Skip to content

Solirius/pins-ai-template-a

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Single Prompt with Structured Output (TypeScript/LangChain)

This template processes a variable list of file paths with one external prompt and one Zod schema. For each processed file, it emits one JSON line that contains the structured output from the model (based on the schema) and the input file path

What this demo does

The included example prompt and schema ask the model to return:

  1. Whether the decision is dismissed or upheld
  2. The principal reason in brief (maximum three sentences)
  3. The case reference number

Requirements

  • Node.js 22+
  • An Azure OpenAI deployment
  • Azure authentication via managed identity (or API key)

Environment variables

Set these before running:

  • AZURE_OPENAI_ENDPOINT
  • AZURE_OPENAI_API_VERSION

Example:

export AZURE_OPENAI_ENDPOINT=https://swedencentral.api.cognitive.microsoft.com/
export AZURE_OPENAI_API_VERSION=2024-12-01-preview

Note that these values are set in the .env.example which should be copied to .env and updated with your actual values if needed.

Install

npm install

Run

npm run start -- \
  --deployment <azure_deployment_name> \
  --prompt example/decision.prompt.md \
  --schema example/decision.schema.ts \
  123456.txt

Schema flag supports both forms:

  • --schema <path> to load the module default export
  • --schema <path>#<exportName> to load a named export

The command writes one JSON object per line to stdout.

Input file paths can be plain text (for example .txt), Word documents (.doc / .docx), or PDF documents (.pdf).

Generic extension points

  • Replace example/decision.prompt.md with your own text file that contains the prompt.
  • Replace example/decision.schema.ts with any module that exports a Zod schema that aligns with your prompt.

About

Single Prompt with Structured Output (TypeScript/LangChain)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors