ChatMessageFactory.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\Chat;
  4. use App\Models\ChatMessage;
  5. use Illuminate\Database\Eloquent\Factories\Factory;
  6. use Illuminate\Support\Str;
  7. class ChatMessageFactory extends Factory
  8. {
  9. /**
  10. * Define the model's default state.
  11. *
  12. * @return array
  13. */
  14. public function definition()
  15. {
  16. return [
  17. 'uid' => (string) Str::uuid(),
  18. 'chat_id' => Chat::factory(),
  19. 'parent_id' => null,
  20. 'session_id' => (string) Str::uuid(),
  21. 'role' => $this->faker->randomElement(['user', 'assistant', 'tool']),
  22. 'content' => $this->faker->paragraph,
  23. 'model_id' => null,
  24. 'tool_calls' => null,
  25. 'tool_call_id' => null,
  26. 'is_active' => true,
  27. ];
  28. }
  29. public function user()
  30. {
  31. return $this->state(function (array $attributes) {
  32. return [
  33. 'role' => 'user',
  34. 'content' => $this->faker->sentence,
  35. 'model_name' => null,
  36. 'tool_calls' => null,
  37. 'tool_call_id' => null,
  38. ];
  39. });
  40. }
  41. public function assistant()
  42. {
  43. return $this->state(function (array $attributes) {
  44. return [
  45. 'role' => 'assistant',
  46. 'content' => $this->faker->paragraph,
  47. 'model_name' => $this->faker->randomElement(['gpt-4', 'gpt-3.5-turbo', 'claude-3']),
  48. 'tool_calls' => null,
  49. 'tool_call_id' => null,
  50. ];
  51. });
  52. }
  53. public function tool()
  54. {
  55. return $this->state(function (array $attributes) {
  56. return [
  57. 'role' => 'tool',
  58. 'content' => $this->faker->paragraph,
  59. 'model_name' => null,
  60. 'tool_calls' => null,
  61. 'tool_call_id' => 'call_' . $this->faker->randomNumber(8),
  62. ];
  63. });
  64. }
  65. public function withToolCalls()
  66. {
  67. return $this->state(function (array $attributes) {
  68. return [
  69. 'role' => 'assistant',
  70. 'content' => null,
  71. 'tool_calls' => [
  72. [
  73. 'id' => 'call_' . $this->faker->randomNumber(8),
  74. 'function' => $this->faker->randomElement(['get_weather', 'search_web', 'calculate']),
  75. 'arguments' => [
  76. 'query' => $this->faker->sentence,
  77. 'city' => $this->faker->city
  78. ]
  79. ]
  80. ]
  81. ];
  82. });
  83. }
  84. public function inactive()
  85. {
  86. return $this->state(function (array $attributes) {
  87. return [
  88. 'is_active' => false,
  89. ];
  90. });
  91. }
  92. public function withMetadata($metadata = null)
  93. {
  94. return $this->state(function (array $attributes) use ($metadata) {
  95. return [
  96. 'metadata' => $metadata ?: [
  97. 'temperature' => $this->faker->randomFloat(2, 0, 2),
  98. 'tokens' => $this->faker->numberBetween(50, 500),
  99. 'max_tokens' => $this->faker->numberBetween(500, 2000),
  100. 'model_version' => $this->faker->randomElement(['1.0', '1.1', '2.0'])
  101. ],
  102. ];
  103. });
  104. }
  105. public function withEditor($editorId = null)
  106. {
  107. return $this->state(function (array $attributes) use ($editorId) {
  108. return [
  109. 'editor_id' => $editorId ?: (string) Str::uuid(),
  110. ];
  111. });
  112. }
  113. }