mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
🚀 feat: GPT-4.5, Anthropic Tool Header, and OpenAPI Ref Resolution (#6118)
* 🔧 refactor: Update settings to use 'as const' for improved type safety and make gpt-4o-mini default model (cheapest) * 📖 docs: Update README to reflect support for GPT-4.5 in image analysis feature * 🔧 refactor: Update model handling to use default settings and improve encoding logic * 🔧 refactor: Enhance model version extraction logic for improved compatibility with future GPT and omni models * feat: GPT-4.5 tx/token update, vision support * fix: $ref resolution logic in OpenAPI handling * feat: add new 'anthropic-beta' header for Claude 3.7 to include token-efficient tools; ref: https://docs.anthropic.com/en/docs/build-with-claude/tool-use/token-efficient-tool-use
This commit is contained in:
parent
9802629848
commit
2293cd667e
15 changed files with 337 additions and 148 deletions
|
|
@ -585,21 +585,99 @@ describe('resolveRef', () => {
|
|||
openapiSpec.paths['/ai.chatgpt.render-flowchart']?.post
|
||||
?.requestBody as OpenAPIV3.RequestBodyObject
|
||||
).content['application/json'].schema;
|
||||
expect(flowchartRequestRef).toBeDefined();
|
||||
const resolvedFlowchartRequest = resolveRef(
|
||||
flowchartRequestRef as OpenAPIV3.RequestBodyObject,
|
||||
openapiSpec.components,
|
||||
);
|
||||
|
||||
expect(resolvedFlowchartRequest).toBeDefined();
|
||||
expect(resolvedFlowchartRequest.type).toBe('object');
|
||||
const properties = resolvedFlowchartRequest.properties as FlowchartSchema;
|
||||
expect(properties).toBeDefined();
|
||||
expect(flowchartRequestRef).toBeDefined();
|
||||
|
||||
const resolvedSchemaObject = resolveRef(
|
||||
flowchartRequestRef as OpenAPIV3.ReferenceObject,
|
||||
openapiSpec.components,
|
||||
) as OpenAPIV3.SchemaObject;
|
||||
|
||||
expect(resolvedSchemaObject).toBeDefined();
|
||||
expect(resolvedSchemaObject.type).toBe('object');
|
||||
expect(resolvedSchemaObject.properties).toBeDefined();
|
||||
|
||||
const properties = resolvedSchemaObject.properties as FlowchartSchema;
|
||||
expect(properties.mermaid).toBeDefined();
|
||||
expect(properties.mermaid.type).toBe('string');
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveRef general cases', () => {
|
||||
const spec = {
|
||||
openapi: '3.0.0',
|
||||
info: { title: 'TestSpec', version: '1.0.0' },
|
||||
paths: {},
|
||||
components: {
|
||||
schemas: {
|
||||
TestSchema: { type: 'string' },
|
||||
},
|
||||
parameters: {
|
||||
TestParam: {
|
||||
name: 'myParam',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: { $ref: '#/components/schemas/TestSchema' },
|
||||
},
|
||||
},
|
||||
requestBodies: {
|
||||
TestRequestBody: {
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: { $ref: '#/components/schemas/TestSchema' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies OpenAPIV3.Document;
|
||||
|
||||
it('resolves schema refs correctly', () => {
|
||||
const schemaRef: OpenAPIV3.ReferenceObject = { $ref: '#/components/schemas/TestSchema' };
|
||||
const resolvedSchema = resolveRef<OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject>(
|
||||
schemaRef,
|
||||
spec.components,
|
||||
);
|
||||
expect(resolvedSchema.type).toEqual('string');
|
||||
});
|
||||
|
||||
it('resolves parameter refs correctly, then schema within parameter', () => {
|
||||
const paramRef: OpenAPIV3.ReferenceObject = { $ref: '#/components/parameters/TestParam' };
|
||||
const resolvedParam = resolveRef<OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject>(
|
||||
paramRef,
|
||||
spec.components,
|
||||
);
|
||||
expect(resolvedParam.name).toEqual('myParam');
|
||||
expect(resolvedParam.in).toEqual('query');
|
||||
expect(resolvedParam.required).toBe(false);
|
||||
|
||||
const paramSchema = resolveRef<OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject>(
|
||||
resolvedParam.schema as OpenAPIV3.ReferenceObject,
|
||||
spec.components,
|
||||
);
|
||||
expect(paramSchema.type).toEqual('string');
|
||||
});
|
||||
|
||||
it('resolves requestBody refs correctly, then schema within requestBody', () => {
|
||||
const requestBodyRef: OpenAPIV3.ReferenceObject = {
|
||||
$ref: '#/components/requestBodies/TestRequestBody',
|
||||
};
|
||||
const resolvedRequestBody = resolveRef<OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject>(
|
||||
requestBodyRef,
|
||||
spec.components,
|
||||
);
|
||||
|
||||
expect(resolvedRequestBody.content['application/json']).toBeDefined();
|
||||
|
||||
const schemaInRequestBody = resolveRef<OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject>(
|
||||
resolvedRequestBody.content['application/json'].schema as OpenAPIV3.ReferenceObject,
|
||||
spec.components,
|
||||
);
|
||||
|
||||
expect(schemaInRequestBody.type).toEqual('string');
|
||||
});
|
||||
});
|
||||
|
||||
describe('openapiToFunction', () => {
|
||||
it('converts OpenAPI spec to function signatures and request builders', () => {
|
||||
const { functionSignatures, requestBuilders } = openapiToFunction(getWeatherOpenapiSpec);
|
||||
|
|
@ -1095,4 +1173,43 @@ describe('createURL', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('openapiToFunction parameter refs resolution', () => {
|
||||
const weatherSpec = {
|
||||
openapi: '3.0.0',
|
||||
info: { title: 'Weather', version: '1.0.0' },
|
||||
servers: [{ url: 'https://api.weather.gov' }],
|
||||
paths: {
|
||||
'/points/{point}': {
|
||||
get: {
|
||||
operationId: 'getPoint',
|
||||
parameters: [{ $ref: '#/components/parameters/PathPoint' }],
|
||||
responses: { '200': { description: 'ok' } },
|
||||
},
|
||||
},
|
||||
},
|
||||
components: {
|
||||
parameters: {
|
||||
PathPoint: {
|
||||
name: 'point',
|
||||
in: 'path',
|
||||
required: true,
|
||||
schema: { type: 'string', pattern: '^(-?\\d+(?:\\.\\d+)?),(-?\\d+(?:\\.\\d+)?)$' },
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies OpenAPIV3.Document;
|
||||
|
||||
it('correctly resolves $ref for parameters', () => {
|
||||
const { functionSignatures } = openapiToFunction(weatherSpec, true);
|
||||
const func = functionSignatures.find((sig) => sig.name === 'getPoint');
|
||||
expect(func).toBeDefined();
|
||||
expect(func?.parameters.properties).toHaveProperty('point');
|
||||
expect(func?.parameters.required).toContain('point');
|
||||
|
||||
const paramSchema = func?.parameters.properties['point'] as OpenAPIV3.SchemaObject;
|
||||
expect(paramSchema.type).toEqual('string');
|
||||
expect(paramSchema.pattern).toEqual('^(-?\\d+(?:\\.\\d+)?),(-?\\d+(?:\\.\\d+)?)$');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue