ã¯ããã«
ã¹ã¿ãã¼1ã3å¹ãªãªã¤ãããããã¨ããããã¾ããï¼ nikkieã§ãã
ä¸ã¯ã¾ãã«å¤§LLMæ代ï¼
æ¥ã
æ°ãããã¼ã«ãã©ãã©ãç»å ´ãã¦ãã¾ãã
ãã®ä¸ããï¼æè¿åºã¦ãããã¼ã«ã§ã¯ãªãã§ããï¼Microsoftã«ããPrompt flowã触ãã¾ããã
ç®æ¬¡
Prompt flow
Azureã®æ©æ¢°å¦ç¿æ©è½ã®1ã¤ã¨ãã¦å§ã¾ãã1å¹´ãããåããOSSã«ãªã£ãããã§ãã
Prompt flowã£ã¦å ã Azure MLã®1æ©è½ã ã£ããã©ãä»ã¯MITã©ã¤ã»ã³ã¹ã®OSSãªã®ã§ãAzure使ããªãã¦ãå©ç¨ãå¯è½ã§ããVSCodeæ¡å¼µã§GUIã§ãã¼ã«ã«éçºããªããDockerã³ã³ããã«ãã¦APIã¨ãã¦å¤é¨ã®ãµã¼ãã¸ãããã¤ãããã¨ãå¯è½ã
— Hirosato Gamo | AI Cloud Solution Architect (@hiro_gamo) 2024å¹´1æ31æ¥
OSSã¨ãã¦ã®Prompt flowã®ããã¥ã¡ã³ãã¯âhttps://t.co/F1xYn7qPqO pic.twitter.com/OxLqwjEXdw
ããã¥ã¡ã³ã
Pythonã©ã¤ãã©ãªï¼SDKï¼
https://pypi.org/project/promptflow/
Prompt flowããã¼ã«ã«ã§åãã
ãã¥ã¼ãã£ã¼æè¡ããã°ãåèã«ãã¾ããï¼å·çã«æè¬ð«¶ï¼
ç°å¢æ§ç¯
- uv 0.5.17 (Homebrew 2025-01-10)
- Python 3.11.8
- promptflow 1.17.1
- promptflow-tools 1.4.0
- VS Codeæ¡å¼µãPrompt flow for VS Codeããã¤ã³ã¹ãã¼ã«
ä¾åã©ã¤ãã©ãªã®è©³ç´°ãªãã¼ã¸ã§ã³ã¯uv.lock
ãåç
§ãã ããã
https://github.com/ftnext/ml-playground/blob/9634078896ee7772ec4f34ae04a06e5a87cdc5e9/promptflow/uv.lock
ç°å¢æ§ç¯å¾ã«pf
ã³ãã³ãã使ããããã«ãªã£ã¦ãã¾ãã
% uv run pf --help usage: pf [-h] [-v] {config,connection,flow,run,tool,trace,service,upgrade} ... pf: manage prompt flow assets. Learn more: https://microsoft.github.io/promptflow.
Connectionã®ä½æ
Connectionã¨ã¯ãLLMã®ãããªå¤é¨ãµã¼ãã¹ã«ã¢ã¯ã»ã¹ããããã®æ
å ±ãä¿åãããã®1ã
https://microsoft.github.io/promptflow/concepts/concept-connections.html
ä»åã¯OpenAIã®LLMï¼GPTï¼ã使ãããã®APIãã¼ãªã©ã§ãã
Connectionã¯YAMLããèªã¿è¾¼ãããã§ã以ä¸ããã¯ã£ããã¡ã¤ã«ãä½ãã¾ãã
https://github.com/microsoft/promptflow/blob/promptflow_1.17.1/examples/connections/openai.yml
. âââ .venv/ âââ connections/ â âââ openai.yml # ãã¯ã£ã¦ä½æ âââ pyproject.toml âââ uv.lock
Connectionä½æã³ãã³ã
ï¼ç°å¢å¤æ°OPENAI_API_KEY
ãè¨å®æ¸ã¿ã§ã2ï¼
% uv run pf connection create --file connections/openai.yml --set api_key=$OPENAI_API_KEY
uv run pf connection list
ã§ãopen_ai_connectionãããããã¨ã確èªã§ãã¾ã
Flowã®ä½æ
Flowã¨ã¯ãï¼Prompt flowãä½é¨ããææ³ãæ··ããã¾ãããï¼LLMã使ã£ãã¢ããªã±ã¼ã·ã§ã³ã®è¡¨ç¾ã¨ããç解ã§ãã
DAGï¼æåéå·¡åã°ã©ãï¼ã§è¡¨ç¾ãããã¯ã¼ã¯ããã¼ã®ãããªæãã§ãã3ã
ref: https://microsoft.github.io/promptflow/concepts/concept-flows.html#dag-flow
å®ä½ã¯ãã£ã¬ã¯ããªã«ç½®ããããã¡ã¤ã«ä¸å¼ã¨æãã¦ãã¾ãã
Flowä½æã³ãã³ã
% uv run pf flow init --flow my-first-flow
my-first-flow
ãã£ã¬ã¯ããªä»¥ä¸ãã¹ãã£ãã©ã¼ã«ãã£ã³ã°ããã¾ãã
. âââ .venv/ âââ connections/ â âââ openai.yml âââ my-first-flow/ â âââ .promptflow/ â â âââ flow.tools.json â âââ .gitignore â âââ data.jsonl â âââ flow.dag.yaml â âââ hello.jinja2 â âââ hello.py â âââ requirements.txt âââ pyproject.toml âââ uv.lock
Prompt flowã¯ãããã³ããï¼ãã³ãã¬ã¼ãã¨ã³ã¸ã³ Jinja2ããµãã¼ãï¼ãPythonã³ã¼ãï¼ã¹ã¯ãªããï¼ãã¤ãªãã§Flowãæ§æã§ããããã§ãã
ãããªãã¨ã§ãããã ãã¨ãªã£ãä¾ããã¡ãï¼
https://github.com/microsoft/promptflow/tree/promptflow_1.17.1/examples/flows/standard/web-classification
Flowã«URLã渡ãããã¨ãã¹ã¯ãªããã§HTMLãåå¾ãã¦ãLLMã«ããã³ãããéã£ã¦è¦ç´ãåé¡ãããã¦ãã¾ã
ä»åã¯ãã¢ãã¾ãã¨ãLLMãå¼ã³åºãã ãã¨ãã¾ããã
ã¹ãã£ãã©ã¼ã«ãããããã¡ã¤ã«ã®ãã¡ä½¿ããªããã®ãåé¤ãã¦
. âââ .venv/ âââ connections/ â âââ openai.yml âââ my-first-flow/ â âââ .promptflow/ â â âââ flow.tools.json â âââ .gitignore â âââ flow.dag.yaml â âââ llm_node.jinja2 # æ°è¦ä½æï¼LLMã«éãããã³ããï¼ âââ pyproject.toml âââ uv.lock
flow.dag.yaml
ã¯VS Codeæ¡å¼µã«ãããVisual editorã§ãéãã¾ãã
ä»åã¯æ§æè¦ç´ ãå°ãªãããã¼ãªã®ã§ãYAMLãç´ã§æ¸ãã¾ãã
$schema: https://azuremlschemas.azureedge.net/promptflow/latest/Flow.schema.json inputs: text: type: string default: ããã«ã¡ã¯ï¼ããªãã®ãã¨ããªãã¨å¼ã¹ã°ããã§ããï¼ outputs: response: type: string reference: ${llm_node.output} nodes: - name: llm_node type: llm source: type: code path: llm_node.jinja2 inputs: model: gpt-4o-mini max_tokens: 20 question: ${inputs.text} connection: open_ai_connection api: chat
Flowå®è¡ï¼
Flow my-first-flow
ããã¹ãå®è¡ãã¾ãã
ããã©ã«ãå¤ã使ããã¦ãã¾ãï¼--inputs
å¼æ°ã§ä¸ãããããã¾ãï¼
% uv run pf flow test --flow my-first-flow Starting prompt flow service... Start prompt flow service on 127.0.0.1:23334, version: 1.17.1. You can stop the prompt flow service with the following command:'pf service stop'. 2025-01-12 12:15:16 +0900 55641 execution.flow INFO Start executing nodes in thread pool mode. 2025-01-12 12:15:16 +0900 55641 execution.flow INFO Start to run 1 nodes with concurrency level 16. 2025-01-12 12:15:16 +0900 55641 execution.flow INFO Executing node llm_node. node run id: ca010d9c-b109-4868-bef2-541d48b4b953_llm_node_0 2025-01-12 12:15:16 +0900 55641 execution.flow INFO Node llm_node completes. { "response": "ããã«ã¡ã¯ï¼ç§ã¯AIã¢ã·ã¹ã¿ã³ãã§ãã®ã§ããã¢ã·ã¹ã¿ã³ããã¨å¼ãã§ãã" }
% uv run pf flow test --flow my-first-flow --inputs text='Prompt flowã§å·æ³ãè© ãã§' { "response": "ãã¡ããã§ãï¼å·æ³ãè© ã¿ã¾ããã\n\næ¥ã®é¢¨ \næ¡èã" }
OpenAIã®LLMï¼GPT-4o-miniï¼ã«ãããã³ãããéããã¨ãã§ãã¾ããï¼4
çµããã«
Prompt flowããã¼ã«ã«ã§åããã¾ããã
LLMé¢ä¿ã®ãã¼ã«ã¯ã©ã¡ããã¨ããã¨è¿½ãã¦ããªã身ãªã®ã§ããPrompt flowç¥ã£ã¦ãããããã¾ã§ã®LLMã¢ããªã®éçºãå°ãã¯æ¥½ã§ãããããªãã¨ããææ³ã§ãã
LangChainã§ããªããªæ¸ãã¦ãããã¨æãã¾ãããPrompt flowã¯ããã³ãããã¹ã¯ãªãããã¤ãªãã§ãã¿ã´ã©ã¹ã¤ããçã«LLMã¢ããªãçµã¿ä¸ããã¨ããã¢ããã¼ãã ã¨æã£ã¦ãã¾ãã
éçºè
åãDifyçãªï¼
ä»åã¯çé確èªã§ã触ã£ãã®ã¯ããããä¸é¨ã®æ©è½ã§ãã
å¤éã®ãã¼ã¿ã§å®è¡ãã§ãã¾ãããããã³ãããå¤æ´ããæã®è©ä¾¡ãã§ããã¿ããã§ãã
ãªãã¸ããªãã¯ãã¼ã³ãã¦Connectionã ãè¨å®ããããï¼uvã®åãåãã¦ï¼ä»ã®æ¹ã®æå ã§ãåãããããããªããã¨æãã¾ã
- ããã¥ã¡ã³ãã§ã¯ãConnections are for storing information about how to access external services like LLMs: endpoint, api keys etc.ã↩
- ç°å¢å¤æ°ãåç §ããããã«ãæ¸ããããã§ãããref: https://microsoft.github.io/promptflow/how-to-guides/manage-connections.html#load-from-environment-variables↩
- standard flowãä»å触ã£ã¦ãã¾ã↩
-
ãªãç§ã¯æªè¨å®ãªã®ã§ãYAMLã®modelã
o1
ã«å¤ããã¨ã¨ã©ã¼ãè¿ãã¾ãããThe modelo1
does not exist or you do not have access to it.ã↩