Skip to content

Commit

Permalink
Playground and OpenAI models
Browse files Browse the repository at this point in the history
  • Loading branch information
hejny committed May 15, 2024
1 parent 4a17d13 commit 4d044f7
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 11 deletions.
6 changes: 6 additions & 0 deletions .vscode/terminals.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@
"onlySingle": true,
"focus": false
},
{
"name": "🧸 Playground",
"command": "ts-node ./other/playground/playground.ts",
"onlySingle": true,
"focus": true
},
{
"name": "🔼👑 Release major version",
"command": "npm version major",
Expand Down
45 changes: 45 additions & 0 deletions other/playground/playground.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env ts-node

import * as dotenv from 'dotenv';

dotenv.config({ path: '.env' });

import chalk from 'colors';
import { join } from 'path';
import { OpenAiExecutionTools } from '../../src/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools';

if (process.cwd() !== join(__dirname, '../..')) {
console.error(chalk.red(`CWD must be root of the project`));
process.exit(1);
}

playground()
.catch((error) => {
console.error(chalk.bgRed(error.name || 'NamelessError'));
console.error(error);
process.exit(1);
})
.then(() => {
process.exit(0);
});

async function playground() {
console.info(`🧸 Playground`);

// Do here stuff you want to test
//========================================>

const openAiExecutionTools = new OpenAiExecutionTools({
// TODO: [♐] Pick just the best model of required variant
isVerbose: true,
apiKey: process.env.OPENAI_API_KEY,
});

const models = await openAiExecutionTools.listModels();

console.info({ models });

//========================================/

console.info(`[ Done 🧸 Playground ]`);
}
19 changes: 19 additions & 0 deletions other/playground/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"downlevelIteration": true,
"allowJs": true,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"experimentalDecorators": true,
"noUnusedLocals": false,
"resolveJsonModule": true,
"esModuleInterop": true
},
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion samples/usage/logging/logging.ts.todo
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function main() {
const tools = {
llm: new OpenAiExecutionTools({
isVerbose: true,
openAiApiKey: process.env.OPENAI_API_KEY,
apiKey: process.env.OPENAI_API_KEY,
}),
script: [
new JavascriptEvalExecutionTools({
Expand Down
2 changes: 1 addition & 1 deletion samples/usage/remote/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function main() {
return new OpenAiExecutionTools({
// TODO: [♐] Pick just the best model of required variant
isVerbose: true,
openAiApiKey: process.env.OPENAI_API_KEY!,
apiKey: process.env.OPENAI_API_KEY!,
user: clientId,
});
},
Expand Down
2 changes: 1 addition & 1 deletion samples/usage/simple-script/simple-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function main() {
llm: new OpenAiExecutionTools({
// TODO: [♐] Pick just the best model of required variant
isVerbose: true,
openAiApiKey: process.env.OPENAI_API_KEY,
apiKey: process.env.OPENAI_API_KEY,
}),
script: [
new JavascriptEvalExecutionTools({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import colors from 'colors';
import OpenAI from 'openai';
import type { Promisable } from 'type-fest';
import { PromptbookExecutionError } from '../../../../errors/PromptbookExecutionError';
import type { Prompt } from '../../../../types/Prompt';
import type { string_date_iso8601 } from '../../../../types/typeAliases';
Expand Down Expand Up @@ -179,24 +178,267 @@ export class OpenAiExecutionTools implements LlmExecutionTools {
/**
* List all available OpenAI models that can be used
*/
public listModels(): Promisable<Array<AvailableModel>> {
public listModels(): Array<AvailableModel> {
/*
Note: Dynamic lising of the models
const models = await this.openai.models.list({});
console.log({ models });
console.log(models.data);
*/

return [
// TODO: !!!! [🕚] Make this list dynamic
// Note: Done at 2024-05-15
// TODO: [🕚] Make this list dynamic - dynamically can be listed modelNames but not modelVariant, legacy status, context length and pricing
// @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
// @see https://openai.com/api/pricing/
// @see /other/playground/playground.ts


/*/
{
modelTitle: 'dall-e-3',
modelName: 'dall-e-3',
},
/**/

/*/
{
modelTitle: 'whisper-1',
modelName: 'whisper-1',
},
/**/

/**/
{
modelTitle: 'GPT 3.5 Turbo',
modelName: 'gpt-3.5-turbo',
modelVariant: 'COMPLETION',
modelTitle: 'davinci-002',
modelName: 'davinci-002',
},
/**/

/*/
{
modelTitle: 'dall-e-2',
modelName: 'dall-e-2',
},
/**/

/**/
{
modelVariant: 'CHAT',
modelTitle: 'gpt-3.5-turbo-16k',
modelName: 'gpt-3.5-turbo-16k',
},
/**/

/*/
{
modelTitle: 'tts-1-hd-1106',
modelName: 'tts-1-hd-1106',
},
/**/

/*/
{
modelTitle: 'tts-1-hd',
modelName: 'tts-1-hd',
},
/**/

/**/
{
modelVariant: 'CHAT',
modelTitle: 'gpt-4',
modelName: 'gpt-4',
},
/**/

/**/
{
modelVariant: 'CHAT',
modelTitle: 'gpt-4-0613',
modelName: 'gpt-4-0613',
},
/**/

/**/
{
modelVariant: 'CHAT',
modelTitle: 'gpt-4-turbo-2024-04-09',
modelName: 'gpt-4-turbo-2024-04-09',
},
/**/

/**/
{
modelTitle: 'GPT 4 Turbo',
modelVariant: 'CHAT',
modelTitle: 'gpt-3.5-turbo-1106',
modelName: 'gpt-3.5-turbo-1106',
},
/**/

/**/
{
modelVariant: 'CHAT',
modelTitle: 'gpt-4-turbo',
modelName: 'gpt-4-turbo',
},
/**/

/**/
{
modelVariant: 'COMPLETION',
modelTitle: 'gpt-3.5-turbo-instruct-0914',
modelName: 'gpt-3.5-turbo-instruct-0914',
},
/**/

/**/
{
modelVariant: 'COMPLETION',
modelTitle: 'gpt-3.5-turbo-instruct',
modelName: 'gpt-3.5-turbo-instruct',
},
/**/

/*/
{
modelTitle: 'tts-1',
modelName: 'tts-1',
},
/**/

/**/
{
modelVariant: 'CHAT',
modelTitle: 'gpt-3.5-turbo',
modelName: 'gpt-3.5-turbo',
},
/**/

/**/
{
modelVariant: 'CHAT',
modelTitle: 'gpt-3.5-turbo-0301',
modelName: 'gpt-3.5-turbo-0301',
},
/**/

/**/
{
modelVariant: 'COMPLETION',
modelTitle: 'babbage-002',
modelName: 'babbage-002',
},
/**/

/**/
{
modelVariant: 'CHAT',
modelTitle: 'gpt-4-1106-preview',
modelName: 'gpt-4-1106-preview',
},
/**/

/**/
{
modelVariant: 'CHAT',
modelTitle: 'gpt-4-0125-preview',
modelName: 'gpt-4-0125-preview',
},
/**/

/*/
{
modelTitle: 'tts-1-1106',
modelName: 'tts-1-1106',
},
/**/

/**/
{
modelVariant: 'CHAT',
modelTitle: 'gpt-3.5-turbo-0125',
modelName: 'gpt-3.5-turbo-0125',
},
/**/

/**/
{
modelVariant: 'CHAT',
modelTitle: 'gpt-4-turbo-preview',
modelName: 'gpt-4-turbo-preview',
},
/**/

/*/
{
modelTitle: 'GPT 4o',
modelTitle: 'text-embedding-3-large',
modelName: 'text-embedding-3-large',
},
/**/

/*/
{
modelTitle: 'text-embedding-3-small',
modelName: 'text-embedding-3-small',
},
/**/

/**/
{
modelVariant: 'CHAT',
modelTitle: 'gpt-3.5-turbo-0613',
modelName: 'gpt-3.5-turbo-0613',
},
/**/

/*/
{
modelTitle: 'text-embedding-ada-002',
modelName: 'text-embedding-ada-002',
},
/**/

/*/
{
modelVariant: 'CHAT',
modelTitle: 'gpt-4-1106-vision-preview',
modelName: 'gpt-4-1106-vision-preview',
},
/**/

/*/
{
modelTitle: 'gpt-4-vision-preview',
modelName: 'gpt-4-vision-preview',
},
/**/

/**/
{
modelVariant: 'CHAT',
modelTitle: 'gpt-4o-2024-05-13',
modelName: 'gpt-4o-2024-05-13',
},
/**/

/**/
{
modelVariant: 'CHAT',
modelTitle: 'gpt-4o',
modelName: 'gpt-4o',
},
/**/

/**/
{
modelVariant: 'CHAT',
modelTitle: 'gpt-3.5-turbo-16k-0613',
modelName: 'gpt-3.5-turbo-16k-0613',
},
/**/
];
}
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
"declaration": true,
"outDir": "typings"
},
"include": ["src"]
"include": ["src", "other/playground/playground.ts"]
}

0 comments on commit 4d044f7

Please sign in to comment.