Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix build issue with example #374

Merged
merged 2 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions examples/salty-ocean-model-comparison/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import rootConfig from "../../eslint.config.mjs";
import examplesConfig from "../eslint.config.mjs";

export default [
...rootConfig,
...examplesConfig,
{
files: ["**/*.{js,mjs,cjs,jsx,ts,tsx}"],
languageOptions: {
parserOptions: {
tsconfigRootDir: import.meta.dirname,
project: "./tsconfig.json",
},
},
},
];
4 changes: 1 addition & 3 deletions examples/salty-ocean-model-comparison/nodemon.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"watch": [
"src"
],
"watch": ["src"],
"ext": ".ts,.tsx",
"exec": "tsx ./src/index.tsx"
}
8 changes: 6 additions & 2 deletions examples/salty-ocean-model-comparison/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "salty-ocean-model-comparison",
"name": "@gensx-examples/salty-ocean-model-comparison",
"private": true,
"version": "0.0.1",
"type": "module",
Expand All @@ -9,7 +9,11 @@
"scripts": {
"dev": "nodemon",
"start": "tsx ./src/index.tsx",
"build": "tsc"
"build": "tsc",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,md}\""
},
"description": "Starter project for [GenSX](https://gensx.com), created using `npx create-gensx`.",
"main": "index.js",
Expand Down
31 changes: 15 additions & 16 deletions examples/salty-ocean-model-comparison/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createOpenAI } from "@ai-sdk/openai";
import { OpenAIContext, OpenAIProvider } from "@gensx/openai";
import { GenerateText } from "@gensx/vercel-ai-sdk";
import { gsx } from "gensx";
import { OpenAIProvider, OpenAIContext } from "@gensx/openai";
import OpenAI from "openai";
import { GenerateText } from "@gensx/vercel-ai-sdk";
import { createOpenAI } from "@ai-sdk/openai";

// Define types for the API provider configuration
interface APIProviderConfig {
Expand All @@ -22,13 +22,13 @@ interface APIProviderRunnerProps {
name: string;
}

type APIProviderRunnerOutput = {
interface APIProviderRunnerOutput {
result: string;
provider: string;
};
type ListModelsOutput = {
}
interface ListModelsOutput {
models: OpenAI.Models.ModelsPage;
};
}
// Example component to list available OpenAI models
const ListModels = gsx.Component<{}, ListModelsOutput>(
"ListModels",
Expand All @@ -49,7 +49,7 @@ const GetAllModelResponsesFromProvider = gsx.Component<
APIProviderRunnerOutput
>(
"Get All Model Responses from Provider",
async ({ providerConfig, prompt, name }) => {
({ providerConfig, prompt, name }) => {
return (
<OpenAIProvider {...providerConfig} componentOpts={{ name: name }}>
<ListModels>
Expand All @@ -58,7 +58,6 @@ const GetAllModelResponsesFromProvider = gsx.Component<
const filteredModels = models.data
.filter(
(model) =>
model.object === "model" &&
!model.id.includes("embedding") &&
!model.id.includes("audio") &&
!model.id.includes("whisper") &&
Expand Down Expand Up @@ -107,28 +106,28 @@ const GetModelHistoryAcrossProviders = gsx.Component<
prompt: string;
providers?: APIProvider[];
},
any
APIProviderRunnerOutput[]
>(
"Get History of Model Responses across Providers",
({ prompt, providers }) => {
const apiProviders = providers || [
const apiProviders = providers ?? [
{
name: "OpenAI",
providerConfig: {
apiKey: process.env["OPENAI_API_KEY"],
apiKey: process.env.OPENAI_API_KEY,
},
},
{
name: "Groq",
providerConfig: {
baseURL: "https://api.groq.com/openai/v1",
apiKey: process.env["GROQ_API_KEY"],
apiKey: process.env.GROQ_API_KEY,
},
},
];

// Map through all API providers and get history for each
return apiProviders.map((provider) => (
return gsx.array(apiProviders).map((provider) => (
<GetAllModelResponsesFromProvider
name={provider.name}
providerConfig={provider.providerConfig}
Expand All @@ -152,13 +151,13 @@ const result = await workflow.run(
providers: [
{
name: "OpenAI",
providerConfig: { apiKey: process.env["OPENAI_API_KEY"] },
providerConfig: { apiKey: process.env.OPENAI_API_KEY },
},
{
name: "Groq",
providerConfig: {
baseURL: "https://api.groq.com/openai/v1",
apiKey: process.env["GROQ_API_KEY"],
apiKey: process.env.GROQ_API_KEY,
},
},
],
Expand Down
14 changes: 3 additions & 11 deletions examples/salty-ocean-model-comparison/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"lib": [
"ESNext",
"DOM"
],
"lib": ["ESNext", "DOM"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
Expand All @@ -17,11 +14,6 @@
"jsxImportSource": "gensx",
"outDir": "./dist"
},
"include": [
"./src/**/*.ts",
"./src/**/*.tsx"
],
"exclude": [
"node_modules"
]
"include": ["./src/**/*.ts", "./src/**/*.tsx"],
"exclude": ["node_modules"]
}
Loading