Skip to content

Commit

Permalink
Refactor project name and update AI provider support
Browse files Browse the repository at this point in the history
  • Loading branch information
aeltorio committed Oct 4, 2024
1 parent 9360997 commit bce09f7
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The AI Outlook Add-in enhances your email workflow by providing AI-powered assis
- Prompt easy configurable in src/config.json
- Model configuration in src/config.json
- Language translation integration
- Compatible with Groq AI and Sambanova AI ([via AI-Proxy-Cloudflare](https://github.com/sctg-development/ai-proxy-cloudflare))
- Compatible with Groq AI and Sambanova AI ([via AI-Proxy-Cloudflare due to CORS](https://github.com/sctg-development/ai-proxy-cloudflare))

## Prerequisites

Expand Down
85 changes: 85 additions & 0 deletions src/aipane/AIPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,118 @@

import config from "../config.json";
export interface AIPrompt {
/**
* Unique identifier for the prompt.
*/
id: string;

/**
* System message for the prompt.
*/
system: string;

/**
* User message for the prompt.
*/
user: string;

/**
* Summary of the prompt.
*/
summary: string;
}

/**
* Represents an AI model.
* @interface
*/
export interface AIModel {
/**
* Unique identifier for the model.
*/
id: string;

/**
* Name of the model.
*/
name: string;

/**
* Indicates if this model is the default.
*/
default: boolean;

/**
* Maximum number of tokens the model can process.
*/
max_tokens: number;
}

/**
* Represents an AI provider.
* @interface
*/
export interface AIProvider {
/**
* Indicates if this provider is the default.
*/
default: boolean;

/**
* Name of the provider.
*/
name: string;

/**
* Base URL for the provider's API.
*/
baseUrl: string;

/**
* Base path for the provider's API.
*/
basePath: string;

/**
* API key for accessing the provider's services.
*/
apiKey: string;

/**
* List of models provided by the AI provider.
*/
models: AIModel[];

/**
* Indicates if the provider is proxied. (e.g., for CORS issues)
* It was designed to be used with a AI-Proxy-Cloudflare worker https://github.com/sctg-development/ai-proxy-cloudflare.
* And AI-sdk https://github.com/sctg-development/ai-typescript
*/
aiproxied: boolean;
}

/**
* Retrieves the default AI provider from the configuration.
* @returns {AIProvider} The default AI provider.
*/
export function getDefaultProvider(): AIProvider {
return config.providers.filter((provider: AIProvider) => provider.default)[0];
}

/**
* Retrieves a specific AI provider by name.
* @param {string} providerName - The name of the provider to retrieve.
* @returns {AIProvider} The AI provider with the specified name.
*/
export function getProvider(providerName: string): AIProvider {
return config.providers.filter((provider: AIProvider) => provider.name === providerName)[0];
}
/**
* Retrieves a specific AI model from a given provider by model ID.
* @param {AIProvider} provider - The AI provider containing the model.
* @param {string} modelId - The ID of the model to retrieve.
* @returns {AIModel} The AI model with the specified ID.
*/
export function getModel(provider: AIProvider, modelId: string): AIModel {
return provider.models.filter((model: AIModel) => model.id === modelId)[0];
}
4 changes: 2 additions & 2 deletions src/aipane/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { insertText } from "../aipane";
import HeroApiKey from "./HeroApiKey";
import HeroComboPrompts from "./HeroComboPrompts";
import HeroModels from "./HeroModels";
import { AIModel, getDefaultProvider } from "../AIPrompt";
import { AIModel, getDefaultProvider, getModel } from "../AIPrompt";

interface AppProps {
title: string;
Expand Down Expand Up @@ -68,7 +68,7 @@ const App: React.FC<AppProps> = (props: AppProps) => {
};

const handleModelChange = (newValue: string) => {
setModel(provider.models.find((model) => model.id === newValue) || null);
setModel(getModel(provider, newValue) || null);
};

const handlePromptSubmit = (userText: string) => {
Expand Down

0 comments on commit bce09f7

Please sign in to comment.