chore: fix some stuff idk
This commit is contained in:
@@ -103,14 +103,6 @@ interface ProductAnalysis {
|
|||||||
|
|
||||||
// 2. Create a ResponseType object
|
// 2. Create a ResponseType object
|
||||||
const productAnalysisType = createResponseType<ProductAnalysis>(
|
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'
|
'A comprehensive product analysis with pros, cons, rating, and recommendation'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -31,16 +31,6 @@ interface UserProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const userProfileType = createResponseType<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',
|
'A user profile with personal information, preferences, and skills',
|
||||||
{
|
{
|
||||||
name: 'John Doe',
|
name: 'John Doe',
|
||||||
@@ -64,16 +54,6 @@ interface ProductAnalysis {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const productAnalysisType = createResponseType<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',
|
'A comprehensive product analysis with pros, cons, rating, and recommendation',
|
||||||
{
|
{
|
||||||
productName: 'Example Product',
|
productName: 'Example Product',
|
||||||
@@ -102,18 +82,6 @@ interface CodeReview {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const codeReviewType = createResponseType<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',
|
'A comprehensive code review with scoring, issues, and recommendations',
|
||||||
{
|
{
|
||||||
overallScore: 8,
|
overallScore: 8,
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export interface AIMessage {
|
|||||||
*/
|
*/
|
||||||
export interface ResponseType<T = any> {
|
export interface ResponseType<T = any> {
|
||||||
/** The TypeScript type definition as a string */
|
/** The TypeScript type definition as a string */
|
||||||
typeDefinition: string;
|
typeDefinition?: string;
|
||||||
/** Human-readable description of the expected response format */
|
/** Human-readable description of the expected response format */
|
||||||
description: string;
|
description: string;
|
||||||
/** Example of the expected response structure */
|
/** Example of the expected response structure */
|
||||||
@@ -171,7 +171,6 @@ export interface ProviderInfo {
|
|||||||
/**
|
/**
|
||||||
* Creates a response type definition for structured AI outputs
|
* 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 description - Human-readable description of the expected format
|
||||||
* @param example - Optional example of the expected response structure
|
* @param example - Optional example of the expected response structure
|
||||||
* @param strictJson - Whether to enforce strict JSON formatting (default: true)
|
* @param strictJson - Whether to enforce strict JSON formatting (default: true)
|
||||||
@@ -180,15 +179,6 @@ export interface ProviderInfo {
|
|||||||
* @example
|
* @example
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* const userType = createResponseType(
|
* const userType = createResponseType(
|
||||||
* `{
|
|
||||||
* name: string;
|
|
||||||
* age: number;
|
|
||||||
* email: string;
|
|
||||||
* preferences: {
|
|
||||||
* theme: 'light' | 'dark';
|
|
||||||
* notifications: boolean;
|
|
||||||
* };
|
|
||||||
* }`,
|
|
||||||
* 'A user profile with personal information and preferences',
|
* 'A user profile with personal information and preferences',
|
||||||
* {
|
* {
|
||||||
* name: 'John Doe',
|
* name: 'John Doe',
|
||||||
@@ -200,13 +190,11 @@ export interface ProviderInfo {
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function createResponseType<T = any>(
|
export function createResponseType<T = any>(
|
||||||
typeDefinition: string,
|
|
||||||
description: string,
|
description: string,
|
||||||
example?: T,
|
example?: T,
|
||||||
strictJson: boolean = true
|
strictJson: boolean = true
|
||||||
): ResponseType<T> {
|
): ResponseType<T> {
|
||||||
return {
|
return {
|
||||||
typeDefinition: typeDefinition.trim(),
|
|
||||||
description,
|
description,
|
||||||
example,
|
example,
|
||||||
strictJson
|
strictJson
|
||||||
@@ -222,32 +210,25 @@ export function createResponseType<T = any>(
|
|||||||
export function generateResponseTypePrompt(responseType: ResponseType): string {
|
export function generateResponseTypePrompt(responseType: ResponseType): string {
|
||||||
const { typeDefinition, description, example, strictJson } = responseType;
|
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.';
|
||||||
|
|
||||||
`;
|
if (typeDefinition) {
|
||||||
prompt += `Type Definition:
|
prompt += ' The JSON object must strictly adhere to the following TypeScript type definition:\n\n';
|
||||||
typescript
|
prompt += 'Type Definition:\n```typescript\n' + typeDefinition + '\n```\n\n';
|
||||||
${typeDefinition}
|
} else {
|
||||||
|
prompt += '\n\n';
|
||||||
|
}
|
||||||
|
|
||||||
`;
|
prompt += 'Description: ' + description + '\n\n';
|
||||||
prompt += `Description: ${description}
|
|
||||||
|
|
||||||
`;
|
|
||||||
|
|
||||||
if (example) {
|
if (example) {
|
||||||
prompt += `Example of the expected JSON output:
|
prompt += 'Example of the expected JSON output:\n```json\n' + JSON.stringify(example, null, 2) + '\n```\n\n';
|
||||||
json
|
|
||||||
${JSON.stringify(example, null, 2)}
|
|
||||||
|
|
||||||
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strictJson) {
|
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 {
|
} 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;
|
return prompt;
|
||||||
|
|||||||
Reference in New Issue
Block a user