标签: lucid

AdonisJS - 如何根据 Antl Provider 的语言环境返回验证消息

我正在对我的 API 应用国际化,但我遇到了一些与 Antl 和验证消息相关的问题。

对于标准响应消息,我将根据用户设置的区域设置返回。我创建了一个切换语言环境的路由,并设置为一个 cookie 和一个全局中间件,以从 cookie 中获取语言环境,然后我只返回存储在语言环境资源中的消息。

全局中间件:

class Locale {
  async handle ({ request, antl }, next) {
    const lang = request.cookie('lang')

    if (lang) {
      antl.switchLocale(lang)
    }

    await next()
  }
}
Run Code Online (Sandbox Code Playgroud)

路线:

Route.get('/switch/:lang', ({ params, antl, request, response }) => {
  // Getting the current available locales
  const locales = antl.availableLocales()

  try {
    // Saving into cookies
    if (locales.indexOf(params.lang) > -1) {
      response.cookie('lang', params.lang, { path: '/' })
    }

    return response.status(200).send({ message: 'Locale changed succesfully' }) …
Run Code Online (Sandbox Code Playgroud)

javascript backend node.js adonis.js lucid

7
推荐指数
1
解决办法
1315
查看次数

如何将 keras 模型导入 lucid

简短版本:

我想在 lucid 中可视化 keras 模型,但未能将模型转换为 lucid 可接受的格式。

长版:

我想和 lucid 一起玩,探索一个内置于 keras 的简单模型(CNN for MNIST like this one https://www.tensorflow.org/tutorials)。

将模型导入 lucid 的教程 https://colab.research.google.com/drive/1PPzeZi5sBN2YRlBmKsdvZPbfYtZI-pHl#scrollTo=3YKffRa70uGm

告诉我我需要一个“冻结图”。所以我跟着这个教程

https://towardsdatascience.com/freezing-a-keras-model-c2e26cb84a38

将 keras 模型转换为 tf 估计器,对其进行训练并应用教程中提供的 freeze_graph() 方法。

但是生成的图形似乎没有 lucid 可以使用的输入节点 - 我假设是因为图形基于的估计器期望输入函数而不是张量作为输入?

有没有办法调整这个图,以便它接受常规的 tf 张量作为输入?

或者,是否有另一种方法可以将 keras 模型训练和保存为冻结图,而无需绕过 tf 估计器?

python keras tensorflow lucid tf.keras

5
推荐指数
0
解决办法
354
查看次数

Laravel Lucid Architecture dependency injection

I am new to Lucid Architecture applied with Laravel.

我正在尝试找到将依赖项注入到我的功能中的最佳方法。这是我的用户页面功能:

class UsersPageFeature extends Feature {

    public function handle( Request $request,User $user ) {
        $data = [];
        $users = $this->run( GetUsersJob::class,['userModel'=> $user );
        $data['users'] = $users;
        return $this->run( new RespondWithViewJob( "web::pages.users.page",  $data) );
    }
}
Run Code Online (Sandbox Code Playgroud)

而我的GetUsersJob

class GetUsersJob extends Job {

    public function __construct($user) {
        $this->user = $user;
    }

    public function handle( ) {
        return $user->all();
    }
}
Run Code Online (Sandbox Code Playgroud)

它可以工作,但是我需要将所有依赖项传递给每个作业。我认为这可以做得更好。

请提出一个更好的方法。

php dependency-injection laravel laravel-5 lucid

5
推荐指数
0
解决办法
102
查看次数

Adonis JS v5 关系缺少模型属性

我正在学习如何使用Adonis 框架 (v5),按照传统规定,我正在创建一个待办事项列表 api 来测试它。

我遇到的问题是关于UserTodo实体之间的关系。

这是两个模型:

// file: app/Models/Todo.ts

export default class Todo extends BaseModel {
  @column({ isPrimary: true })
  public id: number

  @belongsTo(() => User, {
    foreignKey: 'id',
  })
  public author: BelongsTo<typeof User>

  @column()
  public completed: boolean

  @column()
  public title: string

  @column()
  public description: string | null

  @column.dateTime({ autoCreate: true })
  public createdAt: DateTime

  @column.dateTime({ autoCreate: true, autoUpdate: true })
  public updatedAt: DateTime
}
Run Code Online (Sandbox Code Playgroud)
// file: app/Models/User.ts

export default class User extends …
Run Code Online (Sandbox Code Playgroud)

javascript orm typescript adonis.js lucid

4
推荐指数
1
解决办法
3041
查看次数

如何在 Lucid Model 中设置表名?

该框架按惯例工作(例如 User \xe2\x86\x92 users),在英语中运行良好,但在其他语言中可能不太优雅......

\n

adonis.js lucid

0
推荐指数
1
解决办法
2225
查看次数