Skip to content
Open
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
10 changes: 9 additions & 1 deletion apps/promptions-chat/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# Copy this file to .env and add your OpenAI API key
# Copy this file to .env

# Required: Set your API key
VITE_OPENAI_API_KEY=your_openai_api_key_here

# Optional: Set base URL for the OpenAI-compatible API endpoint (if blank, defaults to OpenAI API endpoint)
# VITE_OPENAI_BASE_URL=

# Optional: Set model to use (if blank, defaults to gpt-3.5-turbo)
# VITE_OPENAI_MODEL=
8 changes: 6 additions & 2 deletions apps/promptions-chat/src/services/ChatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ interface ChatMessage {

export class ChatService {
private client: OpenAI;
private model: string;

constructor() {
// In a real application, you'd want to handle the API key more securely
// For development, you can set VITE_OPENAI_API_KEY in your .env file
const apiKey = import.meta.env.VITE_OPENAI_API_KEY || process.env.OPENAI_API_KEY;
const baseURL = import.meta.env.VITE_OPENAI_BASE_URL || process.env.OPENAI_BASE_URL;
this.model = import.meta.env.VITE_OPENAI_MODEL || process.env.OPENAI_MODEL || "gpt-3.5-turbo";

if (!apiKey) {
throw new Error(
Expand All @@ -21,6 +24,7 @@ export class ChatService {

this.client = new OpenAI({
apiKey,
baseURL,
dangerouslyAllowBrowser: true, // Only for demo purposes - use a backend in production
});
}
Expand All @@ -35,7 +39,7 @@ export class ChatService {
try {
const stream = await this.client.chat.completions.create(
{
model: "gpt-4.1",
model: this.model,
messages: messages as OpenAI.Chat.Completions.ChatCompletionMessageParam[],
stream: true,
temperature: 0.7,
Expand Down Expand Up @@ -64,7 +68,7 @@ export class ChatService {
async sendMessage(messages: ChatMessage[]): Promise<string> {
try {
const response = await this.client.chat.completions.create({
model: "gpt-3.5-turbo",
model: this.model,
messages: messages as OpenAI.Chat.Completions.ChatCompletionMessageParam[],
temperature: 0.7,
max_tokens: 1000,
Expand Down
10 changes: 9 additions & 1 deletion apps/promptions-image/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# Copy this file to .env and add your OpenAI API key
# Copy this file to .env

# Required: Set your API key
VITE_OPENAI_API_KEY=your_openai_api_key_here

# Optional: Set base URL for the OpenAI-compatible API endpoint (if blank, defaults to OpenAI API endpoint)
# VITE_OPENAI_BASE_URL=

# Optional: Set model to use (if blank, defaults to gpt-3.5-turbo)
# VITE_OPENAI_MODEL=
6 changes: 5 additions & 1 deletion apps/promptions-image/src/services/ImageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import { ImageGenerationParams, GeneratedImage } from "../types";

export class ImageService {
private client: OpenAI;
private chatModel: string;

constructor() {
const apiKey = import.meta.env.VITE_OPENAI_API_KEY || process.env.OPENAI_API_KEY;
const baseURL = import.meta.env.VITE_OPENAI_BASE_URL || process.env.OPENAI_BASE_URL;
this.chatModel = import.meta.env.VITE_OPENAI_MODEL || process.env.OPENAI_MODEL || "gpt-3.5-turbo";

if (!apiKey) {
throw new Error(
Expand All @@ -15,6 +18,7 @@ export class ImageService {

this.client = new OpenAI({
apiKey,
baseURL,
dangerouslyAllowBrowser: true, // Only for demo purposes - use a backend in production
});
}
Expand Down Expand Up @@ -61,7 +65,7 @@ export class ImageService {
try {
const stream = await this.client.chat.completions.create(
{
model: "gpt-4.1",
model: this.chatModel,
messages: messages as OpenAI.Chat.Completions.ChatCompletionMessageParam[],
stream: true,
temperature: 0.7,
Expand Down