chore: fix some stuff idk
This commit is contained in:
@@ -103,14 +103,6 @@ interface ProductAnalysis {
|
||||
|
||||
// 2. Create a ResponseType object
|
||||
const productAnalysisType = createResponseType<ProductAnalysis>(
|
||||
`{
|
||||
productName: string;
|
||||
priceRange: 'budget' | 'mid-range' | 'premium';
|
||||
pros: string[];
|
||||
cons: string[];
|
||||
overallRating: number;
|
||||
recommendation: 'buy' | 'consider' | 'avoid';
|
||||
}`,
|
||||
'A comprehensive product analysis with pros, cons, rating, and recommendation'
|
||||
);
|
||||
|
||||
|
||||
@@ -31,16 +31,6 @@ interface UserProfile {
|
||||
}
|
||||
|
||||
const userProfileType = createResponseType<UserProfile>(
|
||||
`{
|
||||
name: string;
|
||||
age: number;
|
||||
email: string;
|
||||
preferences: {
|
||||
theme: 'light' | 'dark';
|
||||
notifications: boolean;
|
||||
};
|
||||
skills: string[];
|
||||
}`,
|
||||
'A user profile with personal information, preferences, and skills',
|
||||
{
|
||||
name: 'John Doe',
|
||||
@@ -64,16 +54,6 @@ interface ProductAnalysis {
|
||||
}
|
||||
|
||||
const productAnalysisType = createResponseType<ProductAnalysis>(
|
||||
`{
|
||||
productName: string;
|
||||
category: string;
|
||||
priceRange: 'budget' | 'mid-range' | 'premium';
|
||||
pros: string[];
|
||||
cons: string[];
|
||||
overallRating: number;
|
||||
recommendation: 'buy' | 'consider' | 'avoid';
|
||||
reasoning: string;
|
||||
}`,
|
||||
'A comprehensive product analysis with pros, cons, rating, and recommendation',
|
||||
{
|
||||
productName: 'Example Product',
|
||||
@@ -102,18 +82,6 @@ interface CodeReview {
|
||||
}
|
||||
|
||||
const codeReviewType = createResponseType<CodeReview>(
|
||||
`{
|
||||
overallScore: number;
|
||||
issues: Array<{
|
||||
type: 'error' | 'warning' | 'suggestion';
|
||||
line?: number;
|
||||
message: string;
|
||||
severity: 'low' | 'medium' | 'high';
|
||||
}>;
|
||||
strengths: string[];
|
||||
improvements: string[];
|
||||
summary: string;
|
||||
}`,
|
||||
'A comprehensive code review with scoring, issues, and recommendations',
|
||||
{
|
||||
overallScore: 8,
|
||||
|
||||
@@ -41,7 +41,7 @@ export interface AIMessage {
|
||||
*/
|
||||
export interface ResponseType<T = any> {
|
||||
/** The TypeScript type definition as a string */
|
||||
typeDefinition: string;
|
||||
typeDefinition?: string;
|
||||
/** Human-readable description of the expected response format */
|
||||
description: string;
|
||||
/** Example of the expected response structure */
|
||||
@@ -171,7 +171,6 @@ export interface ProviderInfo {
|
||||
/**
|
||||
* Creates a response type definition for structured AI outputs
|
||||
*
|
||||
* @param typeDefinition - TypeScript type definition as a string
|
||||
* @param description - Human-readable description of the expected format
|
||||
* @param example - Optional example of the expected response structure
|
||||
* @param strictJson - Whether to enforce strict JSON formatting (default: true)
|
||||
@@ -180,15 +179,6 @@ export interface ProviderInfo {
|
||||
* @example
|
||||
* ```typescript
|
||||
* const userType = createResponseType(
|
||||
* `{
|
||||
* name: string;
|
||||
* age: number;
|
||||
* email: string;
|
||||
* preferences: {
|
||||
* theme: 'light' | 'dark';
|
||||
* notifications: boolean;
|
||||
* };
|
||||
* }`,
|
||||
* 'A user profile with personal information and preferences',
|
||||
* {
|
||||
* name: 'John Doe',
|
||||
@@ -200,13 +190,11 @@ export interface ProviderInfo {
|
||||
* ```
|
||||
*/
|
||||
export function createResponseType<T = any>(
|
||||
typeDefinition: string,
|
||||
description: string,
|
||||
example?: T,
|
||||
strictJson: boolean = true
|
||||
): ResponseType<T> {
|
||||
return {
|
||||
typeDefinition: typeDefinition.trim(),
|
||||
description,
|
||||
example,
|
||||
strictJson
|
||||
@@ -222,32 +210,25 @@ export function createResponseType<T = any>(
|
||||
export function generateResponseTypePrompt(responseType: ResponseType): string {
|
||||
const { typeDefinition, description, example, strictJson } = responseType;
|
||||
|
||||
let prompt = `You are an AI assistant that must respond with a JSON object. The JSON object must strictly adhere to the following TypeScript type definition:
|
||||
let prompt = 'You are an AI assistant that must respond with a JSON object.';
|
||||
|
||||
`;
|
||||
prompt += `Type Definition:
|
||||
typescript
|
||||
${typeDefinition}
|
||||
|
||||
if (typeDefinition) {
|
||||
prompt += ' The JSON object must strictly adhere to the following TypeScript type definition:\n\n';
|
||||
prompt += 'Type Definition:\n```typescript\n' + typeDefinition + '\n```\n\n';
|
||||
} else {
|
||||
prompt += '\n\n';
|
||||
}
|
||||
|
||||
`;
|
||||
prompt += `Description: ${description}
|
||||
|
||||
`;
|
||||
prompt += 'Description: ' + description + '\n\n';
|
||||
|
||||
if (example) {
|
||||
prompt += `Example of the expected JSON output:
|
||||
json
|
||||
${JSON.stringify(example, null, 2)}
|
||||
|
||||
|
||||
`;
|
||||
prompt += 'Example of the expected JSON output:\n```json\n' + JSON.stringify(example, null, 2) + '\n```\n\n';
|
||||
}
|
||||
|
||||
if (strictJson) {
|
||||
prompt += `IMPORTANT: Your entire response must be a single, valid JSON object that conforms to the type definition above. Do not include any additional text, explanations, or markdown formatting before or after the JSON object.`;
|
||||
prompt += 'IMPORTANT: Your entire response must be a single, valid JSON object. Do not include any additional text, explanations, or markdown formatting before or after the JSON object.';
|
||||
} else {
|
||||
prompt += `Your response should contain a JSON object that follows the structure defined above.`;
|
||||
prompt += 'Your response should contain a JSON object that follows the structure defined above.';
|
||||
}
|
||||
|
||||
return prompt;
|
||||
|
||||
Reference in New Issue
Block a user