Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: unified JS and Go reflection API tests -- run the same test against both JS and Go #617

Merged
merged 17 commits into from
Jul 15, 2024
25 changes: 15 additions & 10 deletions go/ai/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,23 @@ type ModelMetadata struct {
// [ModelAction] that runs it.
func DefineModel(provider, name string, metadata *ModelMetadata, generate func(context.Context, *GenerateRequest, ModelStreamingCallback) (*GenerateResponse, error)) *Model {
metadataMap := map[string]any{}
if metadata != nil {
if metadata.Label != "" {
metadataMap["label"] = metadata.Label
if metadata == nil {
// Always make sure there's at least minimal metadata.
metadata = &ModelMetadata{
Label: name,
}
supports := map[string]bool{
"media": metadata.Supports.Media,
"multiturn": metadata.Supports.Multiturn,
"systemRole": metadata.Supports.SystemRole,
"tools": metadata.Supports.Tools,
}
metadataMap["supports"] = supports
}
if metadata.Label != "" {
metadataMap["label"] = metadata.Label
}
supports := map[string]bool{
"media": metadata.Supports.Media,
"multiturn": metadata.Supports.Multiturn,
"systemRole": metadata.Supports.SystemRole,
"tools": metadata.Supports.Tools,
}
metadataMap["supports"] = supports

return (*Model)(core.DefineStreamingAction(provider, name, atype.Model, map[string]any{
"model": metadataMap,
}, generate))
Expand Down
2 changes: 1 addition & 1 deletion js/ai/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export function defineModel<
streamingCallback?: StreamingCallback<GenerateResponseChunkData>
) => Promise<GenerateResponseData>
): ModelAction<CustomOptionsSchema> {
const label = options.label || `${options.name} GenAI model`;
const label = options.label || options.name;
const middleware: ModelMiddleware[] = [
...(options.use || []),
validateSupport(options),
Expand Down
10 changes: 8 additions & 2 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@
"description": "",
"main": "lib/e2e.js",
"scripts": {
"test": "node --import tsx src/e2e.ts"
"test": "npm-run-all pnpm-test:dev_ui_test pnpm-test:reflection_api",
"test:dev_ui_test": "node --import tsx src/dev_ui_test.ts",
"test:reflection_api": "node --import tsx src/reflection_api_test.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"json-diff": "^1.0.6",
"puppeteer": "^22.5.0",
"puppeteer-screen-recorder": "^3.0.3",
"semver": "^7.6.0",
"terminate": "^2.6.1"
"terminate": "^2.6.1",
"yaml": "^2.4.5"
},
"devDependencies": {
"@types/json-diff": "^1.0.3",
"npm-run-all": "^4.1.5",
"tsx": "^4.7.1"
}
}
Loading
Loading