npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sassoftware/gpt-samples

v2.1.0

Published

Examples of integrating gpt prompts into SAS Viya apps

Downloads

7

Readme

Examples of integrating gpt into SAS Viya apps

This repository contains examples of integrating gpt into application targeting SAS Viya.

The examples use gpt-4 with functions. Many of the functions use @sassoftware/restaf, @sassoftware/restaflib and @sassoftware/restafedit to make REST API calls to SAS Viya.

image info

The functions are small and easy to follow. Feel free to change these to suit own programming style.

The code is in https://github.com/sassoftware/restaf-demos/tree/gpt-samples


Table of Contents


---;

Data Points


  1. gpt-4 model is the default openai model.
    • OPENAI_MODEL - To change the model, set this enviroment variable to the desired model.
  2. It is the user's reponsibility to get the api key for openai.
    • The samples assume that the key is available as environment variable OPENAI_KEY
  3. Most examples make use of SAS REST API to access SAS Viya. The applications use @sassoftware/restaf, @sassoftware/restaflib and @sassoftware/restafedit to make these calls. See https://sassoftware.github.io/restaf/ for more information.
  4. The source code in this repository is provided under Apache-2.0 licensing model

Authentication

Please sas-cli auth login|logCode to setup authentication token.

Environment Variables

  • OPENAI_KEY - Set this to the api key from openai
  • OPENAI_MODEL - (optional) set to the model you want to use(defaults to gpt-4)
  • VIYASOURCE - set this to either cas, compute or none. Defaults to cas. Used in prompts that access Viya resources. The 'none' value is useful if you want to use this cli as a standard chat without accessing Viya.

Running as a cli


After setting the environment variables listed above, start the application as follows:

npx @sassoftware/gpt-samples@latest

On the prompt, enter chat to start the gpt session

Enter help to get guidance on what is possible

The gpt session will stay active until you enter exit

To exit the cli enter exit again.

Installation and Setup

The instruction below is for those users who wish to clone the code and extend the application.

  • git clone https://github.com/sassoftware/restaf-demos gpt-samples -b gpt-samples
  • cd gpt-samples
  • npm install
  • Define the environment variables described below

Getting started - Basic example

This example demonstrates setting up access to gpt and defining a function called basic. This function's sole purpose is to reformat user provided keywords as html, array or JavaScript object. The code is in ./packages/basic/index.js

Usage

npm run basic <some text>

Some sample prompt and results:

npm run basic what is SAS Viya

SAS Viya is a cloud-based, in-memory analytics engine from SAS Institute, an American multinational developer of analytics software. SAS Viya provides quick, accurate results and reveals valuable insights from large amounts of data. It's capable of machine learning, text analytics, forecasting, optimization, and statistics. It can be used through a variety of programming languages including Python, R, Java, and Lua, or through its visual interface.

npm run basic keywords

Sure, can you provide me with the keywords you want to process?

npm run basic keywords a,b,c as array

[ 'a', 'b', 'c' ]

npm run basic keywords a,b,c as html


<ul><li>a</li><li>b</li><li>c</li></ul>

Example with access to Viya

This is similar to the previous example The basic function now executes SAS code or casl code.

The prompt should look something like this:


run file path to your .sas file or .casl file

The following starter files are included. Use .sas files if env VIYASOURCE is set to compute

  • ../../programs/echo.casl
  • ../../programs/datastep.casl
  • ../../programs/datastep.sas

Usage for SAS example

npm run basicSAS "run file <some path>"

run file ../programs/datastep.casl

{
    "casResults": {
        "result": {
            "Fetch": {
                "_ctb": true,
                "attributes": {
                    "Action": {
                        "type": "string",
                        "value": "fetch"
                    },
                    "Actionset": {
                        "type": "string",
                        "value": "table"
                    },
                    "CreateTime": {
                        "type": "double",
                        "value": 2022787095.92428
                    }
                },
                "label": "Selected Rows from Table A",
                "name": "Fetch",
                "rows": [
                    [
                        1,
                        1
                    ]
                ],
                "schema": [
                    {
                        "attributes": {},
                        "format": "",
                        "label": "",
                        "name": "_Index_",
                        "type": "int",
                        "width": 8
                    },
                    {
                        "attributes": {},
                        "format": "",
                        "label": "",
                        "name": "x",
                        "type": "double",
                        "width": 8
                    }
                ],
                "title": "Selected Rows from Table A"
            }
        }
    }
}

run file ../programs/datastep.sas

Make sure the env variable VIYASOURCE is set to compute.

[
    {
        "line": "1    options NOSYNTAXCHECK OBS=MAX;%let syscc=0;",
        "type": "source",
        "version": 1
    },
    {
        "line": "2    data a;",
        "type": "source",
        "version": 1
    },
    {
        "line": "3      x=1;",
        "type": "source",
        "version": 1
    },
    {
        "line": "4    run;",
        "type": "source",
        "version": 1
    },
    {
        "line": "",
        "type": "note",
        "version": 1
    },
    {
        "line": "NOTE: The data set WORK.A has 1 observations and 1 variables.",
        "type": "note",
        "version": 1
    },
    {
        "line": "NOTE: DATA statement used (Total process time):",
        "type": "note",
        "version": 1
    },
    {
        "line": "      real time           0.00 seconds",
        "type": "note",
        "version": 1
    },
    {
        "line": "      cpu time            0.00 seconds",
        "type": "note",
        "version": 1
    },
    {
        "line": "      ",
        "type": "note",
        "version": 1
    },
    {
        "line": "",
        "type": "note",
        "version": 1
    },
    {
        "line": "5    ",
        "type": "source",
        "version": 1
    },
    {
        "line": "6    proc print; run;",
        "type": "source",
        "version": 1
    },
    {
        "line": "",
        "type": "note",
        "version": 1
    },
    {
        "line": "NOTE: There were 1 observations read from the data set WORK.A.",
        "type": "note",
        "version": 1
    },
    {
        "line": "NOTE: The PROCEDURE PRINT printed page 1.",
        "type": "note",
        "version": 1
    },
    {
        "line": "NOTE: PROCEDURE PRINT used (Total process time):",
        "type": "note",
        "version": 1
    },
    {
        "line": "      real time           0.05 seconds",
        "type": "note",
        "version": 1
    },
    {
        "line": "      cpu time            0.06 seconds",
        "type": "note",
        "version": 1
    },
    {
        "line": "      ",
        "type": "note",
        "version": 1
    },
    {
        "line": "",
        "type": "note",
        "version": 1
    },
    {
        "line": "7    ",
        "type": "source",
        "version": 1
    },
    {
        "line": "8    ;",
        "type": "source",
        "version": 1
    },
    {
        "line": "",
        "type": "note",
        "version": 1
    }
]