工作流介绍
- 了解工作流对大模型进行高质量工作的辅助意义
- 学会复现吴恩达博士的翻译工作流开源项目
- 了解构成大模型工作流系统的关键元素
- 学会搭建一个更复杂的业务场景工作流
一、为什么我们需要工作流?
❓ 什么样的职场打工人是合格的打工人?
- 反应快,理解能力强?
- 有相关经验,学过相关学科?
- 有行动力,不纸上谈兵,还要能下地干活?
哪些因素会影响大模型应用的效果?
- 模型能力(智力)
- 通识理解和泛化能力
- 输入信息理解、推理、规划、执行能力
- 输入信息补充知识学习能力
- 文字生成创作的风格
- 相关信息(知识)
- 与任务相关的信息
- 与互动背景相关的信息
- 模型输出控制(行动方法)
- 单次请求控制
- Prompt表达优化
- 以CoT为代表的思维链控制方法
- 输出格式控制(文本格式语法、工程结构化数据输出…)
- 多次请求控制
- 以ReAct(Action-Observation-Reflection)为代表的多轮自我反思优化
- 复杂任务的执行过程编排管理
- 单次请求控制
单次请求的局限性
- 上下文窗口长度限制、输出长度限制(早期的LangChain长文本Summarize)
- 直接进行CoT控制(尤其是用自然语言表达CoT)会输出思考过程,但我们不希望用户看到这个过程
- 随着工作进展出现的新信息,对任务时序、编排有依赖的信息,不一定能在单次请求中一次性完成输入
工作流的优势
- 将工作任务拆分成多个工作节点
- 能够将模型单次请求调用视作一个工作节点
- 能够灵活将其他代码逻辑也写入工作节点
- 能够对工作节点进行任务编排
- 能够在工作节点之间进行数据传递
[试一试]
直接请求模型的效果:
from ENV import deep_seek_url, deep_seek_api_key, deep_seek_default_model
import Agently
agent = (Agently.create_agent().set_settings("current_model", "OAIClient").set_settings("model.OAIClient.url", deep_seek_url).set_settings("model.OAIClient.auth", { "api_key": deep_seek_api_key }).set_settings("model.OAIClient.options", { "model": deep_seek_default_model })
)result = agent.input(input("[请输入您的要求]: ")).start()
print("[回复]: ", result)
使用工作流:
workflow = Agently.Workflow()@workflow.chunk()
def user_input(inputs, storage):storage.set("user_input", input("[请输入您的要求]: "))return@workflow.chunk()
def judge_intent_and_quick_reply(inputs, storage):result = (agent.input(storage.get("user_input")).output({"user_intent": ("闲聊 | 售后问题 | 其他", "判断用户提交的{input}内容属于给定选项中的哪一种"),"quick_reply": ("str",
"""如果{user_intent}=='闲聊',那么直接给出你的回应;
如果{user_intent}=='售后问题',那么请用合适的方式告诉用户你已经明白用户的诉求,安抚客户情绪并请稍等你去看看应该如何处理;
如果{user_intent}=='其他',此项输出null""")}).start())storage.set("reply", result["quick_reply"])return result["user_intent"]@workflow.chunk()
def generate_after_sales_reply(inputs, storage):storage.set("reply", (agent.input(storage.get("user_input")).instruct(
"""请根据{input}的要求,以一个专业客户服务人员的角色给出回复,遵循如下模板进行回复:
亲爱的客户,感谢您的耐心等待。
我理解您希望{{复述客户的要求}},是因为{{复述客户要求提出要求的理由}},您的心情一定非常{{阐述你对客户心情/感受的理解}}。
{{给出对客户当前心情的抚慰性话语}}。
我们会尽快和相关人员沟通,并尽量进行满足。请留下您的联系方式以方便我们尽快处理后与您联系。
"""
).start()))return@workflow.chunk()
def generate_other_topic_reply(inputs, storage):storage.set("reply", "我们好像不应该聊这个,还是回到您的问题或诉求上来吧。")return@workflow.chunk_class()
def reply(inputs, storage):print("[回复]: ", storage.get("reply"))return(workflow.connect_to("user_input").connect_to("judge_intent_and_quick_reply").if_condition(lambda return_value, storage: return_value=="闲聊").connect_to("@reply").connect_to("end").elif_condition(lambda return_value, storage: return_value=="售后问题").connect_to("@reply").connect_to("generate_after_sales_reply").connect_to("@reply").connect_to("user_input").else_condition().connect_to("generate_other_topic_reply").connect_to("@reply").connect_to("END")
)workflow.start()
pass
二、让我们从吴恩达博士的开源翻译工作流项目说起
-
项目地址:https://github.com/andrewyng/translation-agent
-
项目基本思路:
- 让模型在完成首轮翻译之后,通过自我反思后修正的工作流优化翻译结果,以提升最终文本翻译的质量
-
关键步骤:
-
第一步:
- 输入信息:原始文本语言(source_lang) 、翻译目标语言(target_lang) 和 原始文本(source_text)
- 角色设定:以翻译文本为任务目标的语言学家
- 输出结果:基于所有输入信息,对 原始文本(source_text) 进行 第一轮翻译的结果(translation_1);
-
第二步:
- 输入信息:原始文本语言(source_lang) 、翻译目标语言(target_lang) 、 原始文本(source_text) 和 第一轮翻译结果(translation_1)
- 角色设定:以阅读原始文本和翻译文本,并给出翻译改进意见为任务目标的语言学家
- 输出结果:基于所有输入信息,对 第一轮翻译结果(translation_1) 提出的 改进意见反思(reflection)
-
第三步:
- 输入信息:原始文本语言(source_lang) 、翻译目标语言(target_lang) 、 原始文本(source_text) 、 第一轮翻译结果(translation_1) 和 改进意见反思(reflection)
- 角色设定:以翻译文本为任务目标的语言学家(和第一步相同)
- 输出结果:基于所有输入信息,给出的第二轮优化后翻译结果(translation_2)
-
-
关键代码文件:https://github.com/andrewyng/translation-agent/blob/main/src/translation_agent/utils.py
-
关键代码片段:
def one_chunk_initial_translation(source_lang: str, target_lang: str, source_text: str ) -> str:"""Translate the entire text as one chunk using an LLM.Args:source_lang (str): The source language of the text.target_lang (str): The target language for translation.source_text (str): The text to be translated.Returns:str: The translated text."""system_message = f"You are an expert linguist, specializing in translation from {source_lang} to {target_lang}."translation_prompt = f"""This is an {source_lang} to {target_lang} translation, please provide the {target_lang} translation for this text. \ Do not provide any explanations or text apart from the translation. {source_lang}: {source_text}{target_lang}:"""prompt = translation_prompt.format(source_text=source_text)translation = get_completion(prompt, system_message=system_message)return translationdef one_chunk_reflect_on_translation(source_lang: str,target_lang: str,source_text: str,translation_1: str,country: str = "", ) -> str:"""Use an LLM to reflect on the translation, treating the entire text as one chunk.Args:source_lang (str): The source language of the text.target_lang (str): The target language of the translation.source_text (str): The original text in the source language.translation_1 (str): The initial translation of the source text.country (str): Country specified for target language.Returns:str: The LLM's reflection on the translation, providing constructive criticism and suggestions for improvement."""system_message = f"You are an expert linguist specializing in translation from {source_lang} to {target_lang}. \ You will be provided with a source text and its translation and your goal is to improve the translation."if country != "":reflection_prompt = f"""Your task is to carefully read a source text and a translation from {source_lang} to {target_lang}, and then give constructive criticism and helpful suggestions to improve the translation. \ The final style and tone of the translation should match the style of {target_lang} colloquially spoken in {country}.The source text and initial translation, delimited by XML tags <SOURCE_TEXT></SOURCE_TEXT> and <TRANSLATION></TRANSLATION>, are as follows:<SOURCE_TEXT> {source_text} </SOURCE_TEXT><TRANSLATION> {translation_1} </TRANSLATION>When writing suggestions, pay attention to whether there are ways to improve the translation's \n\ (i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),\n\ (ii) fluency (by applying {target_lang} grammar, spelling and punctuation rules, and ensuring there are no unnecessary repetitions),\n\ (iii) style (by ensuring the translations reflect the style of the source text and takes into account any cultural context),\n\ (iv) terminology (by ensuring terminology use is consistent and reflects the source text domain; and by only ensuring you use equivalent idioms {target_lang}).\n\Write a list of specific, helpful and constructive suggestions for improving the translation. Each suggestion should address one specific part of the translation. Output only the suggestions and nothing else."""else:reflection_prompt = f"""Your task is to carefully read a source text and a translation from {source_lang} to {target_lang}, and then give constructive criticism and helpful suggestions to improve the translation. \The source text and initial translation, delimited by XML tags <SOURCE_TEXT></SOURCE_TEXT> and <TRANSLATION></TRANSLATION>, are as follows:<SOURCE_TEXT> {source_text} </SOURCE_TEXT><TRANSLATION> {translation_1} </TRANSLATION>When writing suggestions, pay attention to whether there are ways to improve the translation's \n\ (i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),\n\ (ii) fluency (by applying {target_lang} grammar, spelling and punctuation rules, and ensuring there are no unnecessary repetitions),\n\ (iii) style (by ensuring the translations reflect the style of the source text and takes into account any cultural context),\n\ (iv) terminology (by ensuring terminology use is consistent and reflects the source text domain; and by only ensuring you use equivalent idioms {target_lang}).\n\Write a list of specific, helpful and constructive suggestions for improving the translation. Each suggestion should address one specific part of the translation. Output only the suggestions and nothing else."""prompt = reflection_prompt.format(source_lang=source_lang,target_lang=target_lang,source_text=source_text,translation_1=translation_1,)reflection = get_completion(prompt, system_message=system_message)return reflectiondef one_chunk_improve_translation(source_lang: str,target_lang: str,source_text: str,translation_1: str,reflection: str, ) -> str:"""Use the reflection to improve the translation, treating the entire text as one chunk.Args:source_lang (str): The source language of the text.target_lang (str): The target language for the translation.source_text (str): The original text in the source language.translation_1 (str): The initial translation of the source text.reflection (str): Expert suggestions and constructive criticism for improving the translation.Returns:str: The improved translation based on the expert suggestions."""system_message = f"You are an expert linguist, specializing in translation editing from {source_lang} to {target_lang}."prompt = f"""Your task is to carefully read, then edit, a translation from {source_lang} to {target_lang}, taking into account a list of expert suggestions and constructive criticisms.The source text, the initial translation, and the expert linguist suggestions are delimited by XML tags <SOURCE_TEXT></SOURCE_TEXT>, <TRANSLATION></TRANSLATION> and <EXPERT_SUGGESTIONS></EXPERT_SUGGESTIONS> \ as follows:<SOURCE_TEXT> {source_text} </SOURCE_TEXT><TRANSLATION> {translation_1} </TRANSLATION><EXPERT_SUGGESTIONS> {reflection} </EXPERT_SUGGESTIONS>Please take into account the expert suggestions when editing the translation. Edit the translation by ensuring:(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text), (ii) fluency (by applying {target_lang} grammar, spelling and punctuation rules and ensuring there are no unnecessary repetitions), \ (iii) style (by ensuring the translations reflect the style of the source text) (iv) terminology (inappropriate for context, inconsistent use), or (v) other errors.Output only the new translation and nothing else."""translation_2 = get_completion(prompt, system_message)return translation_2def one_chunk_translate_text(source_lang: str, target_lang: str, source_text: str, country: str = "" ) -> str:"""Translate a single chunk of text from the source language to the target language.This function performs a two-step translation process:1. Get an initial translation of the source text.2. Reflect on the initial translation and generate an improved translation.Args:source_lang (str): The source language of the text.target_lang (str): The target language for the translation.source_text (str): The text to be translated.country (str): Country specified for target language.Returns:str: The improved translation of the source text."""translation_1 = one_chunk_initial_translation(source_lang, target_lang, source_text)reflection = one_chunk_reflect_on_translation(source_lang, target_lang, source_text, translation_1, country)translation_2 = one_chunk_improve_translation(source_lang, target_lang, source_text, translation_1, reflection)return translation_2
三、使用LangGraph和Agently Workflow分别复现这个工作流
3.1 LangGraph
LangGraph手册:LangGraph
import json
import openai
from ENV import deep_seek_url, deep_seek_api_key, deep_seek_default_model
from langgraph.graph import StateGraph, START, END
import os# 模型请求准备
client = openai.OpenAI(api_key = deep_seek_api_key,base_url =deep_seek_url
)
default_model = deep_seek_default_modeldef get_completion(prompt: str,system_message: str = "You are a helpful assistant.",model: str = default_model,temperature: float = 0.3,json_mode: bool = False,
):response = client.chat.completions.create(model=model,temperature=temperature,top_p=1,messages=[{"role": "system", "content": system_message},{"role": "user", "content": prompt},],)return response.choices[0].message.content# 定义传递的信息结构
from typing import TypedDict, Optional
class State(TypedDict):source_lang: strtarget_lang: strsource_text: strcountry: Optional[str] = Nonetranslation_1: Optional[str] = Nonereflection: Optional[str] = Nonetranslation_2: Optional[str] = None# 创建一个工作流对象
workflow = StateGraph(State)# 定义三个工作块
"""
获取state中的信息:state.get("key_name")
更新state中的信息:return { "key_name": new_value }
"""
def initial_translation(state):source_lang = state.get("source_lang")target_lang = state.get("target_lang")source_text = state.get("source_text")system_message = f"You are an expert linguist, specializing in translation from {source_lang} to {target_lang}."prompt = f"""This is an {source_lang} to {target_lang} translation, please provide the {target_lang} translation for this text. \
Do not provide any explanations or text apart from the translation.
{source_lang}: {source_text}{target_lang}:"""translation = get_completion(prompt, system_message=system_message)print("[初次翻译结果]: \n", translation)return { "translation_1": translation }def reflect_on_translation(state):source_lang = state.get("source_lang")target_lang = state.get("target_lang")source_text = state.get("source_text")country = state.get("country") or ""translation_1 = state.get("translation_1")system_message = f"You are an expert linguist specializing in translation from {source_lang} to {target_lang}. \
You will be provided with a source text and its translation and your goal is to improve the translation."additional_rule = (f"The final style and tone of the translation should match the style of {target_lang} colloquially spoken in {country}."if country != ""else "")prompt = f"""Your task is to carefully read a source text and a translation from {source_lang} to {target_lang}, and then give constructive criticism and helpful suggestions to improve the translation. \
{additional_rule}The source text and initial translation, delimited by XML tags <SOURCE_TEXT></SOURCE_TEXT> and <TRANSLATION></TRANSLATION>, are as follows:<SOURCE_TEXT>
{source_text}
</SOURCE_TEXT><TRANSLATION>
{translation_1}
</TRANSLATION>When writing suggestions, pay attention to whether there are ways to improve the translation's \n\
(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),\n\
(ii) fluency (by applying {target_lang} grammar, spelling and punctuation rules, and ensuring there are no unnecessary repetitions),\n\
(iii) style (by ensuring the translations reflect the style of the source text and takes into account any cultural context),\n\
(iv) terminology (by ensuring terminology use is consistent and reflects the source text domain; and by only ensuring you use equivalent idioms {target_lang}).\n\Write a list of specific, helpful and constructive suggestions for improving the translation.
Each suggestion should address one specific part of the translation.
Output only the suggestions and nothing else."""reflection = get_completion(prompt, system_message=system_message)print("[初次翻译结果]: \n", reflection)return { "reflection": reflection }def improve_translation(state):source_lang = state.get("source_lang")target_lang = state.get("target_lang")source_text = state.get("source_text")translation_1 = state.get("translation_1")reflection = state.get("reflection")system_message = f"You are an expert linguist, specializing in translation editing from {source_lang} to {target_lang}."prompt = f"""Your task is to carefully read, then edit, a translation from {source_lang} to {target_lang}, taking into
account a list of expert suggestions and constructive criticisms.The source text, the initial translation, and the expert linguist suggestions are delimited by XML tags <SOURCE_TEXT></SOURCE_TEXT>, <TRANSLATION></TRANSLATION> and <EXPERT_SUGGESTIONS></EXPERT_SUGGESTIONS> \
as follows:<SOURCE_TEXT>
{source_text}
</SOURCE_TEXT><TRANSLATION>
{translation_1}
</TRANSLATION><EXPERT_SUGGESTIONS>
{reflection}
</EXPERT_SUGGESTIONS>Please take into account the expert suggestions when editing the translation. Edit the translation by ensuring:(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),
(ii) fluency (by applying {target_lang} grammar, spelling and punctuation rules and ensuring there are no unnecessary repetitions), \
(iii) style (by ensuring the translations reflect the style of the source text)
(iv) terminology (inappropriate for context, inconsistent use), or
(v) other errors.Output only the new translation and nothing else."""translation_2 = get_completion(prompt, system_message)print("[初次翻译结果]: \n", translation_2)return { "translation_2": translation_2 }# 规划执行任务
## 节点(node)注册
workflow.add_node("initial_translation", initial_translation)
workflow.add_node("reflect_on_translation", reflect_on_translation)
workflow.add_node("improve_translation", improve_translation)
## 连接节点
workflow.set_entry_point("initial_translation")
#workflow.add_edge(START, )
workflow.add_edge("initial_translation", "reflect_on_translation")
workflow.add_edge("reflect_on_translation", "improve_translation")
workflow.add_edge("improve_translation", END)# 开始执行
app = workflow.compile()
result = app.invoke({"source_lang": "English","target_lang": "中文","source_text": """Translation Agent: Agentic translation using reflection workflow
This is a Python demonstration of a reflection agentic workflow for machine translation. The main steps are:Prompt an LLM to translate a text from source_language to target_language;
Have the LLM reflect on the translation to come up with constructive suggestions for improving it;
Use the suggestions to improve the translation.
Customizability
By using an LLM as the heart of the translation engine, this system is highly steerable. For example, by changing the prompts, it is easier using this workflow than a traditional machine translation (MT) system to:Modify the output's style, such as formal/informal.
Specify how to handle idioms and special terms like names, technical terms, and acronyms. For example, including a glossary in the prompt lets you make sure particular terms (such as open source, H100 or GPU) are translated consistently.
Specify specific regional use of the language, or specific dialects, to serve a target audience. For example, Spanish spoken in Latin America is different from Spanish spoken in Spain; French spoken in Canada is different from how it is spoken in France.
This is not mature software, and is the result of Andrew playing around with translations on weekends the past few months, plus collaborators (Joaquin Dominguez, Nedelina Teneva, John Santerre) helping refactor the code.According to our evaluations using BLEU score on traditional translation datasets, this workflow is sometimes competitive with, but also sometimes worse than, leading commercial offerings. However, we’ve also occasionally gotten fantastic results (superior to commercial offerings) with this approach. We think this is just a starting point for agentic translations, and that this is a promising direction for translation, with significant headroom for further improvement, which is why we’re releasing this demonstration to encourage more discussion, experimentation, research and open-source contributions.If agentic translations can generate better results than traditional architectures (such as an end-to-end transformer that inputs a text and directly outputs a translation) -- which are often faster/cheaper to run than our approach here -- this also provides a mechanism to automatically generate training data (parallel text corpora) that can be used to further train and improve traditional algorithms. (See also this article in The Batch on using LLMs to generate training data.)Comments and suggestions for how to improve this are very welcome!"""
})print(result)
# 绘制流程图
from mermaid import Mermaid
Mermaid(app.get_graph().draw_mermaid())
3.2 Agently Workflow
- Agently官网:Agently.cn
- Agently Workflow与LangGraph的详细比较:点击查看
- Agently Workflow详细教程:点击查看
import json
from ENV import deep_seek_url, deep_seek_api_key, deep_seek_default_model
import Agently
import os # 将模型请求配置设置到agent工厂,后续工厂创建的agent对象都可以继承这个配置
agent_factory = (Agently.AgentFactory().set_settings("current_model", "OAIClient").set_settings("model.OAIClient.url", deep_seek_url).set_settings("model.OAIClient.auth", { "api_key": deep_seek_api_key }).set_settings("model.OAIClient.options", { "model": deep_seek_default_model })
)# 创建工作流
workflow = Agently.Workflow()# 定义关键处理节点
## 首次翻译
@workflow.chunk()
def initial_translation(inputs, storage):source_lang = storage.get("source_lang")target_lang = storage.get("target_lang")source_text = storage.get("source_text")# 创建一个翻译agent来执行任务translate_agent = agent_factory.create_agent()# 给翻译agent设置system信息translate_agent.set_agent_prompt("role",f"You are an expert linguist, specializing in translation from {source_lang} to {target_lang}.")# 向翻译agent发起翻译任务请求translation_1 = (translate_agent.input(
f"""This is an {source_lang} to {target_lang} translation, please provide the {target_lang} translation for this text. \
Do not provide any explanations or text apart from the translation.
{source_lang}: {source_text}{target_lang}:""").start())# 保存翻译结果storage.set("translation_1", translation_1)# 保存翻译agent备用storage.set("translate_agent", translate_agent)return {"stage": "initial translation","result": translation_1}## 反思优化
@workflow.chunk()
def reflect_on_translation(inputs, storage):source_lang = storage.get("source_lang")target_lang = storage.get("target_lang")source_text = storage.get("source_text")country = storage.get("country", "")translation_1 = storage.get("translation_1")# 创建一个反思agent来执行任务reflection_agent = agent_factory.create_agent()# 给反思agent设置system信息reflection_agent.set_agent_prompt("role",f"You are an expert linguist specializing in translation from {source_lang} to {target_lang}. \
You will be provided with a source text and its translation and your goal is to improve the translation.")additional_rule = ("The final style and tone of the translation should match the style of {target_lang} colloquially spoken in {country}."if country != ""else "")# 向反思agent发起反思任务reflection = (reflection_agent.input(
f"""Your task is to carefully read a source text and a translation from {source_lang} to {target_lang}, and then give constructive criticism and helpful suggestions to improve the translation. \
{additional_rule}The source text and initial translation, delimited by XML tags <SOURCE_TEXT></SOURCE_TEXT> and <TRANSLATION></TRANSLATION>, are as follows:<SOURCE_TEXT>
{source_text}
</SOURCE_TEXT><TRANSLATION>
{translation_1}
</TRANSLATION>When writing suggestions, pay attention to whether there are ways to improve the translation's \n\
(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),\n\
(ii) fluency (by applying {target_lang} grammar, spelling and punctuation rules, and ensuring there are no unnecessary repetitions),\n\
(iii) style (by ensuring the translations reflect the style of the source text and takes into account any cultural context),\n\
(iv) terminology (by ensuring terminology use is consistent and reflects the source text domain; and by only ensuring you use equivalent idioms {target_lang}).\n\Write a list of specific, helpful and constructive suggestions for improving the translation.
Each suggestion should address one specific part of the translation.
Output only the suggestions and nothing else.""").start())# 保存反思结果storage.set("reflection", reflection)return {"stage": "reflection","result": reflection}## 二次翻译
@workflow.chunk()
def improve_translation(inputs, storage):source_lang = storage.get("source_lang")target_lang = storage.get("target_lang")source_text = storage.get("source_text")translation_1 = storage.get("translation_1")reflection = storage.get("reflection")# 使用保存下来的翻译agenttranslate_agent = storage.get("translate_agent")# 直接发起二次翻译任务translation_2 = (translate_agent.input(
f"""Your task is to carefully read, then edit, a translation from {source_lang} to {target_lang}, taking into
account a list of expert suggestions and constructive criticisms.The source text, the initial translation, and the expert linguist suggestions are delimited by XML tags <SOURCE_TEXT></SOURCE_TEXT>, <TRANSLATION></TRANSLATION> and <EXPERT_SUGGESTIONS></EXPERT_SUGGESTIONS> \
as follows:<SOURCE_TEXT>
{source_text}
</SOURCE_TEXT><TRANSLATION>
{translation_1}
</TRANSLATION><EXPERT_SUGGESTIONS>
{reflection}
</EXPERT_SUGGESTIONS>Please take into account the expert suggestions when editing the translation. Edit the translation by ensuring:(i) accuracy (by correcting errors of addition, mistranslation, omission, or untranslated text),
(ii) fluency (by applying {target_lang} grammar, spelling and punctuation rules and ensuring there are no unnecessary repetitions), \
(iii) style (by ensuring the translations reflect the style of the source text)
(iv) terminology (inappropriate for context, inconsistent use), or
(v) other errors.Output only the new translation and nothing else.""").start())# 保存二次翻译结果storage.set("translation_2", translation_2)return {"stage": "improve translation","result": translation_2}# 连接工作块
(workflow.connect_to("initial_translation").connect_to("reflect_on_translation").connect_to("improve_translation").connect_to("end")
)# 添加过程输出优化
@workflow.chunk_class()
def output_stage_result(inputs, storage):print(f"[{ inputs['default']['stage'] }]:\n", inputs["default"]["result"])return(workflow.chunks["initial_translation"].connect_to("@output_stage_result").connect_to("reflect_on_translation.wait")
)
(workflow.chunks["reflect_on_translation"].connect_to("@output_stage_result").connect_to("improve_translation.wait")
)
(workflow.chunks["improve_translation"].connect_to("@output_stage_result")
)# 启动工作流
result = workflow.start(storage = {"source_lang": "English","target_lang": "中文","source_text": """Translation Agent: Agentic translation using reflection workflow
This is a Python demonstration of a reflection agentic workflow for machine translation. The main steps are:Prompt an LLM to translate a text from source_language to target_language;
Have the LLM reflect on the translation to come up with constructive suggestions for improving it;
Use the suggestions to improve the translation.
Customizability
By using an LLM as the heart of the translation engine, this system is highly steerable. For example, by changing the prompts, it is easier using this workflow than a traditional machine translation (MT) system to:Modify the output's style, such as formal/informal.
Specify how to handle idioms and special terms like names, technical terms, and acronyms. For example, including a glossary in the prompt lets you make sure particular terms (such as open source, H100 or GPU) are translated consistently.
Specify specific regional use of the language, or specific dialects, to serve a target audience. For example, Spanish spoken in Latin America is different from Spanish spoken in Spain; French spoken in Canada is different from how it is spoken in France.
This is not mature software, and is the result of Andrew playing around with translations on weekends the past few months, plus collaborators (Joaquin Dominguez, Nedelina Teneva, John Santerre) helping refactor the code.According to our evaluations using BLEU score on traditional translation datasets, this workflow is sometimes competitive with, but also sometimes worse than, leading commercial offerings. However, we’ve also occasionally gotten fantastic results (superior to commercial offerings) with this approach. We think this is just a starting point for agentic translations, and that this is a promising direction for translation, with significant headroom for further improvement, which is why we’re releasing this demonstration to encourage more discussion, experimentation, research and open-source contributions.If agentic translations can generate better results than traditional architectures (such as an end-to-end transformer that inputs a text and directly outputs a translation) -- which are often faster/cheaper to run than our approach here -- this also provides a mechanism to automatically generate training data (parallel text corpora) that can be used to further train and improve traditional algorithms. (See also this article in The Batch on using LLMs to generate training data.)Comments and suggestions for how to improve this are very welcome!"""
})# 打印执行结果
#print(workflow.storage.get("translation_1"))
#print(workflow.storage.get("reflection"))
#print(workflow.storage.get("translation_2"))
print(json.dumps(result, indent=4, ensure_ascii=False))
四、大模型应用工作流的关键要素解析
4.1 基本要素
- 工作流基本要素
- 🟩 工作块/工作节点
- 🔀 连接关系
- 普通连接
- 条件连接
- 📡 数据通讯
- 块间数据传递
- 工作流内数据传递
4.2 大模型应用工作流需要具备的特性
-
💫 能够成环
以支持在特定工作环(多步工作)中反复尝试,尝试结果不符合预期可以回到第一步重试
-
🛜 能够按条件分发
以支持意图识别、路径规划、工具选择、多agent路由等场景中,根据推理结果进入不同的下游工作流,同时也能支持符合特定条件后跳出环
-
⏭️ 能够多分支并行执行并在终点被等待
以支持面对复杂任务时,能够发起不同分支从不同处理角度/用不同处理方式对任务进行处理
-
📋 能够对列表型数据进行拆分处理并回收处理结果
例如生成行动清单、提纲等列表性质的结果后,根据列表项进行逐项处理,或执行类似Map-Reduce的逻辑
-
📡 可在工作流中进行复杂通讯:
-
🛰️ 使用全局环境数据通讯
工作流相当于提供了一个复杂的沙盒环境,沙盒环境中的全局环境数据会影响工作流运行状态,并存储工作流运行过程中的过程数据和最终成果
-
📨 工作块间运行上下游通讯
在复杂工作流中,如果所有的数据都使用全局环境数据通讯,尤其是在不同工作块中对同一个键指向的数据进行操作时,会因为对运行时序的判断困难而导致数据管理混乱,这时候,需要通过块间数据传递来确保数据变化与运行时序期望一致,用大白话说,就是确保“块2”能够正确使用它的前一个块“块1”生成的数据进行工作。
-
4.3 LangGraph的工作流要素图示
4.4 Agently Workflow的工作流要素图示
五、复杂的工作流:故事创作
5.1 设计思路
5.2 实现方案
import json
from ENV import deep_seek_url, deep_seek_api_key, deep_seek_default_model
import Agently
import os # 创建一个作家agentwriter = (Agently.create_agent().set_settings("current_model", "OAIClient").set_settings("model.OAIClient.url", os.environ["DEEPSEEK_BASE_URL"]).set_settings("model.OAIClient.auth", { "api_key": os.environ["DEEPSEEK_API_KEY"] }).set_settings("model.OAIClient.options", { "model": os.environ["DEEP_SEEK_DEFAULT_MODEL"] })
)# 创建两个工作流:主工作流和分块创作工作流
main_workflow = Agently.Workflow()
block_workflow = Agently.Workflow()# 定义主工作流的工作块
## 输入一句话描述
@main_workflow.chunk()
def input_story_idea(inputs, storage):storage.set("story_idea", input("[💡请输入您的故事灵感]: "))return## 创建世界观背景故事
@main_workflow.chunk()
def generate_background(inputs, storage):story_idea = storage.get("story_idea")background = (writer.input({"故事灵感": story_idea}).instruct(
"""请根据{故事灵感}创作故事的世界信息和背景故事,其中:
世界信息需要包括世界的主要国家或地区分布,不同国家或地区的环境描写,科技水平,信仰情况等
世界背景故事需要以时间线的形式描述世界的主要历史沿革,国家或地区之间的重大事件及带来的影响变化等""").output({"世界名称": ("str", ),"主要国家或地区": [{"名称": ("str", ),"关键信息": ("str", ),}],"世界背景故事": [("str", )],}).start())storage.set("background", background)return {"title": "世界观背景故事","result": background,}## 创建关键情节线
@main_workflow.chunk()
def generate_storyline(inputs, storage):story_idea = storage.get("story_idea")background = storage.get("background")storyline = (writer.input({"故事灵感": story_idea,"世界观背景故事": background,}).instruct(
"""请根据{世界观背景故事},围绕{故事灵感},创作故事的关键情节线安排""").output({"情节结构类型": ("str", "基于常见的故事、小说、剧作创作方法,输出你将要使用的剧情结构类型名称"),"情节结构特点": ("str", "阐述{剧情结构类型}的剧情结构手法、特点"),"故事线详细创作": [{"本段故事作用": ("str", "描述本段故事在整体结构中发挥的作用"),"关键情节": ([("str", )], "按时序描述本段故事中的关键情节,以及情节中的关键细节"),"涉及关键人物": ([("str", )], "给出本段故事中涉及的关键人物名"),}],}).start())storage.set("storyline", storyline)return {"title": "关键情节线","result": storyline,}## 分发故事段落设计
@main_workflow.chunk()
def send_story_block_list(inputs, storage):storyline = storage.get("storyline")storyline_details = storyline["故事线详细创作"]extra_instruction = input("[您是否还有其他创作指导说明?如创作风格、注意事项等]")story_block_list = []for item in storyline_details:item.update({ "补充创作指导": extra_instruction })story_block_list.append(item)return story_block_list## 过程产出输出
@main_workflow.chunk_class()
def print_process_output(inputs, storage):print(f"[{ inputs['default']['title'] }]:")if isinstance(inputs["default"]["result"], dict):print(json.dumps(inputs["default"]["result"], indent=4, ensure_ascii=False))else:print(inputs["default"]["result"])return## 最终结果整理
@main_workflow.chunk()
def sort_out(inputs, storage):result = []for item in inputs["default"]:result.append(item["default"])return "\n\n".join(result)# 定义分块创作工作流的工作块
## 获取初始数据
@block_workflow.chunk()
def init_data(inputs, storage):storage.set("story_block", inputs["default"])# 从公共存储中取出上一段创作结果storage.set("last_block_content", block_workflow.public_storage.get("last_block_content"))return## 进行正文创作
@block_workflow.chunk()
def generate_block_content(inputs, storage):# 要考虑的条件较多,可以在请求外部构造input和instruct的prompt数据## 围绕故事线详细创作信息的prompt## {"本段故事作用": ,"关键情节": , "涉及关键人物": , "补充创作指导": }input_dict = storage.get("story_block")instruction_list = ["参考{本段故事作用}及{涉及关键人物},将{关键情节}扩写为完整的故事","每段故事需要尽量包括行动描写、心理活动描写和对白等细节","每次创作只是完整文章结构中的一部分,承担{本段故事作用}说明的作用任务,只需要按要求完成{关键情节}的描述即可,不需要考虑本段故事自身结构的完整性",]## 如果有前一段内容,通过传入前一段内容末尾确保创作的连贯性last_block_content = storage.get("last_block_content", None)if last_block_content:## 在这里取上一段落的最后50个字,可根据需要修改保留的长度keep_length = 50input_dict.update({ "上一段落的末尾": last_block_content[(-1 * keep_length):] })instruction_list.append("创作时需要承接{上一段落的末尾},确保表达的连贯性")## 如果有人类评判反馈的修改意见,添加promptlast_generation = storage.get("block_content", None)revision_suggestion = storage.get("revision_suggestion", None)if last_generation and revision_suggestion:input_dict.update({"已有创作结果": last_generation,"修改意见": revision_suggestion,})instruction_list.append("你之前已经创作了{已有创作结果},但仍然需要修改,请参考{修改意见}进行修订")# 开始创作block_content = (writer.input(input_dict).instruct(instruction_list).start())# 保存创作结果storage.set("block_content", block_content)return {"title": f"本轮创作目标:{ input_dict['本段故事作用'] }","result": block_content,}## 人类判断是否满意
@block_workflow.chunk()
def human_confirm(inputs, storage):confirm = ""while confirm.lower() not in ("y", "n"):confirm = input("[您是否满意本次创作结果?(y/n)]: ")return confirm.lower()## 提交修改意见
@block_workflow.chunk()
def input_revision_suggestion(inputs, storage):storage.set("revision_suggestion", input("[请输入您的修改意见]: "))return## 输出满意的创作成果
@block_workflow.chunk()
def return_block_content(inputs, storage):block_content = storage.get("block_content")# 记得在公共存储中更新本次创作结果block_workflow.public_storage.set("last_block_content", block_content)return block_content## 过程产出输出
@block_workflow.chunk_class()
def print_process_output(inputs, storage):print(f"[{ inputs['default']['title'] }]:")if isinstance(inputs["default"]["result"], dict):print(json.dumps(inputs["default"]["result"], indent=4, ensure_ascii=False))else:print(inputs["default"]["result"])return# 定义分块创作工作流的工作流程
(block_workflow.connect_to("init_data").connect_to("generate_block_content").connect_to("@print_process_output").connect_to("human_confirm").if_condition(lambda return_value, storage: return_value == "y").connect_to("return_block_content").connect_to("end").else_condition().connect_to("input_revision_suggestion").connect_to("generate_block_content")
)(main_workflow.connect_to("input_story_idea").connect_to("generate_background").connect_to("@print_process_output").connect_to("generate_storyline").connect_to("@print_process_output").connect_to("send_story_block_list")# -> list[item1, item2, item3, ...].loop_with(block_workflow) # item1 -> block_workflow:inputs["default"]; item2 -> block_workflow: i#.connect_to("sort_out").connect_to("end")
)# 打印流程图,检查流程正确性
print(main_workflow.draw())
# 开始执行
result = main_workflow.start()
print(result["default"])
5.3 进一步思考和讨论
以下讨论点全部为开放性讨论,没有标准的正确答案,仅作为启发思考和开拓思路的作用
- 使用LangGraph是否可以复现上面的工作流?
- 世界背景和故事线是否也可以引入人类讨论协作的机制?该怎么改写?
- 是否可以像翻译项目一样,引入反思机制?如果可以,反思机制应该如何设计?
- 还有没有更好的故事创作工作流设计?
- 你还有哪些好的工作流点子?学完本课之后,还有哪些创作难点?
6. 其他信息
- Mermaid在线渲染网站:mermaid.live
- 手绘风格流程图在线编辑:excalidraw.com
相关文章:
工作流介绍
了解工作流对大模型进行高质量工作的辅助意义学会复现吴恩达博士的翻译工作流开源项目了解构成大模型工作流系统的关键元素学会搭建一个更复杂的业务场景工作流 一、为什么我们需要工作流? ❓ 什么样的职场打工人是合格的打工人? 反应快,理…...
学习黑客Active Directory 入门指南(五)
Active Directory 入门指南(五):管理工具、安全基础与学习路径 🛠️🛡️📚 大家好!欢迎来到 “Active Directory 入门指南” 系列的最后一篇。在前四篇中,我们已经全面探讨了Active…...
【第三篇】 SpringBoot项目中的属性配置
简介 SpringBoot支持多种配置文件格式,包括application.properties、yml和yaml等。本文章将详细介绍这三种配置文件的内容格式和详细用法,以及在程序中如何对配置文件中的属性进行读取。文章内容若存在错误或需改进的地方,欢迎大家指正&#…...
处理金融数据,特别是股票指数数据,以计算和分析RSRS(相对强度指数)
Python脚本,用于处理金融数据,特别是股票指数数据,以计算和分析RSRS(相对强度指数)指标。以下是代码的逐部分解释: 1. **导入库**: - `pandas`:用于数据处理和CSV文件操作。 - `numpy`:用于数值计算。 - `ElasticNet`:来自`sklearn.linear_model`,用于线性…...
C++面试2——C与C++的关系
C与C++的关系及核心区别的解析 一、哲学与编程范式:代码组织的革命 过程式 vs 多范式混合 C语言是过程式编程的典范,以算法流程为中心,强调“怎么做”(How)。例如,实现链表操作需手动管理节点指针和内存。 C++则是多范式语言,支持面向对象(OOP)、泛型编程(模板)、函…...
Linux云计算训练营笔记day10(MySQL数据库)
Linux云计算训练营笔记day10(MySQL数据库) 目录 Linux云计算训练营笔记day10(MySQL数据库)ifnull别名聚合函数group byHAVING 子查询关联查询 ifnull 在DQL语句中可以使用函数或表达式 函数 IFNULL(arg1,arg2) 如果arg1为NULL,函…...
深度解析:AWS NLB 与 ALB 在 EKS 集群中的最佳选择
前言 AWS 提供多种弹性负载均衡器,包括应用程序负载均衡器 (ALB)、网络负载均衡器 (NLB)、网关负载均衡器 (GWLB) 和经典负载均衡器 (CLB)。本文重点介绍 ALB 和 NLB,因为它们是 EKS 集群最相关的选项。 在确定合适的负载均衡器类型时,需要…...
nginx模块使用、过滤器模块以及handler模块
一、如何使用nginx的模块 1.ngx_code.c: #include "ngx_config.h" #include "ngx_conf_file.h" #include "nginx.h" #include "ngx_core.h" #include "ngx_string.h" #include "ngx_palloc.h" #include "n…...
基于PageHelper的分页查询
基于PageHelper的分页查询 ‘PageHelper是基于java的一个开源框架,用于在MyBatis等持久层框架中方便地进行分页查询操作。它提供了一组简单易用的API和拦截器机制,可以帮助开发者快速集成和使用分页功能。 PageHelper的主要功能包括: 分页…...
Linux518 YUM源仓库回顾(需查)ssh 服务配置回顾 特定任务配置回顾
计划配仓库YUM源 为什么我在/soft文件夹下 使用yum install --downloadonly --downloaddir /soft samba 为什么文件夹下看不到samba文件 exiting because “Download Only” specified 计划过 计划配SSH 参考 ok了 计划配置特定任务解决方案 code: 两端先配好网络 测试好s…...
AI 制作游戏美术素材流程分享(程序员方向粗糙版)
AI 制作游戏美术素材分享(程序员方向粗糙版) 视频讲解: 抖音:https://www.douyin.com/user/self?from_tab_namemain&modal_id7505691614690561295&showTabpost Bilibili: https://www.bilibili.com/video/BV1ojJGzZEve/ 写在最前面: 本方法比较粗糙,只对对美术风…...
山东大学计算机图形学期末复习12——CG13下
CG13下 BSP树 BSP (Binary Space Partition)表示二叉空间分割。 使用这种方法可以使我们在运行时使用一个预先计算好的树来得到多边形从后向前的列表,它的复杂度为O(n)。 它的基本思想是基于这样一个事实:任何平面都可以将空间分…...
Muduo网络库大总结
Muduo网络库大总结 目录 目的知识储备IO模型 阻塞与非阻塞五种IO模型 epoll原理 select/poll的缺点epoll的优势LT与ET模式 Reactor模型muduo核心模块扩展功能 目的 理解阻塞、非阻塞、同步、异步的概念掌握Unix/Linux五种IO模型深入理解epoll原理及优势掌握Reactor模型设计学…...
LLMs:《POE报告:2025年春季人工智能模型使用趋势》解读
LLMs:《POE报告:2025年春季人工智能模型使用趋势》解读 导读:2025年5月13日,该报告基于 Poe 平台的用户数据,分析了 2025 年春季人工智能模型的使用趋势。报告指出,人工智能格局快速演变,通用文…...
机器学习(13)——LGBM(2)
一、LightGBM算法简介 (一)背景 机器学习中的树模型 在机器学习领域,基于树的模型(如决策树、随机森林、梯度提升树等)是非常重要的算法类别。它们具有很强的可解释性,能够很好地处理非线性关系ÿ…...
翻到了一段2005年写的关于需求的文字
那时的俺还很稚嫩,很多东西都不懂。 另外 hfghfghfg其实是俺的一个马甲,早年间在delphibbs时用的。 来自:hfghfghfg, 时间:2005-01-20 13:16, ID:2971188我到客户那里的情况 一边要和他聊天 一边改报表。 一张报表 …...
MCP - Cline 接入 高德地图 Server
文章目录 一、准备1、注册、认证高德开放平台账号2、创建应用、获取 Key3、用量管理2、Cline 配置模型 二、接入三、测试官方测试 - 出行规划专属地图 四、关于 高德 MCP Server - AI时代的出行服务中台1、产品定位2、技术架构亮点3、核心API能力矩阵4、开发者优势5、典型应用场…...
Linux的MySQL头文件和找不到头文件问题解决
头文件 #include <iostream> #include <mysql_driver.h> #include <mysql_connection.h> #include <cppconn/statement.h> #include <cppconn/resultset.h> #include <cppconn/prepared_statement.h> #include <cppconn/exception.h&g…...
进程和线程的区别和联系
二者概念 进程 运行起来一个程序就会在操作系统产生一个或多个进程 进程属于软件资源。 进程是操作系统中资源分配的基本单位。 每个进程拥有独立的 内存空间、文件描述符、系统资源。 进程之间相互隔离,一个进程崩溃不会直接影响其他进程。 操作系统管理进程…...
SHAP分析图的含义
1. 训练集预测结果对比图 表征含义: 展示模型在训练集上的预测值(红色曲线)与真实值(灰色曲线)的对比。通过曲线重合度可直观判断模型的拟合效果。标题中显示的RMSE(均方根误差)量化了预测值与…...
PointNet++:点云处理的升级版算法
在三维计算机视觉和机器学习领域,点云数据的处理一直是一个关键问题。点云是由一系列三维坐标点组成的集合,这些点可以描述物体的形状和结构。然而,由于点云的无序性和不规则性,传统的处理方法往往难以直接应用。PointNet算法的出…...
PostGIS实现矢量数据转栅格数据【ST_AsRaster】
ST_AsRaster函数应用详解:将矢量数据转换为栅格数据 [文章目录] 一、函数概述 二、函数参数与分组说明 三、核心特性与注意事项 四、示例代码 五、应用场景 六、版本依赖 七、总结 一、函数概述 ST_AsRaster是PostGIS中用于将几何对象(如点、线…...
【PyQt5实战】五大对话框控件详解:从文件选择到消息弹窗
对话框是人机交互的重要组件,PyQt5提供了一系列标准对话框满足不同场景需求。本文将深入解析QDialog及其子类的使用方法,助你快速掌握GUI开发核心交互功能。 对话框基础:QDialog QDialog是所有对话框的基类,支持模态/非模态两种…...
机器学习-人与机器生数据的区分模型测试 - 模型选择与微调
内容继续机器学习-人与机器生数据的区分模型测试 整体模型的准确率 X_train_scaled pd.DataFrame(X_train_scaled,columns X_train.columns ) X_test_scaled pd.DataFrame(X_test_scaled,columns X_test.columns)from ngboost.distns import Bernoulli # 模型训练和评估 m…...
学习黑客Active Directory 入门指南(四)
Active Directory 入门指南(四):组策略的威力与操作主机角色 📜👑 大家好!欢迎来到 “Active Directory 入门指南” 系列的第四篇。在前几篇中,我们已经构建了对AD逻辑结构、物理组件、关键服务…...
十一、STM32入门学习之FREERTOS移植
目录 一、FreeRTOS1、源码下载:2、解压源码 二、移植步骤一:在需要移植的项目中新建myFreeRTOS的文件夹,用于存放FREERTOS的相关源码步骤二:keil中包含相关文件夹和文件引用路径步骤三:修改FreeRTOSConfig.h文件的相关…...
Spring ioc和Aop
IOC 在传统Java当中,我们的对象都需要new关键字来生成,这在面对很多对象的情况产生了不必要的麻烦,因为我不需要在一个项目中一直做重复的事情,那怎么办把,自然而然的一些好的框架就诞生了,避免我们去做这…...
动态内存管理2+柔性数组
一、动态内存经典笔试题分析 分析错误并改正 题目1 void GetMemory(char *p) {p (char *)malloc(100); } void Test(void) {char *str NULL;GetMemory(str);strcpy(str, "hello world");printf(str); } int main() {Test();return 0; }错误的原因: …...
USB传输速率 和 RS-232/RS-485串口协议速率 的倍数关系
一、技术背景 RS-232:传统串口标准,典型速率 115.2 kbps(最高约 1 Mbps)。RS-485:工业串口标准,典型速率 10 Mbps(理论最高可达 50 Mbps)。USB:不同版本差异巨大&#x…...
多线程代码案例-4 线程池
1、引入 池是一个非常重要的概念,我们有常量池,数据库连接池,线程池,进程池,内存池…… 池的作用: 1、提前把要用的对象准备好 2、用完的对象也不立即释放,先留着以备下次使用,提…...
JSON Schema 高效校验 JSON 数据格式
在数据交换和API开发中,JSON 已成为最流行的数据格式之一。但你是否遇到过这些困扰? 接收的JSON字段缺失关键数据?数值类型意外变成了字符串?嵌套结构不符合预期? JSON Schema 正是解决这些问题的利器。本文将带你全…...
机器学习09-正规方程
机器学习笔记:正规方程(Normal Equation) 概述 正规方程是线性回归中求解参数的一种解析方法。它基于最小化损失函数(如最小二乘法)来直接计算出参数的最优值。在机器学习中,这种方法尤其适用于特征数量不…...
Java大师成长计划之第26天:Spring生态与微服务架构之消息驱动的微服务
📢 友情提示: 本文由银河易创AI(https://ai.eaigx.com)平台gpt-4-turbo模型辅助创作完成,旨在提供灵感参考与技术分享,文中关键数据、代码与结论建议通过官方渠道验证。 在现代微服务架构中,服务…...
Linux 文件(1)
1. 文件 1.1 文件是什么 一个文件,是由其文件属性与文件内容构成的。文件属性又称为一个文件的元数据,因此如果一个文件,内容为空,这个文件依然要占据磁盘空间。 1.2 文件在哪里 一个文件,如果没有被打开ÿ…...
程序代码篇---python向http界面发送数据
文章目录 前言 前言 本文简单接受了python向http界面发送数据...
【iOS】探索消息流程
探索消息流程 Runtime介绍OC三大核心动态特性动态类型动态绑定动态语言 方法的本质代码转换objc_msgSendSELIMPMethod 父类方法在子类中的实现 消息查找流程开始查找快速查找流程慢速查找流程二分查找方法列表父类缓存查找 动态方法解析动态方法决议实例方法类方法优化 消息转发…...
院校机试刷题第六天:1134矩阵翻转、1052学生成绩管理、1409对称矩阵
一、1134矩阵翻转 1.题目描述 2.解题思路 很简单的模拟题,甚至只是上下翻转,遍历输出的时候先把最下面那一行输出即可。 3.代码 #include <iostream> #include <vector> using namespace std;int main() {int n;cin >> n;vector&l…...
DeepSeek在简历筛选系统中的深度应用
一、多模态解析引擎的技术突破 1.1 复杂格式的精准解析 针对简历格式多样性挑战,DeepSeek采用三级解析架构: 格式标准化层:基于Transformer的DocParser模型支持200+种文档格式转换视觉特征提取:使用改进的YOLOv8进行证书印章识别(mAP@0.5达93.7%)语义重构模块:通过注意…...
c++多线程debug
debug demo 命令行查看 ps -eLf|grep cam_det //查看当前运行的轻量级进程 ps -aux | grep 执行文件 //查看当前运行的进程 ps -aL | grep 执行文件 //查看当前运行的轻量级进程 pstree -p 主线程ID //查看主线程和新线程的关系 查看线程栈结构 pstack 线程ID 步骤&…...
【回溯 剪支 状态压缩】# P10419 [蓝桥杯 2023 国 A] 01 游戏|普及+
本文涉及知识点 C回溯 位运算、状态压缩、枚举子集汇总 P10419 [蓝桥杯 2023 国 A] 01 游戏 题目描述 小蓝最近玩上了 01 01 01 游戏,这是一款带有二进制思想的棋子游戏,具体来说游戏在一个大小为 N N N\times N NN 的棋盘上进行,棋盘…...
CUDA 纹理入门
一、什么是CUDA纹理 CUDA纹理是NVIDIA GPU提供的一种特殊内存访问机制,它允许高效地访问和过滤结构化数据。纹理内存最初是为图形渲染设计的,但在通用计算(GPGPU)中也很有用。 二、纹理内存的优势 缓存优化:纹理内存有专用的缓存,适合空间局部性好的访问模式 硬件过滤:支…...
大模型微调步骤整理
在对深度学习模型进行微调时,我通常会遵循以下几个通用步骤。 第一步是选择一个合适的预训练模型。PyTorch 的 torchvision.models 模块提供了很多经典的预训练模型,比如 ResNet、VGG、EfficientNet 等。我们可以直接使用它们作为模型的基础结构。例如,加载一个预训练的 Re…...
【GPT入门】第39课 OPENAI官方API调用方法
【GPT入门】第39课 OPENAI官方API调用方法 1. OPENAI 免费API2. openai调用最简单的API3.apiKey提取到环境变量 1. OPENAI 免费API 需要科学上网,可以调用 gpt-4o-mini 的 api, 使用其它旧的GPT,反而可能需要收费,例如 gpt-3.5-turbo 2. op…...
【DeepSeek论文精读】11. 洞察 DeepSeek-V3:扩展挑战和对 AI 架构硬件的思考
欢迎关注[【AIGC论文精读】](https://blog.csdn.net/youcans/category_12321605.html)原创作品 【DeepSeek论文精读】1. 从 DeepSeek LLM 到 DeepSeek R1 【DeepSeek论文精读】7. DeepSeek 的发展历程与关键技术 【DeepSeek论文精读】11. 洞察 DeepSeek-V3ÿ…...
MySQL事务的一些奇奇怪怪知识
Gorm事务有error却不返回会发生什么 Gorm包是大家比较高频使用。正常的用法是,如果有失败返回error,整体rollback,如果不返回error则commit。下面是Transaction的源码: // Transaction start a transaction as a block, return …...
C语言内存函数与数据在内存中的存储
一、c语言内存函数 1、memcpy函数是一个标准库函数,用于内存复制。功能上是用来将一块内存中的内容复制到另一块内存中。用户需要提供目标地址、源地址以及要复制的字节数。例如结构体之间的复制。 memcpy函数的原型是:void* memcpy(void* …...
Power BI Desktop运算符和新建列
1.运算符 运算符 含义 加 - 减 * 乘 / 除 ^ 幂 运算符 含义 等于 > 大于 < 小于 > 大于等于 < 小于等于 <> 不等于 运算符 含义 && 与 || 或 not 非 & 字符串连接 in 包含 not in 不包含 2.新建列 …...
windows 安装gdal实现png转tif,以及栅格拼接
windows 安装gdal实现png转tif,以及栅格拼接 一、安装gdal 网上有很多安装gdal的方法,此处通过osgeo4w安装gdal 1.下载osgeo4w 下载地址 https://trac.osgeo.org/osgeo4w/ 2、安装osgeo4w exe文件安装,前面部分很简单,就不再…...
【嵙大o】C++作业合集
参考: C swap(交换)函数 指针/引用/C自带-CSDN博客 Problem IDTitleCPP指针CPP引用1107 Problem A编写函数:Swap (I) (Append Code)1158 Problem B整型数据的输出格式1163 Problem C时间:24小时制转12小时制1205…...
论信息系统项目的采购管理
论信息系统项目的采购管理 背景一、规划采购管理二、实施采购三、控制采购结语 背景 某市为对扶贫对象实施精确识别、精确帮扶、精确管理,决定由民政部门牵头,建设家庭经济状况分析及市、县(区)、镇(街)三级…...