llama-stack 0.4.3__py3-none-any.whl → 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (311) hide show
  1. llama_stack/cli/stack/_list_deps.py +11 -7
  2. llama_stack/cli/stack/run.py +3 -25
  3. llama_stack/core/access_control/datatypes.py +78 -0
  4. llama_stack/core/configure.py +2 -2
  5. {llama_stack_api/internal → llama_stack/core/connectors}/__init__.py +2 -2
  6. llama_stack/core/connectors/connectors.py +162 -0
  7. llama_stack/core/conversations/conversations.py +61 -58
  8. llama_stack/core/datatypes.py +54 -8
  9. llama_stack/core/library_client.py +60 -13
  10. llama_stack/core/prompts/prompts.py +43 -42
  11. llama_stack/core/routers/datasets.py +20 -17
  12. llama_stack/core/routers/eval_scoring.py +143 -53
  13. llama_stack/core/routers/inference.py +20 -9
  14. llama_stack/core/routers/safety.py +30 -42
  15. llama_stack/core/routers/vector_io.py +15 -7
  16. llama_stack/core/routing_tables/models.py +42 -3
  17. llama_stack/core/routing_tables/scoring_functions.py +19 -19
  18. llama_stack/core/routing_tables/shields.py +20 -17
  19. llama_stack/core/routing_tables/vector_stores.py +8 -5
  20. llama_stack/core/server/auth.py +192 -17
  21. llama_stack/core/server/fastapi_router_registry.py +40 -5
  22. llama_stack/core/server/server.py +24 -5
  23. llama_stack/core/stack.py +54 -10
  24. llama_stack/core/storage/datatypes.py +9 -0
  25. llama_stack/core/store/registry.py +1 -1
  26. llama_stack/core/utils/exec.py +2 -2
  27. llama_stack/core/utils/type_inspection.py +16 -2
  28. llama_stack/distributions/dell/config.yaml +4 -1
  29. llama_stack/distributions/dell/doc_template.md +209 -0
  30. llama_stack/distributions/dell/run-with-safety.yaml +4 -1
  31. llama_stack/distributions/nvidia/config.yaml +4 -1
  32. llama_stack/distributions/nvidia/doc_template.md +170 -0
  33. llama_stack/distributions/nvidia/run-with-safety.yaml +4 -1
  34. llama_stack/distributions/oci/config.yaml +4 -1
  35. llama_stack/distributions/oci/doc_template.md +140 -0
  36. llama_stack/distributions/open-benchmark/config.yaml +9 -1
  37. llama_stack/distributions/postgres-demo/config.yaml +1 -1
  38. llama_stack/distributions/starter/build.yaml +62 -0
  39. llama_stack/distributions/starter/config.yaml +22 -3
  40. llama_stack/distributions/starter/run-with-postgres-store.yaml +22 -3
  41. llama_stack/distributions/starter/starter.py +13 -1
  42. llama_stack/distributions/starter-gpu/build.yaml +62 -0
  43. llama_stack/distributions/starter-gpu/config.yaml +22 -3
  44. llama_stack/distributions/starter-gpu/run-with-postgres-store.yaml +22 -3
  45. llama_stack/distributions/template.py +10 -2
  46. llama_stack/distributions/watsonx/config.yaml +4 -1
  47. llama_stack/log.py +1 -0
  48. llama_stack/models/llama/resources/dog.jpg +0 -0
  49. llama_stack/models/llama/resources/pasta.jpeg +0 -0
  50. llama_stack/models/llama/resources/small_dog.jpg +0 -0
  51. llama_stack/providers/inline/agents/meta_reference/__init__.py +1 -0
  52. llama_stack/providers/inline/agents/meta_reference/agents.py +58 -61
  53. llama_stack/providers/inline/agents/meta_reference/responses/openai_responses.py +187 -60
  54. llama_stack/providers/inline/agents/meta_reference/responses/streaming.py +99 -22
  55. llama_stack/providers/inline/agents/meta_reference/responses/types.py +2 -1
  56. llama_stack/providers/inline/agents/meta_reference/responses/utils.py +4 -1
  57. llama_stack/providers/inline/agents/meta_reference/safety.py +2 -2
  58. llama_stack/providers/inline/batches/reference/batches.py +2 -1
  59. llama_stack/providers/inline/eval/meta_reference/eval.py +40 -32
  60. llama_stack/providers/inline/ios/inference/LocalInferenceImpl/LocalInference.h +9 -0
  61. llama_stack/providers/inline/ios/inference/LocalInferenceImpl/LocalInference.swift +189 -0
  62. llama_stack/providers/inline/ios/inference/LocalInferenceImpl/Parsing.swift +238 -0
  63. llama_stack/providers/inline/ios/inference/LocalInferenceImpl/PromptTemplate.swift +12 -0
  64. llama_stack/providers/inline/ios/inference/LocalInferenceImpl/SystemPrompts.swift +89 -0
  65. llama_stack/providers/inline/ios/inference/LocalInferenceImpl.xcodeproj/project.pbxproj +550 -0
  66. llama_stack/providers/inline/ios/inference/LocalInferenceImpl.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  67. llama_stack/providers/inline/ios/inference/LocalInferenceImpl.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  68. llama_stack/providers/inline/post_training/huggingface/post_training.py +33 -38
  69. llama_stack/providers/inline/post_training/huggingface/utils.py +2 -5
  70. llama_stack/providers/inline/post_training/torchtune/common/utils.py +5 -9
  71. llama_stack/providers/inline/post_training/torchtune/post_training.py +28 -33
  72. llama_stack/providers/inline/post_training/torchtune/recipes/lora_finetuning_single_device.py +2 -4
  73. llama_stack/providers/inline/safety/code_scanner/code_scanner.py +12 -15
  74. llama_stack/providers/inline/safety/llama_guard/llama_guard.py +20 -24
  75. llama_stack/providers/inline/safety/prompt_guard/prompt_guard.py +11 -17
  76. llama_stack/providers/inline/scoring/basic/scoring.py +13 -17
  77. llama_stack/providers/inline/scoring/braintrust/braintrust.py +15 -15
  78. llama_stack/providers/inline/scoring/llm_as_judge/scoring.py +13 -17
  79. llama_stack/providers/inline/vector_io/sqlite_vec/sqlite_vec.py +1 -1
  80. llama_stack/providers/registry/agents.py +1 -0
  81. llama_stack/providers/registry/inference.py +1 -9
  82. llama_stack/providers/registry/vector_io.py +136 -16
  83. llama_stack/providers/remote/datasetio/nvidia/README.md +74 -0
  84. llama_stack/providers/remote/eval/nvidia/README.md +134 -0
  85. llama_stack/providers/remote/eval/nvidia/eval.py +22 -21
  86. llama_stack/providers/remote/files/s3/README.md +266 -0
  87. llama_stack/providers/remote/files/s3/config.py +5 -3
  88. llama_stack/providers/remote/files/s3/files.py +2 -2
  89. llama_stack/providers/remote/inference/gemini/gemini.py +4 -0
  90. llama_stack/providers/remote/inference/nvidia/NVIDIA.md +203 -0
  91. llama_stack/providers/remote/inference/openai/openai.py +2 -0
  92. llama_stack/providers/remote/inference/together/together.py +4 -0
  93. llama_stack/providers/remote/inference/vertexai/config.py +3 -3
  94. llama_stack/providers/remote/inference/vertexai/vertexai.py +5 -2
  95. llama_stack/providers/remote/inference/vllm/config.py +37 -18
  96. llama_stack/providers/remote/inference/vllm/vllm.py +0 -3
  97. llama_stack/providers/remote/inference/watsonx/watsonx.py +4 -0
  98. llama_stack/providers/remote/post_training/nvidia/README.md +151 -0
  99. llama_stack/providers/remote/post_training/nvidia/models.py +3 -11
  100. llama_stack/providers/remote/post_training/nvidia/post_training.py +31 -33
  101. llama_stack/providers/remote/safety/bedrock/bedrock.py +10 -27
  102. llama_stack/providers/remote/safety/nvidia/README.md +78 -0
  103. llama_stack/providers/remote/safety/nvidia/nvidia.py +9 -25
  104. llama_stack/providers/remote/safety/sambanova/sambanova.py +13 -11
  105. llama_stack/providers/remote/vector_io/elasticsearch/__init__.py +17 -0
  106. llama_stack/providers/remote/vector_io/elasticsearch/config.py +32 -0
  107. llama_stack/providers/remote/vector_io/elasticsearch/elasticsearch.py +463 -0
  108. llama_stack/providers/remote/vector_io/oci/__init__.py +22 -0
  109. llama_stack/providers/remote/vector_io/oci/config.py +41 -0
  110. llama_stack/providers/remote/vector_io/oci/oci26ai.py +595 -0
  111. llama_stack/providers/remote/vector_io/pgvector/config.py +69 -2
  112. llama_stack/providers/remote/vector_io/pgvector/pgvector.py +255 -6
  113. llama_stack/providers/remote/vector_io/qdrant/qdrant.py +62 -38
  114. llama_stack/providers/utils/bedrock/client.py +3 -3
  115. llama_stack/providers/utils/bedrock/config.py +7 -7
  116. llama_stack/providers/utils/inference/__init__.py +0 -25
  117. llama_stack/providers/utils/inference/embedding_mixin.py +4 -0
  118. llama_stack/providers/utils/inference/http_client.py +239 -0
  119. llama_stack/providers/utils/inference/litellm_openai_mixin.py +6 -0
  120. llama_stack/providers/utils/inference/model_registry.py +148 -2
  121. llama_stack/providers/utils/inference/openai_compat.py +1 -158
  122. llama_stack/providers/utils/inference/openai_mixin.py +42 -2
  123. llama_stack/providers/utils/inference/prompt_adapter.py +0 -209
  124. llama_stack/providers/utils/memory/openai_vector_store_mixin.py +92 -5
  125. llama_stack/providers/utils/memory/vector_store.py +46 -19
  126. llama_stack/providers/utils/responses/responses_store.py +40 -6
  127. llama_stack/providers/utils/safety.py +114 -0
  128. llama_stack/providers/utils/tools/mcp.py +44 -3
  129. llama_stack/testing/api_recorder.py +9 -3
  130. {llama_stack-0.4.3.dist-info → llama_stack-0.5.0.dist-info}/METADATA +14 -2
  131. {llama_stack-0.4.3.dist-info → llama_stack-0.5.0.dist-info}/RECORD +135 -279
  132. llama_stack-0.5.0.dist-info/top_level.txt +1 -0
  133. llama_stack/distributions/meta-reference-gpu/__init__.py +0 -7
  134. llama_stack/distributions/meta-reference-gpu/config.yaml +0 -140
  135. llama_stack/distributions/meta-reference-gpu/meta_reference.py +0 -163
  136. llama_stack/distributions/meta-reference-gpu/run-with-safety.yaml +0 -155
  137. llama_stack/models/llama/hadamard_utils.py +0 -88
  138. llama_stack/models/llama/llama3/args.py +0 -74
  139. llama_stack/models/llama/llama3/generation.py +0 -378
  140. llama_stack/models/llama/llama3/model.py +0 -304
  141. llama_stack/models/llama/llama3/multimodal/__init__.py +0 -12
  142. llama_stack/models/llama/llama3/multimodal/encoder_utils.py +0 -180
  143. llama_stack/models/llama/llama3/multimodal/image_transform.py +0 -409
  144. llama_stack/models/llama/llama3/multimodal/model.py +0 -1430
  145. llama_stack/models/llama/llama3/multimodal/utils.py +0 -26
  146. llama_stack/models/llama/llama3/quantization/__init__.py +0 -5
  147. llama_stack/models/llama/llama3/quantization/loader.py +0 -316
  148. llama_stack/models/llama/llama3_1/__init__.py +0 -12
  149. llama_stack/models/llama/llama3_1/prompt_format.md +0 -358
  150. llama_stack/models/llama/llama3_1/prompts.py +0 -258
  151. llama_stack/models/llama/llama3_2/__init__.py +0 -5
  152. llama_stack/models/llama/llama3_2/prompts_text.py +0 -229
  153. llama_stack/models/llama/llama3_2/prompts_vision.py +0 -126
  154. llama_stack/models/llama/llama3_2/text_prompt_format.md +0 -286
  155. llama_stack/models/llama/llama3_2/vision_prompt_format.md +0 -141
  156. llama_stack/models/llama/llama3_3/__init__.py +0 -5
  157. llama_stack/models/llama/llama3_3/prompts.py +0 -259
  158. llama_stack/models/llama/llama4/args.py +0 -107
  159. llama_stack/models/llama/llama4/ffn.py +0 -58
  160. llama_stack/models/llama/llama4/moe.py +0 -214
  161. llama_stack/models/llama/llama4/preprocess.py +0 -435
  162. llama_stack/models/llama/llama4/quantization/__init__.py +0 -5
  163. llama_stack/models/llama/llama4/quantization/loader.py +0 -226
  164. llama_stack/models/llama/llama4/vision/__init__.py +0 -5
  165. llama_stack/models/llama/llama4/vision/embedding.py +0 -210
  166. llama_stack/models/llama/llama4/vision/encoder.py +0 -412
  167. llama_stack/models/llama/quantize_impls.py +0 -316
  168. llama_stack/providers/inline/inference/meta_reference/__init__.py +0 -20
  169. llama_stack/providers/inline/inference/meta_reference/common.py +0 -24
  170. llama_stack/providers/inline/inference/meta_reference/config.py +0 -68
  171. llama_stack/providers/inline/inference/meta_reference/generators.py +0 -201
  172. llama_stack/providers/inline/inference/meta_reference/inference.py +0 -542
  173. llama_stack/providers/inline/inference/meta_reference/model_parallel.py +0 -77
  174. llama_stack/providers/inline/inference/meta_reference/parallel_utils.py +0 -353
  175. llama_stack-0.4.3.dist-info/top_level.txt +0 -2
  176. llama_stack_api/__init__.py +0 -945
  177. llama_stack_api/admin/__init__.py +0 -45
  178. llama_stack_api/admin/api.py +0 -72
  179. llama_stack_api/admin/fastapi_routes.py +0 -117
  180. llama_stack_api/admin/models.py +0 -113
  181. llama_stack_api/agents.py +0 -173
  182. llama_stack_api/batches/__init__.py +0 -40
  183. llama_stack_api/batches/api.py +0 -53
  184. llama_stack_api/batches/fastapi_routes.py +0 -113
  185. llama_stack_api/batches/models.py +0 -78
  186. llama_stack_api/benchmarks/__init__.py +0 -43
  187. llama_stack_api/benchmarks/api.py +0 -39
  188. llama_stack_api/benchmarks/fastapi_routes.py +0 -109
  189. llama_stack_api/benchmarks/models.py +0 -109
  190. llama_stack_api/common/__init__.py +0 -5
  191. llama_stack_api/common/content_types.py +0 -101
  192. llama_stack_api/common/errors.py +0 -95
  193. llama_stack_api/common/job_types.py +0 -38
  194. llama_stack_api/common/responses.py +0 -77
  195. llama_stack_api/common/training_types.py +0 -47
  196. llama_stack_api/common/type_system.py +0 -146
  197. llama_stack_api/connectors.py +0 -146
  198. llama_stack_api/conversations.py +0 -270
  199. llama_stack_api/datasetio.py +0 -55
  200. llama_stack_api/datasets/__init__.py +0 -61
  201. llama_stack_api/datasets/api.py +0 -35
  202. llama_stack_api/datasets/fastapi_routes.py +0 -104
  203. llama_stack_api/datasets/models.py +0 -152
  204. llama_stack_api/datatypes.py +0 -373
  205. llama_stack_api/eval.py +0 -137
  206. llama_stack_api/file_processors/__init__.py +0 -27
  207. llama_stack_api/file_processors/api.py +0 -64
  208. llama_stack_api/file_processors/fastapi_routes.py +0 -78
  209. llama_stack_api/file_processors/models.py +0 -42
  210. llama_stack_api/files/__init__.py +0 -35
  211. llama_stack_api/files/api.py +0 -51
  212. llama_stack_api/files/fastapi_routes.py +0 -124
  213. llama_stack_api/files/models.py +0 -107
  214. llama_stack_api/inference.py +0 -1169
  215. llama_stack_api/inspect_api/__init__.py +0 -37
  216. llama_stack_api/inspect_api/api.py +0 -25
  217. llama_stack_api/inspect_api/fastapi_routes.py +0 -76
  218. llama_stack_api/inspect_api/models.py +0 -28
  219. llama_stack_api/internal/kvstore.py +0 -28
  220. llama_stack_api/internal/sqlstore.py +0 -81
  221. llama_stack_api/llama_stack_api/__init__.py +0 -945
  222. llama_stack_api/llama_stack_api/admin/__init__.py +0 -45
  223. llama_stack_api/llama_stack_api/admin/api.py +0 -72
  224. llama_stack_api/llama_stack_api/admin/fastapi_routes.py +0 -117
  225. llama_stack_api/llama_stack_api/admin/models.py +0 -113
  226. llama_stack_api/llama_stack_api/agents.py +0 -173
  227. llama_stack_api/llama_stack_api/batches/__init__.py +0 -40
  228. llama_stack_api/llama_stack_api/batches/api.py +0 -53
  229. llama_stack_api/llama_stack_api/batches/fastapi_routes.py +0 -113
  230. llama_stack_api/llama_stack_api/batches/models.py +0 -78
  231. llama_stack_api/llama_stack_api/benchmarks/__init__.py +0 -43
  232. llama_stack_api/llama_stack_api/benchmarks/api.py +0 -39
  233. llama_stack_api/llama_stack_api/benchmarks/fastapi_routes.py +0 -109
  234. llama_stack_api/llama_stack_api/benchmarks/models.py +0 -109
  235. llama_stack_api/llama_stack_api/common/__init__.py +0 -5
  236. llama_stack_api/llama_stack_api/common/content_types.py +0 -101
  237. llama_stack_api/llama_stack_api/common/errors.py +0 -95
  238. llama_stack_api/llama_stack_api/common/job_types.py +0 -38
  239. llama_stack_api/llama_stack_api/common/responses.py +0 -77
  240. llama_stack_api/llama_stack_api/common/training_types.py +0 -47
  241. llama_stack_api/llama_stack_api/common/type_system.py +0 -146
  242. llama_stack_api/llama_stack_api/connectors.py +0 -146
  243. llama_stack_api/llama_stack_api/conversations.py +0 -270
  244. llama_stack_api/llama_stack_api/datasetio.py +0 -55
  245. llama_stack_api/llama_stack_api/datasets/__init__.py +0 -61
  246. llama_stack_api/llama_stack_api/datasets/api.py +0 -35
  247. llama_stack_api/llama_stack_api/datasets/fastapi_routes.py +0 -104
  248. llama_stack_api/llama_stack_api/datasets/models.py +0 -152
  249. llama_stack_api/llama_stack_api/datatypes.py +0 -373
  250. llama_stack_api/llama_stack_api/eval.py +0 -137
  251. llama_stack_api/llama_stack_api/file_processors/__init__.py +0 -27
  252. llama_stack_api/llama_stack_api/file_processors/api.py +0 -64
  253. llama_stack_api/llama_stack_api/file_processors/fastapi_routes.py +0 -78
  254. llama_stack_api/llama_stack_api/file_processors/models.py +0 -42
  255. llama_stack_api/llama_stack_api/files/__init__.py +0 -35
  256. llama_stack_api/llama_stack_api/files/api.py +0 -51
  257. llama_stack_api/llama_stack_api/files/fastapi_routes.py +0 -124
  258. llama_stack_api/llama_stack_api/files/models.py +0 -107
  259. llama_stack_api/llama_stack_api/inference.py +0 -1169
  260. llama_stack_api/llama_stack_api/inspect_api/__init__.py +0 -37
  261. llama_stack_api/llama_stack_api/inspect_api/api.py +0 -25
  262. llama_stack_api/llama_stack_api/inspect_api/fastapi_routes.py +0 -76
  263. llama_stack_api/llama_stack_api/inspect_api/models.py +0 -28
  264. llama_stack_api/llama_stack_api/internal/__init__.py +0 -9
  265. llama_stack_api/llama_stack_api/internal/kvstore.py +0 -28
  266. llama_stack_api/llama_stack_api/internal/sqlstore.py +0 -81
  267. llama_stack_api/llama_stack_api/models.py +0 -171
  268. llama_stack_api/llama_stack_api/openai_responses.py +0 -1468
  269. llama_stack_api/llama_stack_api/post_training.py +0 -370
  270. llama_stack_api/llama_stack_api/prompts.py +0 -203
  271. llama_stack_api/llama_stack_api/providers/__init__.py +0 -33
  272. llama_stack_api/llama_stack_api/providers/api.py +0 -16
  273. llama_stack_api/llama_stack_api/providers/fastapi_routes.py +0 -57
  274. llama_stack_api/llama_stack_api/providers/models.py +0 -24
  275. llama_stack_api/llama_stack_api/py.typed +0 -0
  276. llama_stack_api/llama_stack_api/rag_tool.py +0 -168
  277. llama_stack_api/llama_stack_api/resource.py +0 -37
  278. llama_stack_api/llama_stack_api/router_utils.py +0 -160
  279. llama_stack_api/llama_stack_api/safety.py +0 -132
  280. llama_stack_api/llama_stack_api/schema_utils.py +0 -208
  281. llama_stack_api/llama_stack_api/scoring.py +0 -93
  282. llama_stack_api/llama_stack_api/scoring_functions.py +0 -211
  283. llama_stack_api/llama_stack_api/shields.py +0 -93
  284. llama_stack_api/llama_stack_api/tools.py +0 -226
  285. llama_stack_api/llama_stack_api/vector_io.py +0 -941
  286. llama_stack_api/llama_stack_api/vector_stores.py +0 -53
  287. llama_stack_api/llama_stack_api/version.py +0 -9
  288. llama_stack_api/models.py +0 -171
  289. llama_stack_api/openai_responses.py +0 -1468
  290. llama_stack_api/post_training.py +0 -370
  291. llama_stack_api/prompts.py +0 -203
  292. llama_stack_api/providers/__init__.py +0 -33
  293. llama_stack_api/providers/api.py +0 -16
  294. llama_stack_api/providers/fastapi_routes.py +0 -57
  295. llama_stack_api/providers/models.py +0 -24
  296. llama_stack_api/py.typed +0 -0
  297. llama_stack_api/rag_tool.py +0 -168
  298. llama_stack_api/resource.py +0 -37
  299. llama_stack_api/router_utils.py +0 -160
  300. llama_stack_api/safety.py +0 -132
  301. llama_stack_api/schema_utils.py +0 -208
  302. llama_stack_api/scoring.py +0 -93
  303. llama_stack_api/scoring_functions.py +0 -211
  304. llama_stack_api/shields.py +0 -93
  305. llama_stack_api/tools.py +0 -226
  306. llama_stack_api/vector_io.py +0 -941
  307. llama_stack_api/vector_stores.py +0 -53
  308. llama_stack_api/version.py +0 -9
  309. {llama_stack-0.4.3.dist-info → llama_stack-0.5.0.dist-info}/WHEEL +0 -0
  310. {llama_stack-0.4.3.dist-info → llama_stack-0.5.0.dist-info}/entry_points.txt +0 -0
  311. {llama_stack-0.4.3.dist-info → llama_stack-0.5.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,358 +0,0 @@
1
-
2
-
3
- # Llama 3.1 - Prompt Formats
4
- ## Tokens
5
- Here is a list of special tokens that are supported by Llama 3.1:
6
- - `<|begin_of_text|>`: Specifies the start of the prompt
7
- - `<|end_of_text|>`: Model will cease to generate more tokens. This token is generated only by the base models.
8
- - `<|finetune_right_pad_id|>`: This token is used for padding text sequences to the same length in a batch.
9
- - `<|start_header_id|>` and `<|end_header_id|>`: These tokens enclose the role for a particular message. The possible roles are: [system, user, assistant and ipython]
10
- - `<|eom_id|>`: End of message. A message represents a possible stopping point for execution where the model can inform the executor that a tool call needs to be made. This is used for multi-step interactions between the model and any available tools. This token is emitted by the model when the Environment: ipython instruction is used in the system prompt, or if the model calls for a built-in tool.
11
- - `<|eot_id|>`: End of turn. Represents when the model has determined that it has finished interacting with the user message that initiated its response. This is used in two scenarios:
12
- - at the end of a direct interaction between the model and the user
13
- - at the end of multiple interactions between the model and any available tools
14
- This token signals to the executor that the model has finished generating a response.
15
- - `<|python_tag|>`: Is a special tag used in the model's response to signify a tool call.
16
-
17
-
18
-
19
- There are 4 different roles that are supported by Llama 3.1
20
- - `system`: Sets the context in which to interact with the AI model. It typically includes rules, guidelines, or necessary information that helps the model respond effectively.
21
- - `user`: Represents the human interacting with the model. It includes the inputs, commands, and questions to the model.
22
- - `ipython`: A new role introduced in Llama 3.1. Semantically, this role means "tool". This role is used to mark messages with the output of a tool call when sent back to the model from the executor.
23
- - `assistant`: Represents the response generated by the AI model based on the context provided in the `system`, `ipython` and `user` prompts.
24
-
25
- ## Llama 3.1 Base Model
26
-
27
- Text completion for Llama 3.1 base model uses this format.
28
-
29
- ##### Input Prompt Format
30
- ```
31
- <|begin_of_text|>Color of sky is blue but sometimes can also be
32
- ```
33
-
34
- ##### Model Response Format
35
- ```
36
- red, orange, yellow, green, purple, pink, brown, gray, black, white, and even rainbow colors. The color of the sky can change due to various reasons such as time of day, weather conditions, pollution, and atmospheric phenomena.
37
- The color of the sky is primarily blue because of a phenomenon called
38
- ```
39
-
40
-
41
-
42
- Note start special tag
43
-
44
-
45
- ## Llama 3.1 Instruct Model
46
- ## User and assistant conversation
47
-
48
- Here is a regular multi-turn user assistant conversation and how its formatted.
49
-
50
- ##### Input Prompt Format
51
- ```
52
- <|begin_of_text|><|start_header_id|>system<|end_header_id|>
53
-
54
- You are a helpful assistant<|eot_id|><|start_header_id|>user<|end_header_id|>
55
-
56
- Answer who are you in the form of jeopardy?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
57
-
58
-
59
- ```
60
-
61
- ##### Model Response Format
62
- ```
63
- Here's my response
64
-
65
- "What is a helpful assistant?"<|eot_id|>
66
- ```
67
-
68
-
69
-
70
-
71
-
72
-
73
- ## Tool Calling Formats
74
-
75
-
76
- The three built-in tools (brave_search, wolfram_alpha, and code interpreter) can be turned on using the system prompt:
77
- - Brave Search: Tool call to perform web searches.
78
- - Wolfram Alpha: Tool call to perform complex mathematical calculations.
79
- - Code Interpreter: Enables the model to output python code.
80
-
81
- ## Builtin Tool Calling
82
-
83
-
84
- Here is an example of a conversation using brave search
85
-
86
-
87
- ##### Input Prompt Format
88
- ```
89
- <|begin_of_text|><|start_header_id|>system<|end_header_id|>
90
-
91
- Environment: ipython
92
- Tools: brave_search, wolfram_alpha
93
- Cutting Knowledge Date: December 2023
94
- Today Date: 21 September 2024
95
-
96
- You are a helpful assistant.
97
- <|eot_id|><|start_header_id|>user<|end_header_id|>
98
-
99
- Search the web for the latest price of 1oz gold?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
100
-
101
-
102
- ```
103
-
104
- ##### Model Response Format
105
- ```
106
- <|python_tag|>brave_search.call(query="latest price of 1oz gold")<|eom_id|>
107
- ```
108
-
109
-
110
-
111
-
112
- - Just including Environment: ipython turns on code interpreter; therefore, you don't need to specify code interpretation on the Tools: line. The model can generate python code which is interpreted by the executor, with the result provided back to the model.
113
- - The message body of the assistant response starts with a special tag <|python_tag|>
114
- - As alluded to above, in such an environment, the model can generate <|eom_id|> instead of just the standard <|eot_id|> . The latter indicates the turn is finished, while the former indicates continued multi-step reasoning. That is, the model is expecting a continuation message with the output of the tool call.
115
- - The model tool call response is of the form `tool.call(query="...")` wher tool is `brave_search` or `wolfram_alpha`
116
-
117
-
118
- ## Builtin Code Interpreter
119
-
120
- Here is an actual example of model responding with code
121
-
122
- ##### Input Prompt Format
123
- ```
124
- <|begin_of_text|><|start_header_id|>system<|end_header_id|>
125
-
126
- Environment: ipython<|eot_id|><|start_header_id|>user<|end_header_id|>
127
-
128
- Write code to check if number is prime, use that to see if the number 7 is prime<|eot_id|><|start_header_id|>assistant<|end_header_id|>
129
-
130
-
131
- ```
132
-
133
- ##### Model Response Format
134
- ```
135
- <|python_tag|>def is_prime(n):
136
- if n <= 1
137
- return False
138
- for i in range(2, int(n**0.5) + 1):
139
- if n % i == 0:
140
- return False
141
- return True
142
-
143
- print(is_prime(7)) # Output: True<|eom_id|>
144
- ```
145
-
146
-
147
-
148
-
149
- - Model starts with <|python_tag|> and continues writing python code that it needs to be executed
150
- - No explicit mention of code_interpreter in system prompt. `Environment: ipython` implicitly enables it.
151
-
152
-
153
- ## Built-in tools full interaction
154
-
155
- Here is a full interaction with the built-in tools including the tool response and the final assistant response.
156
-
157
- ##### Input Prompt Format
158
- ```
159
- <|begin_of_text|><|start_header_id|>system<|end_header_id|>
160
-
161
- Environment: ipython
162
- Tools: brave_search, wolfram_alpha
163
- <|eot_id|><|start_header_id|>user<|end_header_id|>
164
-
165
- What is the 100th decimal of pi?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
166
-
167
- <|python_tag|>wolfram_alpha.call(query="100th decimal of pi")<|eom_id|><|start_header_id|>ipython<|end_header_id|>
168
-
169
-
170
- {
171
- "queryresult": {
172
- "success": true,
173
- "inputstring": "100th decimal of pi",
174
- "pods": [
175
- {
176
- "title": "Input interpretation",
177
- "subpods": [
178
- {
179
- "title": "",
180
- "plaintext": "100th digit | π"
181
- }
182
- ]
183
- },
184
- {
185
- "title": "Nearby digits",
186
- "subpods": [
187
- {
188
- "title": "",
189
- "plaintext": "...86208998628034825342117067982148086513282306647093..."
190
- }
191
- ]
192
- },
193
- {
194
- "title": "Result",
195
- "primary": true,
196
- "subpods": [
197
- {
198
- "title": "",
199
- "plaintext": "7"
200
- }
201
- ]
202
- }
203
- ]
204
- }
205
- }
206
- <|eot_id|><|start_header_id|>assistant<|end_header_id|>
207
-
208
-
209
- ```
210
-
211
- ##### Model Response Format
212
- ```
213
- The 100th decimal of pi is 7.<|eot_id|>
214
- ```
215
-
216
-
217
-
218
-
219
- - Note the `<|python_tag|>` in the assistant response.
220
- - Role is `ipython` for the wolfram alpha response that is passed back to the model.
221
- - Final message from assistant has <|eot_id|> tag.
222
-
223
-
224
-
225
- ## Zero shot tool calling
226
- ## JSON based tool calling
227
-
228
-
229
- Llama models can now output custom tool calls from a single message to allow easier tool calling.
230
- The following prompts provide an example of how custom tools can be called from the output of the model.
231
- It's important to note that the model itself does not execute the calls; it provides structured output to facilitate calling by an executor.
232
-
233
-
234
- ##### Input Prompt Format
235
- ```
236
- <|begin_of_text|><|start_header_id|>system<|end_header_id|>
237
-
238
- Environment: ipython
239
-
240
- Cutting Knowledge Date: December 2023
241
- Today Date: 21 September 2024
242
-
243
- You are a helpful assistant.
244
- <|eot_id|><|start_header_id|>user<|end_header_id|>
245
-
246
- Answer the user's question by making use of the following functions if needed.
247
- If none of the function can be used, please say so.
248
- Here is a list of functions in JSON format:
249
- {
250
- "type": "function",
251
- "function": {
252
- "name": "trending_songs",
253
- "description": "Returns the trending songs on a Music site",
254
- "parameters": {
255
- "type": "object",
256
- "properties": [
257
- {
258
- "n": {
259
- "type": "object",
260
- "description": "The number of songs to return"
261
- }
262
- },
263
- {
264
- "genre": {
265
- "type": "object",
266
- "description": "The genre of the songs to return"
267
- }
268
- }
269
- ],
270
- "required": ["n"]
271
- }
272
- }
273
- }
274
-
275
- Return function calls in JSON format.<|eot_id|><|start_header_id|>user<|end_header_id|>
276
-
277
- Use tools to get latest trending songs<|eot_id|><|start_header_id|>assistant<|end_header_id|>
278
-
279
-
280
- ```
281
-
282
- ##### Model Response Format
283
- ```
284
- <|python_tag|>{
285
- "type": "function",
286
- "name": "trending_songs",
287
- "parameters": {
288
- "n": "10",
289
- "genre": "all"
290
- }
291
- }<|eom_id|>
292
- ```
293
-
294
-
295
-
296
-
297
- - JSON format for providing tools needs name, description and parameters
298
- - Model responds with `<|python_tag|>` and `<|eom_id|>` as `Environment: ipython` was in the system prompt
299
- - Instructions for tools added as a user message
300
- - Only single tool calls are supported as of now
301
-
302
-
303
-
304
- ## Example of a user defined tool calling
305
- ## `<function>` based tool calling
306
-
307
-
308
- Here is an example of how you could also write custom instructions for model to do zero shot tool calling.
309
- In this example, we define a custom tool calling format using the `<function>` tag.
310
-
311
-
312
- ##### Input Prompt Format
313
- ```
314
- <|begin_of_text|><|start_header_id|>system<|end_header_id|>
315
-
316
- Environment: ipython
317
-
318
- Cutting Knowledge Date: December 2023
319
- Today Date: 21 September 2024
320
-
321
- You are a helpful assistant.
322
- <|eot_id|><|start_header_id|>user<|end_header_id|>
323
-
324
- You have access to the following functions:
325
-
326
- Use the function 'trending_songs' to 'Returns the trending songs on a Music site':
327
- {"name": "trending_songs", "description": "Returns the trending songs on a Music site", "parameters": {"genre": {"description": "The genre of the songs to return", "param_type": "str", "required": false}, "n": {"description": "The number of songs to return", "param_type": "int", "required": true}}}
328
-
329
- Think very carefully before calling functions.
330
- If you choose to call a function ONLY reply in the following format with no prefix or suffix:
331
-
332
- <function=example_function_name>{"example_name": "example_value"}</function>
333
-
334
- Reminder:
335
- - If looking for real time information use relevant functions before falling back to brave_search
336
- - Function calls MUST follow the specified format, start with <function= and end with </function>
337
- - Required parameters MUST be specified
338
- - Only call one function at a time
339
- - Put the entire function call reply on one line<|eot_id|><|start_header_id|>user<|end_header_id|>
340
-
341
- Use tools to get latest trending songs<|eot_id|><|start_header_id|>assistant<|end_header_id|>
342
-
343
-
344
- ```
345
-
346
- ##### Model Response Format
347
- ```
348
- <function=trending_songs>{"n": 10}</function><|eot_id|>
349
- ```
350
-
351
-
352
-
353
-
354
- - In this case, model does NOT respond with `<|python_tag|>` and ends with `<|eot_id|>`
355
- - Instructions for tools added as a user message
356
-
357
-
358
- Thank You!
@@ -1,258 +0,0 @@
1
- # Copyright (c) Meta Platforms, Inc. and affiliates.
2
- # All rights reserved.
3
- #
4
- # This source code is licensed under the terms described in the LICENSE file in
5
- # the root directory of this source tree.
6
-
7
- # Copyright (c) Meta Platforms, Inc. and affiliates.
8
- # All rights reserved.
9
- #
10
- # This source code is licensed under the terms described in the LICENSE file in
11
- # top-level folder for each specific model found within the models/ directory at
12
- # the top-level of this source tree.
13
-
14
- import json
15
- import textwrap
16
-
17
- from llama_stack.models.llama.datatypes import (
18
- BuiltinTool,
19
- RawMessage,
20
- StopReason,
21
- ToolCall,
22
- ToolPromptFormat,
23
- )
24
- from llama_stack.models.llama.prompt_format import (
25
- # llama3_1_e2e_tool_call_dialog,
26
- TextCompletionContent,
27
- UseCase,
28
- llama3_1_builtin_tool_call_dialog,
29
- llama3_1_custom_tool_call_dialog,
30
- )
31
-
32
-
33
- def wolfram_alpha_response():
34
- return textwrap.dedent(
35
- """
36
- {
37
- "queryresult": {
38
- "success": true,
39
- "inputstring": "100th decimal of pi",
40
- "pods": [
41
- {
42
- "title": "Input interpretation",
43
- "subpods": [
44
- {
45
- "title": "",
46
- "plaintext": "100th digit | \u03c0"
47
- }
48
- ]
49
- },
50
- {
51
- "title": "Nearby digits",
52
- "subpods": [
53
- {
54
- "title": "",
55
- "plaintext": "...86208998628034825342117067982148086513282306647093..."
56
- }
57
- ]
58
- },
59
- {
60
- "title": "Result",
61
- "primary": true,
62
- "subpods": [
63
- {
64
- "title": "",
65
- "plaintext": "7"
66
- }
67
- ]
68
- }
69
- ]
70
- }
71
- }
72
- """
73
- )
74
-
75
-
76
- def usecases() -> list[UseCase | str]:
77
- return [
78
- textwrap.dedent(
79
- """
80
- # Llama 3.1 - Prompt Formats
81
- ## Tokens
82
- Here is a list of special tokens that are supported by Llama 3.1:
83
- - `<|begin_of_text|>`: Specifies the start of the prompt
84
- - `<|end_of_text|>`: Model will cease to generate more tokens. This token is generated only by the base models.
85
- - `<|finetune_right_pad_id|>`: This token is used for padding text sequences to the same length in a batch.
86
- - `<|start_header_id|>` and `<|end_header_id|>`: These tokens enclose the role for a particular message. The possible roles are: [system, user, assistant and tool]
87
- - `<|eom_id|>`: End of message. A message represents a possible stopping point for execution where the model can inform the executor that a tool call needs to be made. This is used for multi-step interactions between the model and any available tools. This token is emitted by the model when the Environment: ipython instruction is used in the system prompt, or if the model calls for a built-in tool.
88
- - `<|eot_id|>`: End of turn. Represents when the model has determined that it has finished interacting with the user message that initiated its response. This is used in two scenarios:
89
- - at the end of a direct interaction between the model and the user
90
- - at the end of multiple interactions between the model and any available tools
91
- This token signals to the executor that the model has finished generating a response.
92
- - `<|python_tag|>`: Is a special tag used in the model's response to signify a tool call.
93
- """
94
- ),
95
- textwrap.dedent(
96
- """
97
- There are 4 different roles that are supported by Llama 3.1
98
- - `system`: Sets the context in which to interact with the AI model. It typically includes rules, guidelines, or necessary information that helps the model respond effectively.
99
- - `user`: Represents the human interacting with the model. It includes the inputs, commands, and questions to the model.
100
- - `tool`: A new role introduced in Llama 3.1. This role is used to mark messages with the output of a tool call when sent back to the model from the executor. (The actual token used by the model for this role is "ipython".)
101
- - `assistant`: Represents the response generated by the AI model based on the context provided in the `system`, `tool` and `user` prompts.
102
- """
103
- ),
104
- UseCase(
105
- title="Llama 3.1 Base Model",
106
- description="Text completion for Llama 3.1 base model uses this format.",
107
- dialogs=[TextCompletionContent(content="Color of sky is blue but sometimes can also be")],
108
- notes="Note start special tag",
109
- ),
110
- "## Llama 3.1 Instruct Model",
111
- UseCase(
112
- title="User and assistant conversation",
113
- description="Here is a regular multi-turn user assistant conversation and how its formatted.",
114
- dialogs=[
115
- [
116
- RawMessage(role="system", content="You are a helpful assistant"),
117
- RawMessage(
118
- role="user",
119
- content="Answer who are you in the form of jeopardy?",
120
- ),
121
- ]
122
- ],
123
- notes="",
124
- ),
125
- "## Tool Calling Formats",
126
- textwrap.dedent(
127
- """
128
- The three built-in tools (brave_search, wolfram_alpha, and code interpreter) can be turned on using the system prompt:
129
- - Brave Search: Tool call to perform web searches.
130
- - Wolfram Alpha: Tool call to perform complex mathematical calculations.
131
- - Code Interpreter: Enables the model to output python code.
132
- """
133
- ),
134
- UseCase(
135
- title="Builtin Tool Calling",
136
- description=textwrap.dedent(
137
- """
138
- Here is an example of a conversation using brave search
139
- """
140
- ),
141
- dialogs=[llama3_1_builtin_tool_call_dialog()],
142
- notes=textwrap.dedent(
143
- """
144
- - Just including Environment: ipython turns on code interpreter; therefore, you don't need to specify code interpretation on the Tools: line. The model can generate python code which is interpreted by the executor, with the result provided back to the model.
145
- - The message body of the assistant response starts with a special tag <|python_tag|>
146
- - As alluded to above, in such an environment, the model can generate <|eom_id|> instead of just the standard <|eot_id|> . The latter indicates the turn is finished, while the former indicates continued multi-step reasoning. That is, the model is expecting a continuation message with the output of the tool call.
147
- - The model tool call response is of the form `tool.call(query="...")` wher tool is `brave_search` or `wolfram_alpha`
148
- """
149
- ),
150
- ),
151
- UseCase(
152
- title="Builtin Code Interpreter",
153
- description="Here is an actual example of model responding with code",
154
- dialogs=[
155
- [
156
- RawMessage(role="system", content="Environment: ipython"),
157
- RawMessage(
158
- role="user",
159
- content="Write code to check if number is prime, use that to see if the number 7 is prime",
160
- ),
161
- ],
162
- ],
163
- notes=textwrap.dedent(
164
- """
165
- - Model starts with <|python_tag|> and continues writing python code that it needs to be executed
166
- - No explicit mention of code_interpreter in system prompt. `Environment: ipython` implicitly enables it.
167
- """
168
- ),
169
- ),
170
- UseCase(
171
- title="Built-in tools full interaction",
172
- description="Here is a full interaction with the built-in tools including the tool response and the final assistant response.",
173
- dialogs=[
174
- [
175
- RawMessage(
176
- role="system",
177
- content="Environment: ipython\nTools: brave_search, wolfram_alpha\n",
178
- ),
179
- RawMessage(role="user", content="What is the 100th decimal of pi?"),
180
- RawMessage(
181
- role="assistant",
182
- content="",
183
- stop_reason=StopReason.end_of_message,
184
- tool_calls=[
185
- ToolCall(
186
- call_id="tool_call_id",
187
- tool_name=BuiltinTool.wolfram_alpha,
188
- arguments=json.dumps({"query": "100th decimal of pi"}),
189
- )
190
- ],
191
- ),
192
- RawMessage(
193
- role="tool",
194
- content=wolfram_alpha_response(),
195
- ),
196
- ],
197
- ],
198
- notes=textwrap.dedent(
199
- """
200
- - Note the `<|python_tag|>` in the assistant response.
201
- - Role is `tool` for the wolfram alpha response that is passed back to the model.
202
- - Final message from assistant has <|eot_id|> tag.
203
- """
204
- ),
205
- ),
206
- "## Zero shot tool calling",
207
- UseCase(
208
- title="JSON based tool calling",
209
- description=textwrap.dedent(
210
- """
211
- Llama models can now output custom tool calls from a single message to allow easier tool calling.
212
- The following prompts provide an example of how custom tools can be called from the output of the model.
213
- It's important to note that the model itself does not execute the calls; it provides structured output to facilitate calling by an executor.
214
- """
215
- ),
216
- dialogs=[llama3_1_custom_tool_call_dialog()],
217
- notes=textwrap.dedent(
218
- """
219
- - JSON format for providing tools needs name, description and parameters
220
- - Model responds with `<|python_tag|>` and `<|eom_id|>` as `Environment: ipython` was in the system prompt
221
- - Instructions for tools added as a user message
222
- - Only single tool calls are supported as of now
223
- """
224
- ),
225
- ),
226
- # FIXME: This is not working yet as expected
227
- # UseCase(
228
- # title="E2E tool call example",
229
- # description=textwrap.dedent(
230
- # """
231
- # Here is an example showing the whole multi-step turn by taking custom tool outputs and passing back to the model.
232
- # """
233
- # ),
234
- # dialogs=[
235
- # llama3_1_e2e_tool_call_dialog(
236
- # tool_prompt_format=ToolPromptFormat.function_tag
237
- # )
238
- # ],
239
- # notes="",
240
- # ),
241
- "## Example of a user defined tool calling",
242
- UseCase(
243
- title="`<function>` based tool calling",
244
- description=textwrap.dedent(
245
- """
246
- Here is an example of how you could also write custom instructions for model to do zero shot tool calling.
247
- In this example, we define a custom tool calling format using the `<function>` tag.
248
- """
249
- ),
250
- dialogs=[llama3_1_custom_tool_call_dialog(ToolPromptFormat.function_tag)],
251
- notes=textwrap.dedent(
252
- """
253
- - In this case, model does NOT respond with `<|python_tag|>` and ends with `<|eot_id|>`
254
- - Instructions for tools added as a user message
255
- """
256
- ),
257
- ),
258
- ]
@@ -1,5 +0,0 @@
1
- # Copyright (c) Meta Platforms, Inc. and affiliates.
2
- # All rights reserved.
3
- #
4
- # This source code is licensed under the terms described in the LICENSE file in
5
- # the root directory of this source tree.